akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> D(N, vector<int>(2));
    rep(i, N) rep(j, 2) cin >> D[i][j];

    int cnt = 0;
    bool ok = false;
    rep(i, N) {
        if (D[i][0] == D[i][1])
            ++cnt;
        else
            cnt = 0;
        if (cnt == 3) {
            ok = true;
            break;
        }
    }

    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3628
N = int(input())
A = [int(input()) for n in range(N)]
 
max_A = max(A)
max_index = A.index(max(A))

A[max_index] = 0
max_A2 = max(A)
A[max_index] = max_A

for n in range(N):
  if A[n] != max_A:
    print(max_A)
  else:
    print(max_A2)

Measured memory_bytes: 12636
import sys
import math

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def pro(k, l, n):
    if l < n:
        if k == 0:
            return(n - l)
        return (n - l + 2)
    if l == n:
        if k == 0:
            return 0
        elif k == 1:
            return 1
        return 3
    else:
        l -= n - 1
        if l == k:
            return 1
        elif l > k:
            return 0
        if l < k - 1:
            return 2
        else:
            return 3
            

def rt(k, l , n):
    if k < n:
        if l == 0:
            return (k * 2 + n)
        return (n + k * 2 - 1)
    elif k == n:
        if l == 1:
            return (k * 3 - 2)
        elif l == 0:
            return (k * 3)
        return (k * 3 - 3)
    else:
        k -= n - 1
        if k == l:
            return (n * 3 - 2)
        elif k > l:
            return (n * 3)
        if k < l - 1:
            return ((n - 1) * 3 - 1)
        else:
            return ((n - 1) * 3)



def main():
    n = iinput()
    a = rlinput()
    res = sum(rlinput())
    c = rlinput()
    for i in range(n - 1):
        if a[i] - a[i + 1] == -1:
            res += c[a[i] - 1]
    print(res)
            
        
    
    
    
    
    


main()

Measured memory_bytes: 38256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

bool done[22];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, D;
    while (cin >> W >> D) {
    	if (W==0 && D==0) break;
    	vi X(W), Y(D);
    	for (int i = 0; i < W; i++)
    		cin >> X[i];
    	for (int i = 0; i < D; i++)
    		cin >> Y[i];
    	memset(done, false, sizeof(done));
    	sort(X.rbegin(), X.rend());
    	sort(Y.rbegin(), Y.rend());
    	int ans = 0;
    	for (int i = 0; i < W; i++) {
    		ans += X[i];
    		for (int j = 0; j < D; j++) {
    			if (!done[j] && X[i] == Y[j]) {
    				done[j] = true;
    				break;
    			}
    		}
    	}
    	for (int i = 0; i < D; i++) {
    		if (!done[i]) ans += Y[i];
    	}
    	cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define llong long long
#define vi vector<int>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())

int main(){
	int p[3],jc[2],min=INF;
	REP(i,3)cin>>p[i];
	REP(i,2)cin>>jc[i];
	REP(i,3){
		REP(j,2){
			if(min>p[i]+jc[j])min=p[i]+jc[j];
		}
	}
	cout<<min-50<<"\n";
	return 0;
}

Measured memory_bytes: 3072
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    int A = sc.nextInt();
    int B = sc.nextInt();
    String U = sc.next();
    if(S.equals(U)){
      A--;
    }else{
      B--;
    }
    System.out.println(A + " " + B);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

map<string, int> m;

int main(){
    int N, max_val = 0;
    cin >> N;
    rep(i, N){
        string s;
        cin >> s;
        m[s]++;
        chmax(max_val, m[s]);
    }
    for (auto mi = m.begin(); mi != m.end(); ++mi){
        if (mi->second == max_val){
            cout << mi->first << endl;
        }
    }
}

Measured memory_bytes: 25216
#include<stdio.h>
#define mod 1000000007ll
#define inf 2147483647ll
#define ll long long
struct edge{
	int to,nex;
}e[3000010];
int c[200010],h[200010],pos[200010],cnt[200010],tot;
ll w[200010],fac[200010],rfac[200010],min[200010];
bool v[200010];
ll pow(ll a,ll b){
	ll ans=1,base=a;
	while(b){
		if(b&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		b>>=1;
	}
	return ans;
}
ll C(ll n,ll k){
	return(((fac[n]*rfac[n-k])%mod)*rfac[k])%mod;
}
void add(int a,int b){
	tot++;
	e[tot].to=b;
	e[tot].nex=h[a];
	h[a]=tot;
}
void dfs(int x){
	v[x]=1;
	for(int i=h[x];i;i=e[i].nex){
		if(!v[e[i].to])dfs(e[i].to);
	}
}
int main(){
	int n,i,fir,sec=0;
	ll X,Y,min1,min2,tot,ans;
	scanf("%d%lld%lld",&n,&X,&Y);
	fac[0]=1;
	for(i=1;i<=n;i++){
		scanf("%d%lld",c+i,w+i);
		fac[i]=(i*fac[i-1])%mod;
		min[i]=inf;
	}
	rfac[n]=pow(fac[n],mod-2);
	for(i=n;i>0;i--)rfac[i-1]=(i*rfac[i])%mod;
	for(i=1;i<=n;i++){
		if(w[i]<min[c[i]]){
			min[c[i]]=w[i];
			pos[c[i]]=i;
		}
	}
	for(i=1;i<=n;i++){
		if(i!=pos[c[i]]&&w[i]+min[c[i]]<=X){
			add(i,pos[c[i]]);
			add(pos[c[i]],i);
		}
	}
	min1=min2=inf;
	for(i=1;i<=n;i++){
		if(w[i]<min1){
			min1=w[i];
			fir=i;
		}
	}
	for(i=1;i<=n;i++){
		if(w[i]<=min2&&c[i]!=c[fir]){
			min2=w[i];
			sec=i;
		}
	}
	for(i=1;i<=n;i++){
		if(i==fir)continue;
		if(c[i]!=c[fir]&&w[i]+w[fir]<=Y){
			add(i,fir);
			add(fir,i);
		}
		if(sec&&c[i]!=c[sec]&&w[i]+w[sec]<=Y){
			add(i,sec);
			add(sec,i);
		}
	}
	dfs(fir);
	tot=0;
	for(i=1;i<=n;i++){
		if(v[i]){
			tot++;
			cnt[c[i]]++;
		}
	}
	ans=1;
	for(i=1;i<=n;i++){
		if(cnt[i]){
			ans=(ans*C(tot,cnt[i]))%mod;
			tot-=cnt[i];
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 16640
#AGC029 A - Irreversible operation
def countB(data):#dataのBの個数kosuとiの総和sumを返す
    sum=0
    kosu=0
    for i in range(len(data)):
        if data[i]=="B":
            kosu=kosu+1
            sum=sum+i
    return[sum,kosu]

text=input()
S=[]
N=len(text)
for i in range(N):
    S.append(text[i])
result=countB(S)
x=result[1]
Ans=int((2*N-x-1)*x/2-result[0])
print(Ans)

Measured memory_bytes: 5096
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;


int main(){
	

	int N; std::cin >> N;
	std::vector<int> A(N);
	rep(i, N)std::cin >> A[i];
	std::vector<int> sorted = A;
	std::sort(sorted.begin(), sorted.end());


	rep(i, N){


		auto itr = std::lower_bound(sorted.begin(), sorted.end(), A[i]);

		int index = std::distance(sorted.begin(), itr);
		if(index == N - 1)std::cout << sorted[N - 2] << std::endl;
		else std::cout << sorted[N - 1] << std::endl;



	}


	return 0;
}

Measured memory_bytes: 3200
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int hp = scanner.nextInt();
        int numSpell = scanner.nextInt();
        List<Spell> spells = new ArrayList<>();
        for (int i = 0; i < numSpell; i++) {
            int attack = scanner.nextInt();
            int mana = scanner.nextInt();
            spells.add(new Spell(attack, mana));
        }
        scanner.close();
        long sumMana = find(spells, hp);
        System.out.println(sumMana);
    }

    private static Map<Integer, Integer> manaMap = new HashMap<>();
    private static int find(List<Spell> spells, int hp) {
        if(hp <= 0) {
            return 0;
        }
        if(manaMap.containsKey(hp)) return manaMap.get(hp);
        int minMana = Integer.MAX_VALUE;
        for(int i = 0; i < spells.size(); i++) {
            int mana = find(spells, hp - spells.get(i).atack) + spells.get(i).mana;
            minMana = Math.min(minMana, mana);
        }
        manaMap.put(hp, minMana);

        return minMana;
    }

    public static class Spell {
        int atack;
        int mana;
        Spell(int atack, int mana) {
            this.atack = atack;
            this.mana = mana;
        }
    }
}

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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
// end of Template

int n;
int harsh(int x){
    int sum = 0;
    queue <int> q;
    while(x>0){
        q.push(x%10);
        x/=10;
    }
    while(!q.empty()){
        sum+=q.front();
        q.pop();
    }
    return sum;
}
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    int f;
    f = harsh(n);

    if(n%f == 0){cout<<"Yes\n";}
    else{cout<<"No\n";}

}


Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

// reference: http://ir5.hatenablog.com/entry/20171209/1512821837

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

use std::mem;
use std::cmp;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let S: String = sc.read();
    let mut ans: u8 = 0;
    for i in (0..S.len()) {
        if S.chars().nth(i).unwrap() == '1' {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2132
import itertools

n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

acc_A = [0]+list(itertools.accumulate(A))
acc_B = [0]+list(itertools.accumulate(B))
    
ans, j = 0, m
for i in range(n+1):
    if acc_A[i] > k:
        break
    while acc_A[i] + acc_B[j] > k:
        j -= 1
    ans = max(ans, i+j)
print(ans)
             

Measured memory_bytes: 50624
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int N, T;
string S;

int main(void){
	//IO("test.in", "test.out");
	scanf("%d", &N);
	S = to_string(N);
	for(int i = 0; i < S.length(); i++) T += S[i] - '0';
	if(N % T == 0) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
#include <iostream>
int main(){
  int r=0,a[10001]={},n,i;
  for(std::cin>>n,i=0;i<n;++i)std::cin>>a[i];
  for(i=0;i<n;++i)while(a[i]%2==0){a[i]/=2;++r;}
  std::cout<<r<<"\n";
}

Measured memory_bytes: 256
N=int(input())
links=[[] for _ in range(N+1)]
for _ in range(N-1):
  a, b, c=map(int, input().split())
  links[a].append([b, c])
  links[b].append([a, c])
  
Q, K=map(int, input().split())

length=[-1]*(N+1)
length[K]=0

import heapq
q=[[tmp[1], tmp[0], K] for tmp in links[K]]
heapq.heapify(q)
while q:
  tmp=heapq.heappop(q)
  length[tmp[1]]=tmp[0]+0
  for x in links[tmp[1]]:
    if tmp[2]!=x[0]:
      heapq.heappush(q, [tmp[0]+x[1], x[0], tmp[1]])

for _ in range(Q):
  x, y=map(int, input().split())
  print(length[x]+length[y])

Measured memory_bytes: 58076
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge
{
    ll to, cost, val;
};
template <class T, class U>
bool chmin(T &a, const U &b)
{
    if (a <= b)
        return false;
    a = b;
    return true;
}
template <class T, class U>
bool chmax(T &a, const U &b)
{
    if (a >= b)
        return false;
    a = b;
    return true;
}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
#define int ll

    int N;
    ll M;
    ll S[110000];
vector<ll> V,VV;

bool check(int x){
    int count=0;
    for(int i=0;i<N;i++){
        count+=(N- (int)(lower_bound(V.begin(),V.end(),x-V[i])-V.begin()) );
    }
    if(count>=M) return true;
    else return false;
}

signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N>>M;
    for(int i=0;i<N;i++){
        ll t;
        cin>>t;
        V.push_back(t);
        VV.push_back(t);
    }
    sort(V.begin(),V.end());
    V.push_back(210000);

      ll ng=210000,ok=0;
  while(ng-ok!=1){
    ll mid=(ng+ok)/2;
    if(check(mid)) ok=mid;
    else ng=mid;
  }
  sort(VV.rbegin(),VV.rend());
  for(int i=1;i<=N;i++){
      S[i]=S[i-1]+VV[i-1];
  }
  //cout<<VV[0]<<endl;
  int count=0;
  ll ans=0;
  for(int i=0;i<N;i++){
      int x=(N- (int)(lower_bound(V.begin(),V.end(),ok-V[i])-V.begin()) );
      ans+=x*V[i]+S[x];
      count+=x;
      //cout<<i<<" "<<x<<endl;
  }
  ans-=(count-M)*ok;
  //cout<<ok<<endl;
  cout<<ans<<endl;
}


Measured memory_bytes: 2796
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S=input()

for s in S:
    if S.count(s)!=2:
        No()
        exit()
Yes()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <utility>

using namespace std;

int main() {
	int n; cin >> n;
	vector<vector<int> > lis(n + 1);
	vector<string> m(n + 1);
	for (int i = 1; i <= n; ++i) {
		int k; cin >> k;
		cin >> m[i];
		lis[k].push_back(i);
	}
	stack<pair<int,int> > st;
	st.push(make_pair(1, 0));
	while (!st.empty()) {
		auto now = st.top(); st.pop();
		for (int i = 0; i < now.second; ++i) cout << ".";
		cout << m[now.first] << endl;
		for (int j = lis[now.first].size() - 1; j >= 0; --j)
			st.push(make_pair(lis[now.first][j], now.second + 1));
	}

	return 0;
}


Measured memory_bytes: 3368
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
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; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N, M;
    in2(N, M);

    vi P(M), Y(M);
    rep(i, M) in2(P[i], Y[i]);

    vvi X(N + 1);
    rep(i, M)
    {
        X[P[i]].push_back(Y[i]);
    }

    rep(i, N + 1) sort(all(X[i]));

    rep(i, M)
    {
        auto itr = lower_bound(all(X[P[i]]), Y[i]);
        int num = distance(X[P[i]].begin(), itr) + 1;

        cout << std::setw(6) << std::setfill('0') << P[i];
        cout << std::setw(6) << std::setfill('0') << num << endl;
    }

    return 0;
}


Measured memory_bytes: 9408
from itertools import product


def solve(string):
    h, w, k, *c = string.split()
    h, w, k = map(int, [h, w, k])
    ans = 0
    for f in product([True, False], repeat=h + w):
        count = 0
        for _f, _c in zip(f, c):
            if _f:
                continue
            count += sum(1 if not __f and v == "#" else 0 for __f, v in zip(f[h:], _c))
        ans += 1 if count == k else 0
    return str(ans)

    pass


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 9108
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int a;
	cin>>a;
	int t=1;
	while(a>=t){
		t*=2;
	}
	cout<<t/2<<endl;
}








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

string str;

int main( void ) {
    
    cin >> str;
    
    bool ok = false;
    for( int i = 0; i < str.length() && ok == false; i ++ ) {
        if( i >= 1 && str[i] == str[i - 1] ) {
            cout << i << " " << i + 1 << endl;
            ok = true;
        }
        
        if( i >= 2 && str[i] == str[i - 2] ) {
            cout << i - 1 << " " << i + 1 << endl;
            ok = true;
        }
    }
    
    if( ok == false )
        cout << -1 << " " << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

const int N = 100;

int main() {
  int n = 0;
  int a[N] = {0};

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }

  int count = 0;
  bool flag = true;
  
  while (flag) {
    flag = false;

    for (int i = 1; i < n; i++) {
      if (a[i - 1] > a[i]) {
	int tmp = a[i - 1];
	a[i - 1] = a[i];
	a[i] = tmp;
	
	count++;
	flag = true;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    std::cout << a[i];

    if (i < (n - 1)) {
      std::cout << " ";
    } else {
      std::cout << std::endl;
    }
  }

  std::cout << count << std::endl;
  
  return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-12

template<class T> T add(T x, T y){ if(abs(x+y) < EPS*(abs(x)+abs(y))) return 0; return x + y; }
template<class T> inline bool semieq(T x, T y){ return abs(x - y) < EPS; }
template<class T> inline bool semige(T x, T y){ return x - y > -EPS; }
template<class T> inline bool semile(T x, T y){ return y - x > -EPS; }

template<class Type> struct Line;

template<class Type>
struct P
{
  friend struct Line<Type>;
private:
  complex<Type> z;

public:
  P(const Type x = 0, const Type y = 0) : z(complex<Type>(x, y)) { }
  void setter(Type x, Type y) { z = complex<Type>(x, y); }
  Type getX(){ return z.real(); }
  Type getY(){ return z.imag(); }
  inline double getSlope(){ return tan(z.arg()); }
  inline double getSlope(P<Type> p){ return (this - p).getSlope(); }

  bool operator == (const P<Type> p){ return  semieq(z.real(), p.real()) &&  semieq(z.imag(), p.imag()); }
  bool operator != (const P<Type> p){ return !semieq(z.real(), p.real()) || !semieq(z.imag(), p.imag()); }
  Type operator * (const P<Type> p){ return (z * p.z).real(); }
  Type operator / (const P<Type> p){ return (z * p.z).imag(); }
};

template<class Type>
struct Line
{
private:
  P<Type> S, T;

public:
  Line(const Type sx, const Type sy, const Type tx, const Type ty) : S(sx, sy), T(tx, ty) {}
  Line(const P<Type> S, const P<Type> T) : S(S), T(T) {}
  inline P<Type> getS(){ return S; }
  inline P<Type> getT(){ return T; }
  inline double getSlope(){ return S.getSlope(T); }
  inline bool isParallel(Line<Type> L){ return semieq(((L.S.z - L.T.z) / (S.z - T.z)).imag(), 0.0); }
  inline bool isVertical(Line<Type> L){ return semieq(((L.S.z - L.T.z) / (S.z - T.z)).real(), 0.0); }
};

typedef double Point;

int n;
P<Point> A[4];
Point x, y;

int main()
{
  cin >> n;

  while(n--){
    rep(i, 4){
      cin >> x >> y;
      A[i].setter(x, y);
    }
    Line<Point> AB(A[0], A[1]);
    Line<Point> CD(A[2], A[3]);
    puts(AB.isParallel(CD) ? "YES" : "NO");
  }

  return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OUT(x) cout << (x) << endl;
#define REP(i, n) for (int i=0; i<n; ++i)

int main(){
    int N, a[100010];
    bool n[100010] = {0};
    cin >> N;
    REP(i, N) cin >> a[i+1];

    int now=1;
    int cnt=0;
    while(1) {
        if(now==2){
            break;
        }
        if(n[now]){
            cnt = -1;
            break;
        }
        n[now] = true; // 済フラグ
        now = a[now];
        cnt++;
    }
    OUT(cnt);
}


Measured memory_bytes: 768
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stack>
#include<queue>
#include<string>
#include<set>
#define ll long long
using namespace std;
int n;
int a[110000];
int main()
{
	int ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	 } 
	 for(int i=1;i<n;i++)
	 {
	 	if(a[i]==i)
	 	{
	 		swap(a[i],a[i+1]);
	 		ans++;
		 }
	 	
	 }
	 if(a[n]==n)
	 ans++;
	 printf("%d\n",ans);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll p[2200],a[100005],k[100005];
int cnt=0;
map<ll,int>x;
map<ll,bool>vis;
ll M(ll t,ll h)
{
    ll ans1=1,ans2=1;
    for(int i=0;i<cnt;i++)
    {
        int cot=0;
        while(t%p[i]==0) cot++,t/=p[i];
        cot%=3;
        if(cot==0) continue;
        if(cot==1)
        {
            ans1*=p[i],ans2*=p[i];
            if(ans2>1e10) ans2=0;
            ans2*=p[i];
        }
        else ans1*=p[i]*p[i],ans2*=p[i];
        if(ans2>1e10) ans2=0;
    }
    ans1*=t;
    ll w=(ll)sqrt(t);
    if(w*w==t)
        ans2*=w;
    else
    {
        ans2*=t;
        if(ans2>1e10) ans2=0;
        ans2*=t;
    }
    if(ans2>1e10) ans2=0;
    x[ans1]++;
    k[h]=ans2;
    return ans1;
}
int main()
{
    for(int i=2;i<=2200;i++)
    {
        bool flag=true;
        for(int j=2;j*j<=i;j++)
        if(i%j==0) {flag=false;break;}
        if(flag) p[cnt++]=i;
    }
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        ll m;
        scanf("%lld",&m);
        a[i]=M(m,i);
    }
    int ans=0;
    vis[1]=true;
    for(int i=1;i<=n;i++)
        if(!vis[a[i]]) ans+=max(x[a[i]],x[k[i]]),vis[a[i]]=vis[k[i]]=true;
    if(x[1]>=1) ans++;
    printf("%d\n",ans);
}

Measured memory_bytes: 22400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll k, a, b;
  cin >> k >> a >> b;
  ll n = 1;
  if(b - a > 1) {
    k -= a - 1;
    if(k <= 0)
      n += k;
    else {
      n = a;
      n += k / 2 * (b - a);
      n += k % 2;
    }
  } else
    n += k;
  cout << n << endl;
}

Measured memory_bytes: 3600
#!/usr/bin/env python3


def main():
    w, h, n = map(int, input().split())
    x_lb = y_lb = 0
    x_ub = w
    y_ub = h
    for _ in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            x_lb = max(x_lb, x)
        elif a == 2:
            x_ub = min(x_ub, x)
        elif a == 3:
            y_lb = max(y_lb, y)
        else:
            y_ub = min(y_ub, y)
    print(max(0, (x_ub - x_lb)) * max(0, (y_ub - y_lb)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;

int n, a[50], p, b = 0, c = 0;

ll nPr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}

	return res;
}

ll nCr(ll n, ll r) {
	//ll res = nPr(n, r) / nPr(r, r);
	double res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
		res /= (i+1);
	}
	return (ll)res;
}

int main() {
	cin >> n >> p;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0) {
			b++;
		}
		else {
			c++;
		}
	}

	//cout << "b:" << b << " c:" << c << endl;
	ll bsum = 0, csum = 0;
	bsum = (ll)pow(2, b);

	if (p == 0) {
		for (int i = 0; i <= c; i++) {
			if (i % 2 == 0) {
				csum += nCr(c, i);
			}
		}
	}
	else {
		for (int i = 0; i <= c; i++) {
			if (i % 2 == 1) {
				csum += nCr(c, i);
			}
		}
	}

	ll ans = bsum*csum;
	cout << ans << endl;
}

Measured memory_bytes: 384
N = int(input())
P = list(map(int, input().split()))

count = 0
for i in range(1, N):
    ma = max(P[i-1: i+2])
    mi = min(P[i-1: i+2])
    if P[i] != ma and P[i] != mi:
        count += 1
    
print(count)

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

void solve()
{
    string s;cin>>s;
    int ans=0;
    for(int i=0;i<3;i++)
    {
        int len=0;
        if(s[i]=='R')
        {
            while(i<3 && s[i]=='R')
            {
                i++;len++;
            }
        }
        ans=max(ans,len);
    }
    cout<<ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

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


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

long long dfs(long long H) {
  if(H == 1) return H;
  H = 2 * dfs(H / 2) + 1;
  return H;
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long H;
  cin >> H;
  cout << dfs(H) << endl;
  return 0;
}


Measured memory_bytes: 3656
n = int(input())
m = int(input())

card = [int(v) + 1 for v in range(2 * n)]
for i in range(m):
    k = int(input())
    if k == 0:
        next = [0] * 2 * n
        for x in range(n):
            next[x * 2] = card[x]
            next[x * 2 + 1] = card[x + n]
        card = next
    else:
        card = card[k:] + card[0: k]

for no in card:
    print(no)





Measured memory_bytes: 5628
N, x = map(int, input().split())
A = [int(x) for x in input().split()]

def f():
    As = sorted(A)
    s = 0
    for i,a in enumerate(As):
        s += a
        if x < s:
            return i
        if x == s:
            return i + 1
    return N - 1
print(f())

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
    public static int value(String data){
        return (data.charAt(1) - '0');
    }
    public static void print(String data[]){
        for(int i = 0 ; i < data.length-1 ; i++)
            System.out.print(data[i] + " ");
        System.out.println(data[data.length-1]);
    }
    public static void Sort(String data[], int n){
        String a[] = new String[n];
	String b[] = new String[n];
	for(int i = 0 ; i < n ; i++){
		a[i] = data[i];
		b[i] = data[i];
	}
	for(int i = 0 ; i < n-1 ; i++){
		for(int j = n-1 ; j > i ; j--){
			if(value(a[j]) < value(a[j-1])){
				String tmp = a[j];
				a[j] = a[j-1];
				a[j-1] = tmp;
			}
		}
	}
	print(a);
	System.out.println("Stable");
	for(int i = 0 ; i < n ; i++){
		int minj = i;
		for(int j = i ; j < n ; j++){
			if(value(b[j]) < value(b[minj]))
				minj = j;
		}
		String tmp = b[i];
		b[i] = b[minj];
		b[minj] = tmp;
	}
	print(b);
	for(int i = 0 ; i < n ; i++)
	{
		if(!(a[i].equals(b[i]))){
			System.out.println("Not stable");
			break;
		}
		else if(i == n-1)
			System.out.println("Stable");
	}
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String data[] = new String[n];
        for(int i = 0 ; i < n ; i++)
            data[i] = sc.next();
        Sort(data,n);
    }
}


Measured memory_bytes: 26396
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(void){
  int n,w,d,p,s;
  int i,j,x,y;
  vector<pii> ps;
  vector<int> res;
  while(cin>>n>>w>>d){
    if((n|w|d)==0) break;
    ps.clear();
    res.clear();
    ps.pb(pii(w,d));

    for(i=0;i<n;i++){
      cin>>p>>s;
      p--;
      x=ps[p].first;
      y=ps[p].second;
      s%=x*2+y*2;
      //if(x+y<=s&&s<=x+y+x) s=x+x+y-s;
      //if(x+y+x<=s) s=x+x+x+y+y-s;
      if(x+y<=s&&s<=x+y+x) s-=x+y;
      if(x+y+x<=s) s-=x+y;
      if(s==x||s==x+y) cout<<"kusowarota"<<endl;
      if(s<=x){
	if(s<=x/2){
	  ps.erase(ps.begin()+p);
	  ps.pb(pii(s,y));
	  ps.pb(pii(x-s,y));
	}
	else{
	  ps.erase(ps.begin()+p);
	  ps.pb(pii(x-s,y));
	  ps.pb(pii(s,y));
	}
      }
      else {
	s-=x;
	if(s<=y/2){
	  ps.erase(ps.begin()+p);
	  ps.pb(pii(x,s));
	  ps.pb(pii(x,y-s));
	}
	else{
	  ps.erase(ps.begin()+p);
	  ps.pb(pii(x,y-s));
	  ps.pb(pii(x,s));
	}
      }
    }
    
    for(i=0;i<ps.size();i++){
      res.pb(ps[i].first*ps[i].second);
    }
    sort(res.begin(),res.end());
    for(i=0;i<res.size();i++){
      cout<<res[i];
      if(i!=res.size()-1) cout<<" ";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3028
#include<cstdio>
int a[8];
int main(){
//	freopen("agc.in","r",stdin);
	for (int i=1;i<=7;++i) scanf("%d",&a[i]);
	long long ans=a[2];
	if (!a[1]||!a[4]||!a[5]){
		ans+=a[1]/2*2;ans+=a[4]/2*2;ans+=a[5]/2*2;
	}else{
		ans+=(long long)a[1]+a[4]+a[5];
		if (a[1]%2==a[4]%2&&a[4]%2==a[5]%2);else  ans--;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int t[] = new int[n];
		int v[] = new int[n];

		int sumt[] = new int[n+1];
		sumt[0]=0;
		for(int i=0; i<n; i++) {
			t[i]=sc.nextInt();
			sumt[i+1]=sumt[i]+t[i];
		}
		for(int i=0; i<n; i++) {
			v[i]=sc.nextInt();
		}

		double maxv[] = new double[sumt[n]*2+1];
		int INF = 1001001;
		for(int i=0; i<maxv.length; i++) {
			maxv[i]=INF;
		}
		int now=0;
		for(int i=0; i<n; i++) {
			for(int j=0; j<2*t[i]; j++) {
				maxv[now] = Math.min(maxv[now], v[i]);
				maxv[now+1] = Math.min(maxv[now+1], v[i]);
				now++;
			}
		}

		maxv[0]=0;
		maxv[sumt[n]*2]=0;

		for(int i=1; i<=sumt[n]*2; i++) {
			maxv[i]=Math.min(maxv[i], maxv[i-1]+0.5);
		}
		for(int i=sumt[n]*2-1; i>=0; i--) {
			maxv[i]=Math.min(maxv[i], maxv[i+1]+0.5);
		}
		double sum = 0.0;
		for(int i=1; i<=sumt[n]*2; i++) {
			sum += (maxv[i] + maxv[i-1]) * 0.25;
		}
		System.out.println(sum);
		sc.close();
	}


}


Measured memory_bytes: 36572
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] b = new int[N - 1];
    for (int i = 0; i < N - 1; i++) b[i] = scanner.nextInt();

    int sum = b[0] + b[N - 2];
    for (int i = 1; i < N - 1; i++) {
      sum += Math.min(b[i], b[i - 1]);
    }
    System.out.println(sum);
  }
}


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

a.sort()
a_max = a[-1]
ban = [0]*(a_max+1)

count = 0
for i in range(n):
    if ban[a[i]]:
        continue
    else:
        if i == n-1 or a[i+1] != a[i]:
            count += 1
        x = a[i]
        while x <= a_max:
            ban[x] = 1
            x += a[i]
#print(ban)
print(count)

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n = in();
    vvint f(n, vint(10));
    rep(i, n) rep(j, 10) cin >> f[i][j];
    vvint p(n, vint(11));
    rep(i, n) rep(j, 11) cin >> p[i][j];

    int ans = -INF;
    rep(bit, (1 << 10))
    {
        if (bit == 0)
            continue;
        vint cnt(n, 0);
        rep(i, 10)
        {
            if (bit & (1 << i))
            {
                rep(j, n)
                {
                    if (f[j][i])
                        ++cnt[j];
                }
            }
        }

        int sum = 0;
        rep(i, n)
        {
            sum += p[i][cnt[i]];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#参考 https://atcoder.jp/contests/abc116/submissions/4059000
n, k = map(int,input().split())
# 価値の大きい順にソート, おいしさが前に来るようにした
sushi = sorted(list(map(int, input().split()))[::-1] for i in range(n))[::-1]
s = set()
# 二個以上あるものの集合があれば良い,かつ最小順
q = []
kiso = 0
for i in range(k):
    d, t = sushi[i]
    if t in s:
        q.append(d)
    else:
        s.add(t)
    kiso += d
ans = kiso + len(s)**2

# 減らせる ∧ 増やせる
i = k
while i < n and q:
    d, t = sushi[i]
    if t not in s:
        s.add(t)
        kiso += -q.pop()+d
        ans = max(ans, kiso+len(s)**2)
        continue
    i+=1
print(ans)

Measured memory_bytes: 22768
#include<iostream>
using namespace std;
int main(void)
{
int x;
while(cin>>x)
{
int a[10]={1,2,4,8,16,32,64,128,256,512};
int b[10]={0};

int j=0;
for(int i=9;i>=0;i--)
{
	if(x>=a[i])
	{
	x-=a[i];
	b[j]=a[i];
	j++;
	if(x==0)break;
	}
}
for(int i=9;i>=0;i--)
{
if(b[i]==0)continue;
else if(b[i]!=0)cout<<b[i]<<(i==0?"\n":" ");
}
}
return 0;
}

Measured memory_bytes: 1160
s = input()[::-1]
t = input()[::-1]

for i in range(len(s) - len(t) + 1):
    check = True
    for j in range(len(t)):
        if s[i+j] == t[j]:
            pass
        elif s[i+j] == "?":
            pass
        else:
            check = False
            break
        
    if check:
        s = list(s)
        t = list(t)
        s[i:i+len(t)] = t
        s = "".join(s)
        s = s.replace("?","a",50)
        print(s[::-1])
        exit()
            
print("UNRESTORABLE")
            



Measured memory_bytes: 9068
import java.util.Scanner;
public class Main {

	public static void main(String[] args)throws Exception {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int T=stdIn.nextInt();
		int t[]=new int[N];
		int key=0;
		int z=0;
		while(z<N) {
			t[z]=stdIn.nextInt();
			if(z!=0) {
				if(t[z]-t[z-1]>T) 
					key+=T;
				else
					key+=t[z]-t[z-1];
			}
			z++;
		}key+=T;
		System.out.println(key);
	}
}

Measured memory_bytes: 81092
def resolve():
    line = input()
    result = [0] * len(line)

    r_odd = 0
    r_even = 0
    for i in range(len(line)):
        if line[i] == 'L':
            if i % 2 == 0:
                result[i] += r_even
                result[i-1] += r_odd
            else:
                result[i] += r_odd
                result[i-1] += r_even
            r_odd = 0
            r_even = 0
        elif line[i] == 'R':
            if i % 2 == 0:
                r_even += 1
            else:
                r_odd += 1
    l_odd = 0
    l_even = 0
    for i in range(len(line)-1, -1, -1):
        if line[i] == 'R':
            if i % 2 == 0:
                result[i] += l_even
                result[i+1] += l_odd
            else:
                result[i] += l_odd
                result[i+1] += l_even
            l_odd = 0
            l_even = 0
        elif line[i] == 'L':
            if i % 2 == 0:
                l_even += 1
            else:
                l_odd += 1

    print(*result)
    
resolve()

Measured memory_bytes: 79188
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

pub trait LexicalPermutation {
    fn next_permutation(&mut self) -> bool;
    fn prev_permutation(&mut self) -> bool;
}

impl<T> LexicalPermutation for [T]
where
    T: Ord,
{
    fn next_permutation(&mut self) -> bool {
        if self.len() < 2 {
            return false;
        }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] >= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        let mut j = self.len() - 1;
        while j >= i && self[j] <= self[i - 1] {
            j -= 1;
        }
        self.swap(j, i - 1);
        self[i..].reverse();
        true
    }

    fn prev_permutation(&mut self) -> bool {
        if self.len() < 2 {
            return false;
        }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] <= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        self[i..].reverse();
        let mut j = self.len() - 1;
        while j >= i && self[j - 1] < self[i - 1] {
            j -= 1;
        }
        self.swap(i - 1, j);
        true
    }
}

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut left = vec![0 as i64; n];
    let mut right = vec![0 as i64; n];
    left[0] = a[0];
    for i in 1..n {
        left[i] = left[i - 1] + a[i];
    }
    right[n - 1] = a[n - 1];
    for i in (1..n).rev() {
        right[i - 1] = right[i] + a[i - 1];
    }
    // println!("{:?} {:?}", left, right);
    let mut result = 1000000000000;
    for i in 1..n {
        let m = (left[i - 1] - right[i]).abs();
        if m < result {
            result = m;
        }
    }
    println!("{}", result);
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x >= y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x <= y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  string s;
  cin >> s;
  string t = "CODEFESTIVAL2016";
  int ans = 0;
  rep(i, 16) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scn = new Scanner(System.in);
        
        while(true){
            String str = scn.nextLine();

            if(str.equals(".")) break;

            str = str.replaceAll("[a-z A-Z \\.]","");

            while(true){
                String st = str;
                str = str.replaceAll("\\(\\)|\\[\\]","");
                if(st.equals(str)) break;
            }
            if(str.equals("")) System.out.println("yes");
            else System.out.println("no");
        }
    }
}



Measured memory_bytes: 68308