akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = (ll)INT_MAX*100;
const ll MOD = 1e9+7;

int N;
ll A[212345];
ll dp[2][212345][16];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N;
  repeat(i,N){
    cin>>A[i];
  }
  for(int l=N-1;l>=0;l--){
    //debug(l);
    repeat(x,16){
      if(l==N-1){
        dp[0][l][x] = x;
      }else{
        ll cnt=0;
        ll a=1;
        while(A[l]>A[l+1]*a){
          a<<=2;
          cnt++;
        }
        a=1;
        ll c=0;
        while(A[l+1]>=A[l]*a){
          a<<=2;
          c++;
        }
        c = max(0ll,c-1);
        cnt += max(0ll,x-c);
        //debug(x);
        //debug(cnt);
        if(cnt<=15){
          dp[0][l][x] = x+dp[0][l+1][cnt];
        }else{
          dp[0][l][x] = x+dp[0][l+1][15]+(N-l-1)*(cnt-15);
        }
      }
    }
  }

  for(int l=1;l<N;l++){
    repeat(x,16){
      if(l==1){
        dp[1][l][x] = x;
      }else{
        ll cnt=0;
        ll a=1;
        while(A[l-1]>A[l-2]*a){
          a<<=2;
          cnt++;
        }
        a=1;
        ll c=0;
        while(A[l-2]>=A[l-1]*a){
          a<<=2;
          c++;
        }
        c = max(0ll,c-1);
        cnt += max(0ll,x-c);
        if(cnt<=15){
          dp[1][l][x] = x+dp[1][l-1][cnt];
        }else{
          dp[1][l][x] = x+dp[1][l-1][15]+(l-1)*(cnt-15);
        }
      }
    }
  }

  //debugArray(dp[1][1],16);
  ll ans=INF;
  for(ll i=0;i<N;i++){
    ans = min(ans,i+2*dp[1][i][0]+2*dp[0][i][0]);
    //debug(ans);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 54912
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

struct LCA {
    vector<vector<int>> par;
    vector<int> d;
    int n;
    LCA(vector<vector<int>> graph, int root) {
        n = graph.size();
        par.resize(n, vector<int>(30));
        d.resize(n, 0);
        function<void(int, int, int)> dfs = [&](int c, int p, int depth) {
            d[c] = depth;
            par[c][0] = p;
            for (auto ch : graph[c]) {
                if (ch != p) dfs(ch, c, depth + 1);
            }
        };
        dfs(0, 0, 0);
        for (int j = 1; j < 30; j++) {
            REP(i, n) { par[i][j] = par[par[i][j - 1]][j - 1]; }
        }
    }
    int getdistance(int u, int v) { return (d[u] + d[v]) - 2 * (d[query(u, v)]); }
    int query(int u, int v) {
        if (d[u] > d[v]) {
            swap(u, v);
        }
        for (int i = 29; 0 <= i; i--) {
            if (d[u] <= d[par[v][i]]) {
                v = par[v][i];
            }
        }
        /* LCA */
        for (int i = 29; 0 <= i; i--) {
            if (par[v][i] != par[u][i]) {
                v = par[v][i];
                u = par[u][i];
            }
        }
        if (u == v) {
            return u;
        } else {
            return par[v][0];
        }
    }
};

struct UnionFind {
    vector<int> parent, size;
    UnionFind(int n) {
        parent.resize(n, -1);
        size.resize(n, 1);
    }
    void unite(int x, int y) {
        if (same(x, y)) {
            return;
        }
        x = root(x);
        y = root(y);
        if (size[x] <= size[y]) {
            swap(x, y);
        }
        parent[y] = x;
        size[x] += size[y];
    }
    bool same(int x, int y) { return (root(x) == root(y)); }
    int root(int x) {
        while (parent[x] != -1) {
            x = parent[x];
        }
        return x;
    }
    int getsize(int x) { return size[root(x)]; }
};
int n, m;
vector<vector<int>> graph;

signed main() {
    int n;
    cin >> n;
    vector<long long> as(n);
    REP(i, n) { cin >> as[i]; }
    as.erase(unique(as.begin(), as.end()), as.end());
    REP(i, as.size() - 1) { cout << as[i] << " "; }
    cout << as[as.size() - 1] << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N, M;
int ac[100000], wa[100000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M;
    int a1 = 0, a2 = 0;
    for(int i = 0; i < M; i++){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "AC") {
            if(ac[p] == 0) a1++;
            ac[p] = 1;
        }
        else {
            if(ac[p] == 0) wa[p]++;
        }        
    }
    for(int i = 0; i < N; i++){
        if(ac[i] == 1) a2 += wa[i];
    }
    cout << a1 << ' ' << a2 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long n,k,r,s,p,dp[3][100003],ans;
string t;
void did(int x){
	if(t[x]=='s')dp[0][x]+=r;
	if(t[x]=='p')dp[1][x]+=s;
	if(t[x]=='r')dp[2][x]+=p;
}
int main(){
	cin>>n>>k>>r>>s>>p>>t;
	for(int i=0;i<k;i++)did(i);
	for(int i=k;i<n;i++){
		dp[0][i]=max(dp[1][i-k],dp[2][i-k]);
		dp[1][i]=max(dp[0][i-k],dp[2][i-k]);
		dp[2][i]=max(dp[0][i-k],dp[1][i-k]);
		did(i); 
	}
	for(int i=n-k;i<n;i++)ans+=max(dp[0][i],max(dp[1][i],dp[2][i]));
	cout<<ans;
}

Measured memory_bytes: 2816
/*input
8
1 2 1 4 2 1 4 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
 
const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    ll sum = 0;
    vector<int> a(n);
    vector<ll> freq(n + 1, 0);
    for(int i = 0; i < n; i++)
    {
    	cin >> a[i];
    	freq[a[i]]++;
    }
    for(int i = 1; i < n + 1; i++) sum += (freq[i] * (freq[i] - 1))/2;
    for(int i = 0; i < n; i++) cout << sum - freq[a[i]] + 1 << endl;
 
    return 0;
}

Measured memory_bytes: 4992
#　変数 n, m, k, arr1, arr2, acum1, acum2, ans

#累積和二つ
#aを回して
#bから条件をみたさないものを引いていく

n, m, k = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

acum1 = [0]
for i in range(n):
    acum1.append( acum1[-1] + arr1[i] )

acum2 = [0]
for i in range(m):
    acum2.append( acum2[-1] + arr2[i])

ans = 0
j = m
for i in range(n+1): 
    if acum1[i] > k:
        break
    while acum2[j] > k - acum1[i] and j>0: #なぜwhile?

            j -= 1
    ans = max(ans,i+j)

print(ans)

Measured memory_bytes: 47544
n=int(input())
l=[int(i) for i in input().split()]
ml=[0]
for i in l:
    res=ml[-1]
    if res<=i:
        ml.append(i)
    else:
        ml.append(res)
ans=0
for i in range(n):
    if ml[i+1]<=l[i]:
        ans+=1
print(ans)

Measured memory_bytes: 3064
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;


//拡張Euclidの互除法
//ap + bq = gcd(a,b) となる(p,q)を求め、gcd(a,b)を返す
long long exGCD(long long a, long long b, long long &p, long long &q){
    if(b==0){
        p=1; q= 0;
        return a;
    }
    long long d = exGCD(b,a%b,q,p);
    q -= a/b * p;
    return d;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int64 a,b; cin >> a >> b;

    int64 p,q; exGCD(a,b,p,q);
    cout << p << " " << q << endl;
}


Measured memory_bytes: 3168
import sys
import numpy as np

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

count = 0
for i in range(N):
    if A[i] < 0:
        count += 1

A_abs = np.abs(A)
if count % 2 == 0:
    print(np.sum(A_abs))
else:
    print(np.sum(A_abs) - 2 * np.min(A_abs))

Measured memory_bytes: 23304
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int ans[10000];
bool get(int x, int y)
{
	printf("? %d %d\n", x, y);
	fflush(stdout);
	char z;
	scanf(" %c", &z);
	return z == 'Y';
}
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if (a <= b)
	{
		printf("Impossible\n");
		fflush(stdout);
		return 0;
	}
	vector<int>v;
	for (int i = 0; i < a + b; i++)
	{
		if (v.empty())v.push_back(i);
		else
		{
			bool f = get(v[v.size() - 1], i);
			if (!f)v.pop_back();
			else v.push_back(i);
		}
	}
	for (int i = 0; i < a + b; i++)ans[i] = get(v[v.size() - 1], i);
	printf("! ");
	for (int i = 0; i < a + b; i++)printf("%d", ans[i]); printf("\n");
	fflush(stdout);
}

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

int main() {
  int N;
  cin >> N;
  int a,b,c,d;
  a = (N - N % 1000) / 1000;
  b = (N % 1000 - N % 100) / 100;
  c = (N % 100 - N % 10) / 10;
  d = N % 10;

  if(a == b  && b == c || b  == c && c == d){ 
    cout << "Yes" << endl; 
  }
  else if(a == b && b == c && c == d) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll l[90], i, n;
  scanf("%lld", &n);
  l[0] = 2, l[1] = 1;
  for(i = 2; i <= n; ++i) l[i] = l[i - 1] + l[i - 2];
  printf("%lld", l[n]);
  return 0;
}

Measured memory_bytes: 128
use proconio::input;
use proconio::fastout;


#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [usize; n],
    }

    let mut appear: Vec<usize> = vec![0; 1000001];
    for v in &a {
        appear[*v] += 1;
    }

    let mut ans = 0;
    a.sort();
    for v in &a {
        if appear[*v] == 1 {
            ans += 1;
        }
        if appear[*v] > 0 {
            for i in (*v .. 1000001).step_by(*v) {
                appear[i] = 0;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 13264
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void){
    ll n, m;
    cin >> n >> m;
    string s, t;
    string cs, ct;
    cin >> s >> t;
    ll ans = n*m/__gcd(n, m);
    bool check = true;
    for(ll i = 0; i < s.length(); i+=(n/__gcd(n, m)))
        cs+=s[i];
    for(ll i = 0; i < t.length(); i+=(m/__gcd(n, m)))
        ct+=t[i];
    //cout << cs << " " << ct << endl;
    if(check==true && cs==ct)
        cout << ans << endl;
    else
        cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;
using std::vector;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){
 
  int n, m; cin >> n >> m;
  vi v(m);
  rep(i, m) cin >> v[i];

  sort(all(v));
  vi sub;

  for(int i = 1; i < m; i++)
    sub.pb(v[i] - v[i - 1]);  

  sort(rall(sub));
  ll ans = 0;
  for(int i = n - 1; i < sub.size(); i++)
    ans += sub[i];

  pr(ans);

  return 0;
}


Measured memory_bytes: 1276
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int N;
int ball[10];
int l[20],r[20];
bool flag;
void DFS(int i,int ll,int rr)//i:当前所放球的序号 ll:左边该第ll位放球 rr:右边该第rr位放球
{
    if(i>=10)
        flag=1;
    if(ball[i]>l[ll-1])
    {
        l[ll]=ball[i];
        DFS(i+1,ll+1,rr);
    }
    if(ball[i]>r[rr-1])
    {
        r[rr]=ball[i];
        DFS(i+1,ll,rr+1);
    }
}
int main()
{
    scanf("%d",&N);
    while(N--)
    {
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        for(int i=0;i<10;i++)
            scanf("%d",&ball[i]);
        flag=0;
        DFS(0,1,1);
        if(flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int DP[3005][3005];
int DP2[3005][3005];

int main(){
    int N,T;
    cin >> N >> T;
    vector<int> A(N+1), B(N+1);
    rep1(i,N) cin >> A[i] >> B[i];
    
    rep1(i,N) rep(j,3005){
        if(j-A[i]>=0) DP[i][j] = max(DP[i-1][j], DP[i-1][j-A[i]]+B[i]);
        else DP[i][j] = DP[i-1][j];
    }
    
    vector<int> C(N+1), D(N+1);
    rep(i,N) C[i] = A[N-i+1], D[i] = B[N-i+1];
    
    rep1(i,N) rep(j,3005){
        if(j-C[i]>=0) DP2[i][j] = max(DP2[i-1][j], DP2[i-1][j-C[i]]+D[i]);
        else DP2[i][j] = DP2[i-1][j];
    }

    int ans = 0;
    rep1(i,N){
        int sum = 0;
        rep(j,T){
            sum = max(sum, DP[i-1][j]+DP2[N-i][T-1-j]);
        }
        ans = max(ans, sum+B[i]);
    }
    
    pr(ans);

}


Measured memory_bytes: 70784
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		String[] ka = new String[v];
		List<String> k = new ArrayList<String>();

		for (int i = 1; i < 14; i++) {
			k.add("S " + i);
		}// S?????????????????§
		for (int i = 1; i < 14; i++) {
			k.add("H " + i);
		}// H?????????????????§
		for (int i = 1; i < 14; i++) {
			k.add("C " + i);
		}// C?????????????????§
		for (int i = 1; i < 14; i++) {
			k.add("D " + i);
		}// D?????????????????§
		for (int i = 0; i < v; i++) {
			ka[i] = sc.nextLine();
		}// ?????£????????????????????§
		List<String> klist = new ArrayList<String>();

		for (String string : k) {
			int ok = 0;// ?????£???????????????
			for (int i = 0; i < ka.length; i++) {

				if (string.equals(ka[i])) {
					ok += 1;// ?????£??????
				} else {

				}

			}
			// ?????£???????????£???
			if (ok == 0) {
				klist.add(string);
			}
		}

		Comparator<String> comparator = new SampleComparator();
		Collections.sort(klist, comparator);// ????????????



		for (String string : klist) {
			if (string.startsWith("S")) {
				System.out.println(string);
			}// S????????£???????????????

		}
		for (String string : klist) {
			if (string.startsWith("H")) {
				System.out.println(string);
			}// H????????£???????????????

		}
		for (String string : klist) {
			if (string.startsWith("C")) {
				System.out.println(string);
			}// C????????£???????????????

		}
		for (String string : klist) {
			if (string.startsWith("D")) {
				System.out.println(string);
			}// D????????£???????????????

		}
	}

}

class SampleComparator implements Comparator<String> {
	@Override
	public int compare(String s1, String s2) {

		String a = s1.substring(2);
		String b = s2.substring(2);
		int c = Integer.parseInt(a);
		int d = Integer.parseInt(b);

		return c - d;
	}
}

Measured memory_bytes: 26284
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define pc pair<char,ll>

void solve()
{
    string s;
    cin>>s;
    s=s+"#";
    ll k;
    cin>>k;
    ll ans=0;
    vector<pair<char,ll> > vec;
    char current=s[0];
    ll count=1;
    for (ll i=1; i<s.length(); i++)
    {
        if (s[i]!=current)
        {
            vec.push_back(pc(current,count));
            current=s[i];
            count=1;
        }
        else
        {
            count++;
        }
    }
    if (sz(vec)==1)
    {
        // cout<<"a"<<" "<<endl;
        ll ans=((sz(s)-1)*k)/2;
        cout<<ans<<endl;
        return;
    }
    for (ll i=1; i<sz(vec)-1; i++)
    {
        ll num=vec[i].second;
        ans+=k*(num/2);
    }
    // cout<<ans<<endl;
    ans+=vec[0].second/2;
    ans+=vec[sz(vec)-1].second/2;
    // cout<<ans<<endl;
    if (vec[0].first!=vec[sz(vec)-1].first)
        ans+=(k-1)*((vec[0].second/2+vec[sz(vec)-1].se/2));
    else
    {
        ans+=(k-1)*((vec[0].second+vec[sz(vec)-1].se)/2);
    }
    cout<<ans<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    t=1;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

//0-index 抽象化半開区間遅延セグツリー
template<typename T, typename E>
class segment_tree{
    typedef function<T(T,T)> F; //要素に適用する演算
    typedef function<T(T,E)> G; //作用素の適用
    typedef function<E(E,E)> H; //作用素の合成
    typedef function<E(E,int)> P;
private:
    int num_of_elm_;
    vector<T> dat_, lazy_;
    F f_;
    G g_;
    H h_;
    P p_;
    T ident_;
    E op_ident_;
public:
    segment_tree(int n, F f, G g, H h, P p, T ident, E op_ident):f_(f), g_(g), h_(h), p_(p), ident_(ident), op_ident_(op_ident){
        num_of_elm_ = 1;
        while(num_of_elm_<n)num_of_elm_*=2;
        dat_ .resize(2*num_of_elm_,ident);
        lazy_.resize(2*num_of_elm_,op_ident);
    }
    
    void eval(int k, int len){
        if(lazy_[k] == op_ident_)return ;
        
        if(k<num_of_elm_){
            lazy_[k*2]=h_(lazy_[k*2], lazy_[k]);
            lazy_[k*2+1]=h_(lazy_[k*2+1], lazy_[k]);
        }
        dat_[k] = g_(dat_[k],p_(lazy_[k], len));
        lazy_[k] = op_ident_;
    }
    
    T update(int L, int R, int val, int l=0, int r=0, int k=1){
        if(k==1)r = num_of_elm_;
        
        eval(k,r-l);
        if(r<=L || R<=l)return dat_[k];
        else if(L<=l && r<=R){
            lazy_[k] = h_(lazy_[k], val);
            return g_(dat_[k], p_(lazy_[k], r-l));
        }
        else{
            return dat_[k] = f_(update(L,R,val,l,(l+r)/2,k*2), update(L,R,val,(l+r)/2,r,k*2+1));
        }
        
    }
    
    T query(int L, int R,int l=0,int r=0, int k=1){
        if(k==1)r = num_of_elm_;
        
        eval(k,r-l);
        if(r<=L || R<=l)return ident_;
        else if(L<=l && r<=R){
            return dat_[k];
        }
        else{
            return f_(query(L,R,l,(l+r)/2,k*2), query(L,R,(l+r)/2,r,k*2+1));
        }
    }
};

int main(){
    int n,q;
    cin>>n>>q;
    auto f = [](int a, int b){return min(a,b);};
    auto g = [](int a, int b){return b;};
    auto h = g;
    auto p = [](int a, int len){return a;};
    segment_tree<int,int> st(n, f, g, h, p, (1LL<<31)-1, -1);
    rep(i,q){
        int com;
        cin>>com;
        if(com==0){
            int s,t,x;
            cin>>s>>t>>x;
            st.update(s,t+1,x);
        }else{
            int x,y;
            cin>>x>>y;
            cout<<st.query(x,y+1)<<endl;
        }
    }
}




Measured memory_bytes: 4956
#include <iostream>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<long long> a(N);
  for(int i = 0; i < N; i++) cin >> a[i];
  
  long long sum = 0;
  for(int i = 0; i < N; i++){
  	sum += a[i];
    if(i == 0)continue;
    a[i] += a[i - 1];
  }
  
  long long ans = LLONG_MAX;
  for(int i = 0; i < N - 1; i++){
  	ans = min(ans, abs(a[i] - (sum - a[i])));
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
//        int t=scanner.nextInt();
//        for(int j=0;j<t;j++){
//            
//        }
        String s=scanner.next();
        if(s.charAt(2)==s.charAt(3) && s.charAt(4)==s.charAt(5)){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }

}


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

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

using namespace std;

typedef long long ll;

#define MAX 100100
int V;
vector<int> G[MAX];

vector<int> path;
bool dfs(int cur,int pre) {
  if( cur == V-1 ) {
    path.push_back(cur);
    return true;
  }
  rep(i,(int)G[cur].size()) {
    int nex = G[cur][i];
    if( nex == pre ) continue;
    if( dfs(nex,cur) ) {
      path.push_back(cur);
      return true;
    }
  }
  return false;
}

int color[MAX];

void compute() {
  assert( dfs(0,-1) );
  reverse(path.begin(),path.end());
  //rep(i,(int)path.size()) cout << i << " : " << path[i] << endl;
  memset(color,-1,sizeof color);
  int n = (int)path.size() / 2;
  if( (int)path.size() & 1 ) ++n;
  deque<int> deq;
  rep(i,(int)path.size()) {
    int v = path[i];
    if( i < n ) color[v] = 1, deq.push_back(v);
    else        color[v] = 0;   
  }

  while( !deq.empty() ) {
    int cur = deq.front(); deq.pop_front();
    rep(i,(int)G[cur].size()) {
      int nex = G[cur][i];
      if( color[nex] == -1 ) {
	color[nex] = 1;
	deq.push_back(nex);
      }
    }
  }

  int F = 0, S = 0;
  rep(i,V) {
    if( color[i] == 1 ) ++F;
    else ++S;
  }
  if( F >  S ) puts("Fennec");
  else         puts("Snuke");

}

int main() {
  cin >> V;
  rep(i,V-1) {
    int a,b;
    cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  compute();
  return 0;
}

Measured memory_bytes: 11384
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
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;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll n,m,q,a[55],b[55],c[55],d[55],now[55],ans;
void dfs(int pos)
{
    if(pos==n+1)
    {
        ll cnt=0;
        for(int i=1;i<=q;i++)
        {
            if(now[b[i]]-now[a[i]]==c[i])
            {
                cnt+=d[i];
            }
        }
        ans=max(ans,cnt);
        return;
    }
    for(int i=now[pos-1];i<=m;i++)
    {
        now[pos]=i;
        dfs(pos+1);
    }
}
int main()
{
    //IOS;
    now[0]=1;
    cin>>n>>m>>q;
    for(int i=1;i<=q;i++)
    {
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    dfs(1);
    cout<<ans;

    return 0;
}
/*

*/


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    double x;
    cin >> x;

    int ans = 0;
    s64 a = 100;
    while (a < x)
    {
        a *= 1.01;
        ++ans;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

vin dx={-1,0,1,0};
vin dy={0,1,0,-1};
int w,h;

int dfs(vvch &c,int x,int y,int &res){
    c[y][x]='?';
    int nx,ny;
    rep(i,4){
        nx=x+dx[i];
        ny=y+dy[i];
        if(0<=nx&&nx<w&&0<=ny&&ny<h&&c[ny][nx]=='.'){
            res++;
            dfs(c,nx,ny,res);
        }
    }
    return res;
}

int main(){
    queue<int> ans;int res;
    while(1){
        cin>>w>>h;
        if(w==0)break;
        vvch c(h,vch(w));int sx,sy;
        rep(i,h)rep(j,w){
            cin>>c[i][j];
            if(c[i][j]=='@'){
                sx=j;
                sy=i;
            }
        }
        res=1;
        ans.push(dfs(c,sx,sy,res));
    }
    while(ans.size()){
        cout<<ans.front()<<endl;
        ans.pop();
    }
}


Measured memory_bytes: 3052
#include<stdio.h>
int main(void)
{
	int a,b,c,i,cnt;
	scanf("%d %d %d",&a,&b,&c);
	cnt=0;
	for(i=a;i<=b;i++){
		if(c%i==0)	cnt++;
	}
	printf("%d\n",cnt);
}


Measured memory_bytes: 2116
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  for(int i = 7; i >= 0; i-- ){
    if(pow(2,i) <= n){
      cout << pow(2,i) << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 384
/*
 　　　　　／＞　 フ
 　　　　　| 　_　 _|
 　 　　　／`ミ _x 彡
 　　 　 /　　　 　 |
 　　　 /　  ヽ　　 ?
 　／￣|　　 |　|　|
 　| (￣ヽ＿_ヽ_)_)
 　＼二つ
*/

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
    static short st[30];short tp=0;
    if(x<0) putchar('-'),x=-x;
    do st[++tp]=x%10,x/=10; while(x);
    while(tp) putchar('0'|st[tp--]);
    putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

%:define Pa pair<int, int> 
const int N = 105000;
const int inf = 1e9;
priority_queue<Pa> q1, q2, q3, q4;
int x[N], y[N], z[N];
int vis[N], A, B, C, n;

Pa get(priority_queue<Pa> &q) { while (vis[q.top().se]) q.pop(); return q.top(); }

int main() {
    read(A), read(B), read(C), n = A + B + C; ll ans = 0;
    for (int i = 1;i <= n; i++) {
        read(x[i]), read(y[i]), read(z[i]);
        ans += z[i], x[i] -= z[i], y[i] -= z[i];
        q1.push(MP(x[i], i)), q2.push(MP(y[i], i));
    }
    /* write(ans); */
    /* for (int i = 1;i <= n; i++) write(x[i], ' '), write(y[i]); */
    while (A || B) {
        Pa t1 = get(q1), t2 = get(q2);
        if (!A) { q3.empty() ? t1.fi = -inf : t1.fi += q3.top().fi; }
        if (!B) { q4.empty() ? t2.fi = -inf : t2.fi += q4.top().fi; }
        if (t1.fi > t2.fi) {
            vis[t1.se] = 1, ans += t1.fi;
            if (A) A--;
            else { B--; Pa t = q3.top(); q3.pop(); q4.push(MP(-t.fi, t.se)); }
            q3.push(MP(y[t1.se] - x[t1.se], t1.se));
        }
        else {
            vis[t2.se] = 1, ans += t2.fi;
            if (B) B--;
            else { A--; Pa t = q4.top(); q4.pop(); q3.push(MP(-t.fi, t.se)); }
            q4.push(MP(x[t2.se] - y[t2.se], t2.se));
        }
    }
    write(ans);
    return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const int MOD = 1e9+7;
const int MAXN = 2e5+3;
const int INF = 1e9;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    //int ntest; cin >> ntest; while(ntest--)
    {
        int n,k; cin >> n >> k;
        vector<int> b(n);
        fori(i,k) {
            int d; cin >> d;
            while(d--) {
                int a; cin >> a;
                b[a-1] = 1;
            }
        }
        int c = 0;
        fori(i,n) c += b[i]==0;
        cout << c << endl;
    }

    return 0;
}


Measured memory_bytes: 3656
package main

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

func wordScanner(n int) *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	b := make([]byte, n)
	s.Buffer(b, n)
	return s
}

func scanNAndIntSlice(s *bufio.Scanner) (int, []int) {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n, scanIntSlice(s, n)
}

func scanIntSlice(s *bufio.Scanner, n int) []int {
	vals := make([]int, n)
	for i := range vals {
		s.Scan()
		m, _ := strconv.Atoi(s.Text())
		vals[i] = m
	}
	return vals
}

func main() {
	s := wordScanner(100)
	_, h := scanNAndIntSlice(s)

	cur := 0
	mv, ans := 0, 0
	for _, hi := range h {
		if hi <= cur {
			mv++
		} else {
			mv = 0
		}
		if mv > ans {
			ans = mv
		}
		cur = hi
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3072
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Pi = Sarray();
            var ans = 0L;
            var cnt = 0L;
            for (var i = 0; i <Pi.Length; ++i)
            {
                if (Pi[i] == i + 1)
                {
                    ++cnt;
                }
                else
                {
                    ans += (cnt + 1) / 2;
                    cnt = 0;
                }
            }
            ans += (cnt + 1) / 2;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 21216
#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    if(n>=1800)
    cout<<1;
    else if(n>=1600)
    cout<<2;
    else if(n>=1400)
    cout<<3;
    else if(n>=1200)
    cout<<4;
    else if(n>=1000)
    cout<<5;
    else if(n>=800)
    cout<<6;
    else if(n>=600)
    cout<<7;
    else
    {
        cout<<8;
    }
    


    
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(auto &a: A)
        cin >> a;
    
    A.insert(A.begin(), 0);
    A.push_back(0);
    
    int sum = 0;
    for(int i=0; i<=N; i++)
        sum += abs(A[i+1]-A[i]);
    
    for(int i=1; i<=N; i++){
        int sub = 0;
        
        if(A[i-1] < A[i] && A[i+1] < A[i]){
            sub = min(abs(A[i]-A[i-1]), abs(A[i]-A[i+1]));
        }
        if(A[i] < A[i-1] && A[i] < A[i+1]){
            sub = min(abs(A[i]-A[i-1]), abs(A[i]-A[i+1]));
        }
        cout << sum-sub*2 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1656
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 22 16:00:08 2018
ABC067C
@author: maezawa
"""
n = int(input())
a = list(map(int, input().split()))

total = sum(a)
cum = a[0]
dif = abs(total - 2*cum)

for i in range(1,n-1):
    cum += a[i]
    if abs(total-2*cum) < dif:
        dif = abs(total-2*cum)
        
print(dif)

Measured memory_bytes: 24812
using System;

class Program
{
  static void Main(string[] args)
  {
    int N = int.Parse(Console.ReadLine());
    int[] A = new int[N];
    int[] B = new int[N];

    for (var i = 0; i < N; i++)
    {
      A[i] = int.Parse(Console.ReadLine());
      B[i] = A[i];
    }

    Array.Sort(A);

    foreach(var b in B)
    {
      if (b != A[N - 1]) //bが最大値と同じでないとき
      {
        Console.WriteLine(A[N - 1]);
      } else //bが最大値と同じである場合
      {
        Console.WriteLine(A[N - 2]);
      }
    }
  }
}

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int main(){
  int N;
  cin >> N;
  bool flag = true;
  rep(i, N){
    int a;
    cin >> a;
    if(a%2 == 0){
      if(a % 3 != 0 && a % 5 != 0) flag = false;
    }
  }
  if(flag){
    cout << "APPROVED" <<endl;
  }else{
    cout << "DENIED" << endl;
  }
}
  

Measured memory_bytes: 256
//ITP1_7_A_19140837_小島優希也
//学習番号 19140837     氏名　小島優希也
#include <iostream>
#include <vector>
using namespace std;

struct test {
    int mid;
    int final;
    int retest;
};

int main(void) {
    vector<test> data;
    while (true) {
        int m, f, r;
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1){
            break;
        }
        else {
            data.push_back((test){m, f, r});
        }
    }
    for (int i = 0; i < data.size(); i++) {
        int sum = data.at(i).mid + data.at(i).final;
        if (data.at(i).mid == -1 || data.at(i).final == -1) cout << "F" << endl;
        else if (sum >= 80) cout << "A" << endl;
        else if (sum >= 65) cout << "B" << endl;
        else if (sum >= 50) cout << "C" << endl;
        else if (sum >= 30 && data.at(i).retest >= 50) cout << "C" << endl;
        else if (sum >= 30) cout << "D" << endl;
        else cout << "F" << endl;
    }
    return 0;
}




Measured memory_bytes: 3120
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

Int Min(const Int a, const Int b) {
    if (a <= b) {
        return a;
    } else {
        return b;
    }
}

int main(void) {
    Int n, a, b;
    cin >> n >> a >> b;
    cout << Min(n * a, b) << endl;
    return 0;
}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c;
	cin>>a>>b>>c;
	if(a==b && c!=b)
		cout<<"Yes"<<endl;
	else if(b==c && a!=b)
		cout<<"Yes"<<endl;
	else if(a==c && b!=c)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

return 0;
}

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

int main() {
    int n, q;
    cin >> n;
    int s[n];
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    cin >> q;
    int t[q];
    for(int i = 0; i < q; i++){
        cin >> t[i];
    }
    
    long cnt = 0;
    for(int i = 0; i < q; i++){
        int l = 0, r = n-1, c = 0;
        while(r > l){
            c = (r + l) / 2;
            if(t[i] > s[c]){
                l = c + 1;
            }else if(t[i] < s[c]){
                r = c - 1;
            }else{
                break;
            }
        }
        if(t[i] == s[(r + l) / 2]) cnt++;
    }
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    string s,t;
    cin >> s >> t;
    vector<int> next[26];
    REP(i,s.size()){
        next[s[i] - 'a'].push_back(i);
    }
    REP(i,s.size()){
        next[s[i] - 'a'].push_back(i + s.size());
    }
    ll ans = 0;
    int pos = 0;
    REP(i,t.size()){
        if(next[t[i] - 'a'].size() == 0){
            cout << -1 << endl;
            return 0;
        }
        pos = *lower_bound(ALL(next[t[i] - 'a']), pos) + 1;
        if(pos >= s.size()){
            pos -= s.size();
            ans += s.size();
        }
    }
    cout << pos + ans << endl;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define endl "\n"

using namespace std;

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

    ll n;
    cin >> n;

    vector<int> arr(n);

    for (int i = 0; i < n; i++)
        cin >> arr[i];

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

    int left = n / 2 - 1;
    int right = n / 2;

    if (arr[left] == arr[right])
    {
        cout << 0;
    }
    else
    {
        cout << arr[right] - arr[left];
    }
}

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

int main() {
	int n, a, b, c, cal[10001], sum = 0, ans;
	
	cin >> n >> a >> b >> c;
	for(int i = 1; i <= n; i++){
		cin >> cal[i];
	}
	
	cal[0] = 10000;
	sort(cal, cal + n + 1, greater<int>());
	
	ans = c / a;
	for(int i = 1; i <= n; i++){
		sum += cal[i];
		ans = max(ans, (c + sum) / (a + b * i));
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1188
from fractions import gcd
A, B, C, D = list(map(int,input().split()))
#ベン図を描いてみれば一目瞭然。全要素unをA以上B以下の整数とする。
#そこからCで割り切れる要素数cnとDで割り切れる要素数dnを引き
#最後にCD両方で(=C,Dの最小公倍数で)割り切れる要素数enを足す

#全要素数un
un = B - A + 1
#Cで割り切れる要素数cn
cn = B//C - (A-1)//C 
#Dで割り切れる要素数dn
dn = B//D - (A-1)//D
#CでもDでも割り切れる要素数en
E = C * D / int(gcd(C, D)) #CとDの最小公倍数
E = int(E)
en = B//E - (A-1)//E
#結果
ans = un - (cn + dn) + en
print(int(ans))

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

int main(){
  int i,j,cnt=0;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  int sum=0;
  for(i=0;i<n;i++){
    if(a[i]>100000){
      sum++;
      a[i]=0;
    }
  }
  int b[100001];
  for(i=0;i<=100000;i++)b[i]=0;
  for(i=0;i<n;i++){
    if(a[i]!=0)b[a[i]]++;
  }
  for(i=0;i<=100000;i++){
    if(b[i]!=0){
      if(b[i]>i){
        sum+=b[i]-i;
      }else if(b[i]<i){
        sum+=b[i];
      }
    }
  }
  cout<<sum<<endl;
  
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

const long long int mod = 1e9+7;
long long n, k;
vector< int > have_p;
int root = 0;

int main(int argc, char* argv[]){
  cin >> n >> k;
  have_p = vector<int>(n, 0);
  have_p[0] = 1;
  vector< vector<int> > edges(n, vector<int>());
  for(int i = 0; i < n-1; i++){
    int a,b;
    cin >> a >> b;
    a--; b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  queue<int> q;
  q.push(0);
  int f;
  long long ans = k;
  while(!q.empty()){
    f = q.front();
    q.pop();
    long long count = 0;
    for(auto v:edges[f]){
      if(have_p[v]) continue;
      count++;
      have_p[v] = 1;
      q.push(v);
    }
    if(f == 0){
      if(k-1 < count){
        cout << 0 << endl;
        return 0;
      }
      for(int i = 0; i < count; i++){
        ans *= k-i-1 ? k-i-1 : 1;
        ans %= mod;
      }
    }
    else{
      if(k-2 < count){
        cout << 0 << endl;
        return 0;
      }
      for(int i = 0; i < count; i++){
        ans *= (k-i-2) ? k-i-2 : 1;
        ans %= mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6904
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9+7
typedef long long int ll;
const int maxn = 1000000;
ll mod = INF;

int d[maxn+1];
int n;
int a[maxn];
int cnt[maxn+1];
int used[maxn+1];
int ans=0;

int main(){
    cin >> n;
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=0;i<=maxn;i++)d[i]=INF;
    d[0]=d[1]=1;
    sort(a,a+n);
    for(int div=2;div<=a[n-1];div++){
        if(d[div]!=INF)continue;
        for(int bediv=div;bediv<=a[n-1];bediv+=div){
            d[bediv]=div;
        }
    }
    
    for(int i=0;i<n;i++){
        int bediv=a[i];
        set<int> s;
        while(bediv>1){
            s.insert(d[bediv]);
            bediv=bediv/d[bediv];
        }
        for(auto ite=s.begin();ite!=s.end();ite++){
            used[*ite]++;
            if(used[*ite]>1){
                ans=1;
                break;
            }
        }
        if(ans==1)break;
    }

    set<int> t;
    int temp=a[0];
    while(temp>1){
        t.insert(d[temp]);
        temp=temp/d[temp];
    }

    for(auto ite=t.begin();ite!=t.end();ite++){
        for(int i=0;i<n;i++){
            if(a[i]%*ite!=0)break;
            if(i==n-1)ans=2;
        }
        if(ans==2)break;
    }

    if(ans==0){
        cout <<"pairwise coprime"<<endl;
    }else if(ans==1){
        cout << "setwise coprime"<<endl;
    }else{
        cout << "not coprime"<<endl;
    }

    return 0;
}

Measured memory_bytes: 11724
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
sm = sum(a) % mod
ans = 0
beki = 0

for i in range(n):
    sm -= a[i]
    ans += a[i] * sm
    ans %= mod
    beki += a[i]*a[i]
    beki %= mod
print(ans)


Measured memory_bytes: 94276
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define rep(i,n) for(i=0;i<n;i++)

typedef struct{
	int i,j,k,r;
}p;

int in(void){
	int i;
	scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;
	scanf("%lld",&i);
	return i;
}
int cmp(const void *a,const void *b){
	return ((p *)b)->r-((p *)a)->r;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long max(long long a,long long b){
	return a>b?a:b;
}

int main(void){
	int a,b,c,n,f[301],i;
	p q[1000];
	while(1){
		a=in();
		b=in();
		c=in();
		if(!a){
			break;
		}
		rep(i,a+b+c){
			f[i+1]=2;
		}
		memset(q,0,sizeof(q));
		n=in();
		rep(i,n){
			q[i].i=in();
			q[i].j=in();
			q[i].k=in();
			q[i].r=in();
		}
		qsort(q,n,sizeof(p),cmp);
		rep(i,n){
			if(q[i].r){
				f[q[i].i]=f[q[i].j]=f[q[i].k]=1;
			}
			else{
				if(f[q[i].i]==1&&f[q[i].j]==1){
					f[q[i].k]=0;
				}
				else if(f[q[i].i]==1&&f[q[i].k]==1){
					f[q[i].j]=0;
				}
				else if(f[q[i].j]==1&&f[q[i].k]==1){
					f[q[i].i]=0;
				}
			}
		}
		rep(i,a+b+c){
			printf("%d\n",f[i+1]);
		}
	}
	return 0;
}

Measured memory_bytes: 676