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

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

  int n;
  cin >> n;

  int answer = 0;
  vector<int> a(n + 1);

  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if(i % 2 == 1 && a[i] % 2 == 1) {
      answer++;
    }
  }
  cout << answer << "\n";
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i< (n);i++)
#define rep1(i,n) for(int i=1;i<= (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

const static ll MOD = (1e+9)+7;

int main(){
    ll N,K;cin>>N>>K;
    vector<ll> lst(N);
    ll cnt_n = 0,cnt_p = 0;
    int flg = -1;
    //0がいると困るので、消す。
    rep(i,N){
        cin>>lst[i];
        if(lst[i] < 0)cnt_n++;
        else if(lst[i] > 0)cnt_p++;
        else{
            K--;flg = i;
        }
    }
    if(flg != -1){
        lst.erase(lst.begin()+flg);
        N--;
    }
    if(K == 0){
        cout<<'0'<<endl;
        return 0;
    }
    if(cnt_n == 0){
        //マイナスなものがないなら、直進するのが正解に決まっている.
        cout<<lst[K-1]<<endl;
        return 0;
    }
    if(cnt_p == 0){
        //プラスがなくても同じ.
        cout<<-lst[cnt_n-K]<<endl;
        return 0;
    }
    //マイナスとプラスが混在している場合が本番.
    ll ans = MOD;//INFとしてMODを利用.
    rep(i,N){
        if(lst[i]<0){
            if(cnt_n-i > K)continue;
            //それ以外.
            if(cnt_n-i == K)ans = min(ans,-lst[i]);
            else{
                if(K+i-1 < 0 || K+i-1 > N-1)continue;
                ans = min(ans,-lst[i] + 2*lst[K+i-1]);
            }
        }else if(lst[i]>0){
            if(i-cnt_n+1 > K)continue;
            if(i-cnt_n+1 == K)ans = min(ans,lst[i]);
            else{
                if(i-K+1 < 0 || i-K+1 > N-1)continue;
                ans = min(ans,lst[i]-2*lst[i-K+1]);
            }
        }else{
            continue;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
struct node{
  int bits, cost;
};
node info[20];
int n, U;
int dp[1 << 20];

int rec(int used, int sbj){ //used: 修得済みの教科
  if(~dp[used]) return dp[used];
  if(sbj >= U) return __builtin_popcount(used);
  int ret = n;
  for(int i = 0; i < n; i++){
    if(info[i].bits&~used || used >> i & 1) continue;
    ret = min( ret, rec( used|(1 << i), sbj + info[i].cost));
  }
  return dp[used] = ret;
}

int main(){
  while(cin >> n >> U, n){
    fill_n( dp, 1 << 20, -1);
    for(int i = 0; i < n; i++){
      int k;
      cin >> info[i].cost >> k;
      info[i].bits = 0;
      while(k--){
        int r;
        cin >> r;
        info[i].bits |= 1 << r;
      }
    }
    cout << rec( 0, 0) << endl;
  }
}

Measured memory_bytes: 5260
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
	int n,y;
	cin>>n>>y;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(i+j>n) break;
			int k=n-i-j;
			if(i*10000+j*5000+k*1000==y){
				cout<<i<<" "<<j<<" "<<k<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(){

        int N;
        int i,j;
        int count_1 = 0;
        int count_2 = 0;
        int ANS;

        cin >> N;

        for(i = 1; i <= N; i++){

                count_1 = 0;

                for(j = 1; j <= i; j++){
                        if(i%j == 0){
                                count_1++;
                        }
                }

                if(count_1 == 8 && i%2 == 1){

                                count_2++;
                }
        }

        cout << count_2 << endl;

}

Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
xy = [[] for i in range(N)]
for i in range(N):
    xy[i] = LI()

distances = []
def distance(town, town2):
    return ((town[0] - town2[0])**2 + (town[1] - town2[1])**2)**0.5

for i in range(N):
    for j in range(i+1,N):
        distances.append(distance(xy[i], xy[j]))

print(sum(distances) / N * 2)


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << 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(void){
    string S; cin >> S;
    ll N = S.size(), P = 2019; 

    ll ans = 0;
    if(P == 2 || P == 5){
        REP(i,N){
            if((S[i]-'0')%P == 0) ans += i+1;
        }
    }
    else{
        vector<ll> decmod(N+1);
        decmod[0] = 1;
        REP(i,N) decmod[i+1] = (decmod[i]*10)%P;
        vector<ll> U(N+1); U[N] = 0;
        REP(i,N){
            U[N-1-i] = (U[N-i] + decmod[i]*(S[N-1-i]-'0'))%P;
        }
        vector<ll> mod(P,0);
        RREP(i,N){
            if(U[i] == 0) ans++;
            ans += mod[U[i]];
            mod[U[i]]++;
        }
    }

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

Measured memory_bytes: 6744
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a==0 || b==0 || (a<0 && b>0)) System.out.println("Zero");
		else if(b<0 && (b-a)%2==0) System.out.println("Negative");
		else System.out.println("Positive");
	}
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

int main() {
    int n,m;
    cin>>n>>m;
    int c[m+1];
    rep(i,m)cin>>c[i+1];
    vvi dp(m+1,vi(n+1,100000));
    dp[0][0]=0;
    for (int i=1;i<m+1;i++){
        for (int j=0;j<n+1;j++){
            if (j==0)dp[i][j]=0;
            if (j>=c[i]){
                dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[m][n]<<endl;


    return 0;
}


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

int main(){
  int N,ans=0,count=1;
  cin >> N;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    if(a!=count){
      ans++;
    }
    else{
      count++;
    }
  }
  if(ans==N){
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}  

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<vii> vvii;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

ll const MOD = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T, n;
    cin >> n;
    ll sum = 0;
    ll ans = 0;
    vll A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
        sum += A[i];
    }
    for (int j = 0; j < n; ++j) {
        ans += A[j]*((sum - A[j])%MOD)%MOD;
        sum -= A[j];
    }
    cout << ans%MOD << "\n";
}

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

using namespace std;
#define N 200200
#define MOD 1000000007LL

long long v[N], s[N];
long ans;
int n, i;
int main(){
    cin >> n;
    for (i = 0; i < n; ++i) {
        cin >> v[i + 1];
        s[i + 1] = (v[i + 1] + s[i]) % MOD;
    }
    ans = 0;
    for (i = 0; i < n; ++i) {
        ans += (v[i + 1] * (s[n] - s[i + 1] + MOD)) % MOD;
        ans %= MOD;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 6716
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

struct Node {
    int color;
    std::vector<int> neighbor;
    int lock_dist;
};

const int MAX_N = 100050;
int N, M, Q;
int a[MAX_N], b[MAX_N], v[MAX_N], d[MAX_N], c[MAX_N];

Node graph[MAX_N];

void dfs(int node, int color, int dist) {
    if (graph[node].color == 0) {
        graph[node].color = color;
    }

    if (dist <= graph[node].lock_dist) {
        return;
    }

    graph[node].lock_dist = dist;

    for (auto n : graph[node].neighbor) {
        dfs(n, color, dist - 1);
    }
}

int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= M; i++) {
        std::cin >> a[i] >> b[i];
    }

    std::cin >> Q;

    for (int i = 1; i <= Q; i++) {
        std::cin >> v[i] >> d[i] >> c[i];
    }

    for (int i = 1; i <= N; i++) {
        graph[i].color = 0;
        graph[i].lock_dist = 0;
    }

    for (int i = 1; i <= M; i++) {
        graph[a[i]].neighbor.push_back(b[i]);
        graph[b[i]].neighbor.push_back(a[i]);
    }

    for (int i = Q; 1 <= i; i--) {
        dfs(v[i], c[i], d[i]);
    }

    for (int i = 1; i <= N; i++) {
        std::cout << graph[i].color << std::endl;
    }

    return 0;
}


Measured memory_bytes: 9976
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  int ma=min(a,b);
  cout<<ma<<" ";
  if(a+b>n) cout<<(a+b-n)<<endl;
  else cout<<0<<endl;


  return 0;
}


Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let b: String = sc.read();
    if b == "A" {
        println!("T");
    } else if b == "T" {
        println!("A");
    } else if b == "G" {
        println!("C");
    } else if b == "C" {
        println!("G");
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    int N, K;
    cin >> N >> K;
    
    int a = N % K;
    
    if (a == 0) cout << 0 << endl;
    else cout << 1 << endl;
    
    return 0;
}


Measured memory_bytes: 256
mod = 10**9 + 7
vmax = 2000
fac = [1, 1] + [0] * (vmax - 1)
finv = [1, 1] + [0] * (vmax - 1)
inv = [0, 1] + [0] * (vmax - 1)
for i in range(2, vmax+1):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def com(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


n, k = (int(v) for v in input().split())
for opcnt in range(1, k+1):
    print((com(k-1, opcnt-1) * com(n-k+1, opcnt)) % mod)


Measured memory_bytes: 42736
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,t,a[200000],res = 0;
	cin >> n >> t;
	for(int i = 0;i < n;i++) {
		cin >> a[i];
		if(i){
			res += min(a[i],a[i - 1] + t) - a[i - 1];
		}
	}
	res += t;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));


int main(){	
	long long B;
	long long A;
	long long K;
	scanf("%lld",&A);
	scanf("%lld",&B);
	scanf("%lld",&K);
	ll old = A;
	A = max(A-K, 0LL);
	K = max(K-old, 0LL);
	B = max(B-K, 0LL);
	cout << A << " " << B << endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

//演習　カエルはまっすぐ帰る

int main() {
    int d, l; //距離、大ジャンプ
    
    //入力
    //printf("距離、大ジャンプ = ");
    scanf("%d %d", &d, &l);
    
    //出力
    printf("%d\n", d/l + d%l);
    
    return 0;
}


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

struct UnionFind{
  vector<ll> p;
  vector<ll> s;
  UnionFind(ll n):p(n),s(n,1){
    REP(i,n) p[i]=i;
  }
  ll find(int x){
    if(x==p[x]) return x;
    return p[x]=find(p[x]);
  }
  void unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(s[x]<s[y]) swap(x,y);
    p[y]=x;
    s[x]+=s[y];
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  ll size(ll x){
    return s[find(x)];
  }
};

int main(){
  ll N,M; scanf("%lld%lld",&N,&M);
  
  vector es(M,vector<int>(2));
  REP(i,M) {
    scanf("%d%d",&es[i][0],&es[i][1]);
    es[i][0]--,es[i][1]--;
  }
  
  UnionFind t(N);
  ll ans[M+1]{};
  ans[0]=N*(N-1)/2;
  REP(i,M) {
    auto e=es.back();
    es.pop_back();
    if(t.same(e[0],e[1])){
      ans[i+1]=ans[i];
    }else{
      ans[i+1]=ans[i]-t.size(e[0])*t.size(e[1]);
      t.unite(e[0],e[1]);
    }
  }
  REP(i,M) {
    printf("%lld\n",ans[M-i-1]);
  }
}

Measured memory_bytes: 11172
def add():
    for i in ans[cnt-1]:
        i=str(i)
        last=i[-1]
        last=int(last)
        for j in range(last-1,last+2):
            if j==10 or j==-1:
                continue
            tmp=i
            tmp+=str(j)
            ans[cnt].append(int(tmp))

n=int(input())
ans=[[]for i in range(10)]
cnt=1
for i in range(1,10):
    ans[0].append(i)

for i in range(9):
    add()
    cnt+=1
merged=[]
for i in ans:
    merged+=i
merged=sorted(merged)
print(merged[n-1])

Measured memory_bytes: 14120
import gc


class Ruiseki2D():
    """二次元累積和を構築する
    構築O(HW), 区間取得クエリO(1)
    """
    def __init__(self, matrix):
        self.h = len(matrix)
        self.w = len(matrix[0])
        self.ruiseki = [[0] * (self.w + 1) for _ in range(self.h + 1)]

        for i in range(self.h):
            for j in range(self.w):
                self.ruiseki[i + 1][j + 1] = self.ruiseki[i + 1][j] + matrix[i][j]
        for i in range(self.h):
            for j in range(self.w):
                self.ruiseki[i + 1][j + 1] += self.ruiseki[i][j + 1]

    def get_sum(self, hl, hr, wl, wr):
        """[hl, hr), [wl, wr) で囲まれた部分の和を求める"""
        return self.ruiseki[hr][wr] + self.ruiseki[hl][wl] - self.ruiseki[hr][wl] - self.ruiseki[hl][wr]


n, m, q = map(int, input().split())
s = [list(map(int, input())) for i in range(n)]
query = [list(map(int, input().split())) for i in range(q)]

ru_col_cnt = Ruiseki2D(s)

# メモリ削減のため累積和配列を使い回す
yoko_edge = [[0] * (m + 1) for i in range(n + 1)]
for i in range(n):
    for j in range(m - 1):
        if s[i][j] == 1 and s[i][j + 1] == 1:
            yoko_edge[i + 1][j + 1] = 1
for i in range(n):
    for j in range(m):
        yoko_edge[i + 1][j + 1] += yoko_edge[i + 1][j]
for i in range(n):
    for j in range(m):
        yoko_edge[i + 1][j + 1] += yoko_edge[i][j + 1]

tate_edge = [[0] * (m + 1) for i in range(n + 1)]
for i in range(n - 1):
    for j in range(m):
        if s[i][j] == 1 and s[i + 1][j] == 1:
            tate_edge[i + 1][j + 1] = 1
for i in range(n):
    for j in range(m):
        tate_edge[i + 1][j + 1] += tate_edge[i + 1][j]
for i in range(n):
    for j in range(m):
        tate_edge[i + 1][j + 1] += tate_edge[i][j + 1]



def yoko_get_sum(hl, hr, wl, wr):
    return yoko_edge[hr][wr] + yoko_edge[hl][wl] - yoko_edge[hr][wl] - yoko_edge[hl][wr]
  
def tate_get_sum(hl, hr, wl, wr):
    return tate_edge[hr][wr] + tate_edge[hl][wl] - tate_edge[hr][wl] - tate_edge[hl][wr]

for hl, wl, hr, wr in query:
    hl, wl = hl - 1, wl - 1
    ans = ru_col_cnt.get_sum(hl, hr, wl, wr)
    ans -= yoko_get_sum(hl, hr, wl, wr - 1) + tate_get_sum(hl, hr - 1, wl, wr)
    print(ans)


Measured memory_bytes: 194388
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>

int main()
{
    long N;
    std::vector<long> s;
    std::cin >> N;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        s.push_back(temp);
    }
    std::sort(s.begin(),s.end());
    long sum=0;
    for(long i=0; i<N; i++){
        sum+=s[i];
    }
    if(sum%10!=0){
        std::cout << sum << std::endl;
    }else{
        for(long i=0; i<N; i++){
            if(s[i]%10!=0){
                sum-=s[i];
                std::cout << sum << std::endl;
                break;
            }
            if(i==N-1){
                std::cout << 0 << std::endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());

        int p = A + B;
        int m = A - B;
        int k = A * B;
        int tmp = Math.max(p, m);
        int ans = Math.max(tmp, k);

        System.out.println(ans);
    }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
void solve()
{
   ll n;
   cin>>n;
   
   string str;
   cin>>str;
   
   if(n==1)
   {
       cout<<1;
       return;
   }
   
   ll ans=0;
   for(ll i=0;i<str.length();i++)
   {
       if(str[i]!=str[i+1])
       ans++;
   }
   
   cout<<ans;
   return;
}

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

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H[1000000];
  int n;
  int ans=0;
  cin >> n;
  for(int i=1;i<=n;i++){
    cin >> H[i];
  }
  //int J[100000];
  //J[0]=100000;
  for(int i=1;i<n;i++){
    
    int j=i;
    while(H[j]>=H[j+1]&&j+1<=n){
      if(H[i]<=H[i-1]&&i>=2) break;
      j++;
      //cout << "j=" << j << endl;
    }
    //J[i]=j;
    //cout << "J" << i << "=" << J[i]<< endl;
    ans=std::max(ans,j-i);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  int n,k,q,num[110000];
  cin >> n >> k >> q;
  for(int i = 1; i <= n; i++)
    num[i] = 0;

  for(int i = 0; i < q; i++) {
    int a; cin >> a;
    num[a]++;
  }
  
  for(int i = 1; i <= n; i++) {
    if(num[i] > q-k) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 3996
N,K=map(int, input().split())
P=list(map(int, input().split()))
C=list(map(int, input().split()))

F=[0]*N
I=[0]*N
CN=[0]*N

for i in range(N):
  around=0
  cnt=0
  A=[]
  if F[i]==0:
    F[i]=1
    around+=1
    cnt+=C[i]
    nex=P[i]-1
    A.append(i)
    while F[nex]==0:
      A.append(nex)
      F[nex]=1
      around+=1
      cnt+=C[nex]
      nex=P[nex]-1
    for j in A:
      I[j]=around
      CN[j]=cnt
ans=-(10**9)*2
for i in range(N):
  #動かす回数が一周に満たない時
  if K<=I[i]:
    d=C[i]
    cnt=d
    nex=P[i]-1
    for j in range(K-1):
      d+=C[nex]
      nex=P[nex]-1
      cnt=max(d,cnt)
  #動かす回数が一周を超えるとき
  elif CN[i]<=0:
    d=C[i]
    cnt=d
    nex=P[i]-1
    for j in range(I[i]-1):
      d+=C[nex]
      nex=P[nex]-1
      cnt=max(d,cnt)
  else:
    syuukai=K//I[i]
    nokori=K%I[i]
    syuukai-=1
    nokori+=I[i]
    d=C[i]
    cnt=d
    nex=P[i]-1
    for j in range(nokori-1):
      d+=C[nex]
      nex=P[nex]-1
      cnt=max(d,cnt)
    cnt+=syuukai*CN[i]
  ans=max(ans,cnt)
print(ans)


Measured memory_bytes: 74676
#include<iostream>
#include<climits>
using namespace std;

int w[10][10];

int d[10][10];

int x[10];

int tw;

void erace(bool flag){
	for(int i=0; i<10; i++){
		if(flag){
			x[i] = 0;
			continue;
		}
		for(int j=0; j<10; j++)
				w[i][j] = INT_MAX;
	}
}

void copy(){
	for(int i=0; i<10; i++)
		for(int j=0; j<10; j++)
			d[i][j] = w[i][j];
}

int min(){
	int tmp = x[0];
	int ans = 0;
	for(int i=1; i<tw; i++){
		if(tmp > x[i]){
			tmp = x[i];
			ans = i;
		}
	}
	return ans;
}

int solve(){
	copy();
	for(int k=0; k<tw; k++){
		for(int i=0; i<tw; i++){
			for(int j=0; j<tw; j++){
				if(d[i][k] >= INT_MAX || d[k][j] >= INT_MAX)
					continue;
				int dis = d[i][k] + d[k][j];
				if(dis < d[i][j])
					d[i][j] = dis;
			}
		}
	}
	erace(true);
	for(int i=0; i<tw; i++){
		for(int k=0; k<tw; k++){
			if(k == i)
				continue;
			x[i] += d[i][k];
		}
	}

	return min();
}

int main(){
	int n,a,b,c;
	while(true){
		tw = 0;
		erace(false);
		cin >> n;
		if(!n)
			return 0;
		for(int i=0; i<n; i++){
			cin >> a >> b >> c;
			w[a][b] = c;
			w[b][a] = c;
			if(tw < a+1)
				tw = a+1;
			if(tw < b+1)
				tw = b+1;
		}
		n = solve();
		cout << n << ' ' << x[n] << endl;
	}
}

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

int main() {
    string s; cin >> s;
    int res = 0;
    stack<char> st;
    for (int i = 0; i < s.size(); ++i) {
        if (st.empty() || st.top() == s[i]) st.push(s[i]);
        else {
            res += 2; // ペアを足す
            st.pop();
        }
    }
    cout << res << endl;
}






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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> m(N);
  for (auto &x:m) {
    cin >> x;
  }
  auto max = std::max_element(m.begin(), m.end());
  int max_value = *max;
  m.erase(max);
  int sum = 0;
  for (auto x: m){
    sum += x;
  }
  if (max_value < sum) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad

solve :: Int -> [[Int]] -> [[Int]]
solve c table = rows ++ [row]
    where
        rows = map (\r -> r ++ [foldl (+) 0 r]) table
        row  = map (\i -> foldl (\a r -> a + (r !! i)) 0 rows) [0 .. c]

main :: IO ()
main = do
    [r, c] <- map read . words <$> getLine
    table  <- map (map read . words) <$> replicateM r getLine
    putStr $ unlines $ map (unwords . map show) $ solve c table

Measured memory_bytes: 6592
n = int(input())
p = [input() for i in range(n)]
if sorted(set(p))!=sorted(p):
    print("No")
    exit()
else:
    for i in range(n-1):
        if p[i][len(p[i])-1]!=p[i+1][0]:
            print("No")
            exit()
    else:
        print("Yes")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int H;
		int W;
		for (int i = 0; i < 10000; i ++) {
			H = scan.nextInt();
			W = scan.nextInt();
			if (H == 0 && W == 0) {
				break;
			}
			for (int h = 0; h < H; h++) {
				for (int w = 0; w < W; w++) {
					if ((h + w) % 2 == 0) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 34688
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int dis[15][15];
const int INF = 0x3f3f3f3f;
int main()
{
    int n;
    while(scanf("%d",&n) != EOF&&n)
    {
        int m = 0;
        memset(dis,0x3f,sizeof(dis));
        for(int i = 0;i < 15;i++)
            dis[i][i] = 0;
        for(int i = 0;i < n;i++)
        {
            int a,b,c;
            scanf("%d %d %d",&a,&b,&c);
            dis[a][b] = dis[b][a] = min(dis[a][b],c);
            m = max(max(a,b),m);
        }
        for(int i = 0;i <= m;i++)
            for(int j = 0;j <= m;j++)
                for(int k = 0;k <= m;k++)
                    dis[j][k] = min(dis[j][k],dis[j][i]+dis[i][k]);
        int ans = INF,cas = 0;
        for(int i = 0;i <= m;i++)
        {
            int sum = 0;
            for(int j = 0;j <= m;j++)
                    sum += dis[i][j];
            if(sum < ans)
            {
                ans = sum;
                cas = i;
            }
        }
        printf("%d %d\n",cas,ans);
    }
    return 0;
}



Measured memory_bytes: 2660
#include <stdio.h>
#define A_MAX 30

int solve(int ,int );
int n,A[A_MAX];
int main()
{
  int m,q,i,judge;

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

int solve(int i,int m)
{
  int res; 
  if(m == 0) return 1;
  if(i >= n) return 0;

  res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}

Measured memory_bytes: 580
from collections import Counter

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

is_p=[1]*(10**6+1)
for i in set(a):
  if is_p[i]:
    for j in range(i+i,10**6+1,i):
      is_p[j]=0

c=Counter(a)

cnt=0
for i in a:
  if is_p[i] and c[i]==1:
    cnt+=1

print(cnt)

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 123;

int l[N];

void solve() {
  int n; scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", l+i);
  int ans = 0;
  for (int i = 0; i < n-2; ++i) {
    for (int j = i+1; j < n-1; ++j) {
      if (l[i] == l[j]) continue;
      for (int k = j+1; k < n; ++k) {
	if (l[i] == l[k] || l[j] == l[k]) continue;
	if (l[i]+l[j] > l[k] &&
	    l[j]+l[k] > l[i] &&
	    l[k]+l[i] > l[j]) {
	  ++ans;
	}
      }
    }
  }
  printf("%d", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3812
N = int(input())
S = []
P = []
sp = []
for i in range(N):
    s, p = input().split()
    S.append(s)
    P.append(int(p))
    p=int(p)
    sp.append((s, -p, i+1))

sp.sort()

for i in sp:
    print(i[2])

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if(A + B >= C){
  cout << B + C << endl;
  }
  else{
cout << C - (C - A - B) + 1 + B << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);
 	
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		string s,a;cin>>a>>s;
 		cout<<s<<a<<endl;	
 	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 924844033
#define rep(i,x) for(int i=0;i<x;i++)
int n,cnt[200005];
vector<int>edge[200005];
int dfs(int v,int u){
	int sum = 1;
	rep(i,edge[v].size()){
		if(edge[v][i]==u) continue;
		int sz = dfs(edge[v][i],v);
		sum += sz;
		cnt[sz]++;
		cnt[n-sz]++;
	}
	return sum;
}
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[200005],R[200005];
void make(){
	F[0] = 1;
	for(int i=1;i<200005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<200005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
int a[(1<<19)],b[(1<<19)],c[(1<<19)];
ll g[16];
void mul(int *a,int *b,int *c,int n){
	if (n<=8){
		memset(g,0,sizeof(g));
		rep(i,n)rep(j,n) g[i+j]+=(ll)a[i]*b[j]%mod;
		rep(i,2*n) c[i]=g[i]%mod;
		return;
	}
	int mid = n/2;
	mul(a,b,c,mid); mul(a+mid,b+mid,c+n,mid);
	int x[mid],y[mid],z[n];
	rep(i,mid){
		x[i]=(a[i]+a[i+mid])%mod; y[i]=(b[i]+b[i+mid])%mod;
	}
	mul(x,y,z,mid);
	rep(i,n) z[i]-=c[i]+c[i+n];
	rep(i,n) c[i+mid]=((c[i+mid]+z[i])%mod+mod)%mod;
}
int main(){
	scanf("%d",&n);
	rep(i,n-1){
		int a,b; scanf("%d%d",&a,&b);
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	dfs(1,-1);
	make();
	rep(i,n){
		a[i] = 1LL*cnt[i]*F[i]%mod;
		b[i] = R[n-1-i];
	}
	mul(a,b,c,(1<<18));
	rep(j,n){
		int i=j+1;
		ll ans = C(n,i) * n % mod;
		ll cur = 1LL*c[n-1+i]*R[i]%mod;
		printf("%lld\n",(ans-cur+mod)%mod);
	}
}

Measured memory_bytes: 33792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
 int a,b;
  cin>>a>>b;
  if(a<1000)
    cout<<"ABC"<<endl;
  else
    cout<<"ABD"<<endl;
}

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

typedef long long LL;
#define PB push_back

using namespace std;

int main (){
  LL n;
  cin >> n;
  LL res ;
  cin >> res;

  for( LL i =1; i < n;i++){
    LL a;
    cin >> a;
    res = __gcd(res, a);
  }

  cout << res;


}

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

int N;
vector<int> G[100000];
int siro(0);
bool flag(false);
int kyori0[100000],kyoriN[100000];
void dfs0(int now,int par, int kyori){
  kyori0[now] = kyori;
  for(int next:G[now]){
    if(next != par){
      dfs0(next,now,kyori+1);
    }
  }
}

void dfsN(int now,int par, int kyori){
  kyoriN[now] = kyori;
  for(int next:G[now]){
    if(next != par){
      dfsN(next,now,kyori+1);
    }
  }
}


int main(){
  cin>>N;
  for(int i(0);i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs0(0,-1, 0);
  dfsN(N-1,-1, 0);
  int cnt(0);
  for(int i(0);i<N;i++){
    if(kyori0[i]<=kyoriN[i]) cnt++;
  }
  //cout << cnt << endl;
  if(cnt*2>N){
    cout << "Fennec" << endl;
  }else{
    cout << "Snuke" << endl;
  }
  return 0;
}


Measured memory_bytes: 11136
H, W, K = map(int, input().split())
lists = [input() for i in range(H)]
black, ans = 0, 0
tate, yoko = [0 for i in range(H)],  [0 for i in range(W)]
listskai = [[0 for j in range(W)]for i in range(H)]

for i in range(W):
    for j in range(H):
        if lists[j][i] == '#':
            black += 1
            tate[j] += 1
            yoko[i] += 1
            listskai[j][i] = 1

def tmp(times, num, max, lista, numa):
    if times == 0:
        return lista + [num]

    for tmpi in range(numa + 1, max):
        if tmpi not in num:
            lista = tmp(times - 1, num + [tmpi], max, lista, tmpi)
    return lista

kurono = black

for looph in range(H):
    for j in tmp(looph, [], H, [], -1):
        for loopw in range(W):
            for i in tmp(loopw, [], W, [], -1):
                kurono = black
                for k in i:
                    kurono -= yoko[k]
                    for d in j:
                        kurono += listskai[d][k]

                for d in j:
                    kurono -= tate[d]

                if kurono == K:
                    ans += 1

print(ans)

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

long long great(long long c, long long d){
  if(c<d){
    swap(c,d);
  }
  while(true){
    if(c%d==0){
      return d;
    }else{
      c%=d;
      swap(c,d);
    }
  }
}

int main(){
  long long a,b,c,d,gcd=1,ans=0;
  cin >> a >> b >> c >> d;
  a--;
  gcd=great(c,d);
  ans=(b-b/c-b/d+b/(c*d/gcd))-(a-a/c-a/d+a/(c*d/gcd));
  cout << ans;
    
}
  

Measured memory_bytes: 256
#include<stdio.h>
main(){
  char s1,s2,tmp='A';
  while(scanf("%c,%c",&s1,&s2)!=EOF){
    if(s1==tmp){
      tmp=s2;
      continue;
    }
    else if(s2==tmp){
      tmp=s1;
      continue;
    }
  }
  printf("%c\n",tmp);
  return 0;
}

Measured memory_bytes: 544
#include <iostream> 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
long long mod;

ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
{
  ll ans=0;
  if(i>=n)
    return 0;

  if(dp[i][k]!=-1)
    return dp[i][k];


  if(k!=0)
  ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
  else
  ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

  return dp[i][k]=ans;

}

ll t[400008];
void build(vector<ll>& a, int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] = max(t[v*2] ,t[v*2+1]);
    }
}

ll maxi(int v, int tl, int tr, int l, int r) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
}



void update(int v, int tl, int tr, int pos, ll new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = max(t[v*2] ,t[v*2+1]);
    }
}

int main() { 
ll a;

cin>>a;
string s="";
//a--;
while(a)
{
  char c='a'+((a-1)%26);
  s=c+s;
  a=(a-1)/26;
}
cout<<s;
return 0;
}


Measured memory_bytes: 3624
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools
from collections import defaultdict

N,*A = map(int,read().split())

Acum = [0] + list(itertools.accumulate(A))

counter = defaultdict(int)
answer = 0
for x in Acum:
    answer += counter[x]
    counter[x] += 1

print(answer)

Measured memory_bytes: 41444
using System.Collections.Generic;
class p0001
{
    static void Main(string[] args)
    {
        List<int> l=new List<int>();
        for (int i = 0; i < 10; i++)
           l.Add(int.Parse(System.Console.ReadLine()));
        l.Sort();
        System.Console.WriteLine( l[9]);
        System.Console.WriteLine( l[8]);
        System.Console.WriteLine( l[7]);
    }
}

Measured memory_bytes: 5760
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
//int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
const int nmax=40,abmax=10,inf = 1000000;

 int a[nmax],b[nmax],c[nmax];
 int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];
int main(){
	int n,ma,mb;
	cin>>n>>ma>>mb;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	for(int i = 0; i <= n; ++i){
 		for(int ca = 0; ca <= nmax*abmax; ++ca){
 			for(int cb = 0; cb <= nmax*abmax; ++cb){
 				dp[i][ca][cb]=inf;
 			}
 		}
 	}
 	dp[0][0][0]=0;
 	for(int i = 0; i < n; ++i){
 		for(int ca = 0; ca <= nmax*abmax; ++ca){
 			for(int cb = 0; cb <= nmax*abmax; ++cb){
	 			if(dp[i][ca][cb]==inf) continue;
				dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb]);
				dp[i+1][ca+a[i]][cb+b[i]]
				=min(dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]);
	 		}
 		}
	}
 	int ans=inf;
	for(int ca = 1; ca <= nmax*abmax; ++ca){
		for(int cb = 1; cb <= nmax*abmax; ++cb){
			if(ca*mb==cb*ma) ans=min(ans,dp[n][ca][cb]);
		}
	}
	if(ans==inf) ans=-1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 28928
import java.util.*;

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        double n = sc.nextInt();
        int k = sc.nextInt();
        double ans = 0;
        double d = 0.5;
        for(int i = 1; i <= n; i++){
            double j = i;
            int l = 1;
            while(k>j){
                double num1 = Math.pow(2,l);
                j = i * num1;
                l = l + 1;
            }
            l = l -1;
            double num = Math.pow(d,l);
            double num2 = (double)1 / n;
            ans = ans + num2 * num;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(a==b?c:(a==c?b:a))<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)
const int inf=2e9;
#define maxx 200005
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main(){
    FASTIO;
    ll n,ans=0;
    cin>>n;
    ll a[n];
    REP(i,0,n) cin>>a[i];
    REP(i,0,n-1){
      if(a[i]>a[i+1]){
        ans+=a[i]-a[i+1];
        a[i+1]=a[i];
      }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5140
s = input()

g = 0
p = 0
ans = 0

for i in s:

    if i == "g":

        if p < g:
            ans += 1
            p += 1

        else:
            g += 1

    else:

        if p < g:
            p += 1

        else:
            g += 1
            ans -= 1

print (ans)


Measured memory_bytes: 3316
#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;
  int res=0;
  int j=0;
  rep(i,n){
    int d1,d2;
    cin >> d1 >> d2;
    if (d1==d2){
      j+=1;
      res=max(res,j);
    }else{
      j=0;
    }
  }
  if (res>=3){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3660
from collections import deque
S = input()
L = len(S)
d = deque()
for i in range(L):
    if S[i] == "0":
        d.append("0")
    elif S[i] == "1":
        d.append("1")
    else:
        if len(d) != 0:
            d.pop()

ans = ''.join(d)
print(ans)


Measured memory_bytes: 9392
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string N;

    cin >> N;

    if(N[0]==N[1] && N[1]==N[2]){
        cout << "Yes" << endl;
    }
    else if(N[1]==N[2] && N[2]==N[3]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int main() {
	string s;
	getline(cin, s);
	cout << "A" << s[8] << "C" << endl;
	return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<queue>
#define For(i,j,k)  for(int i=j;i<=k;++i)
#define Dow(i,j,k)  for(int i=k;i>=j;--i)
#define ll long long
#define inf 1e9
#define pb push_back
#define local freopen("in.in","r",stdin);
#define c(x,y)  ((x-1))*m+(y)
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read()
{
	ll t=0,f=1;char c=gc();
	while(!isdigit(c))  {if(c=='-') f=-1;c=gc();}
	while(isdigit(c))   t=t*10+c-'0',c=gc();
	return t*f;
}
inline void write(ll x){if(x<0) {putchar('-');write(-x);return;}if(x>=10)    write(x/10);putchar(x%10+'0');}
inline void writeln(ll x){write(x);puts("");}
inline void write_p(ll x){write(x);putchar(' ');}

ll ans=2e18,a,b,c,x,y;
int main()
{
	a=read();b=read();c=read();x=read();y=read();
	For(i,0,max(x,y))
	{
		ll tmp=2*i*c+max(0LL,(x-i))*a+max(0LL,(y-i))*b;
		ans=min(ans,tmp);
	}
	writeln(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=1e5+10;

int N;
int h[MAX];
void input(){
	cin>>N;
	rep(i,N)cin>>h[i];
}

int dp[MAX];
void solve(){
	rep1(i,N-1){
		if(i==1)dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
		else dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	}
}

void output(){
  cout<<dp[N-1];
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 1024
#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);

    if(N % 10 == 7){
        printf("Yes\n");
    } else if (((N - (N % 10)) / 10) % 10 == 7) {
        printf("Yes\n");
    } else if ((N - (N % 10) - ((((N - (N % 10)) / 10) % 10) * 10)) / 100 == 7) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1648
#include<iostream>
#include<cstring>
using namespace std;

int main() {
    string a;
    int n;
    cin >> n;
    int a_ = 0, t_ = 0, w_ = 0, r_ = 0;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a[0] == 'A') a_++;
        if (a[0] == 'W') w_++;
        if (a[0] == 'T') t_++;
        if (a[0] == 'R') r_++;
    }
    cout << "AC x " << a_ << "\n";
    cout << "WA x " << w_ << '\n';
    cout << "TLE x "<< t_ << '\n';
    cout << "RE x " << r_ << '\n';
}

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

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
#define MOD 1000000007

ll dp[100001][4];

int main() {

    string s; cin >> s;
    int N = s.size();

    dp[N][3] = 1;

    for (int i = N - 1; i >= 0; i--) {
        for (int j = 3; j >= 0; j--) {
            dp[i][j] = dp[i + 1][j];
            if (s[i] == '?') dp[i][j] *= 3LL;
            if (j < 3 && (s[i] == '?' || s[i] == "ABC"[j])) {
                dp[i][j] += dp[i+1][j+1];
            }
            dp[i][j] %= MOD;
        }
    }

    cout << dp[0][0] << endl;

    return 0;
}


Measured memory_bytes: 3584
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<char> >paint(h,vector<char>(w));
  bool ans=true;
  vl dx={1,-1,0,0};
  vl dy={0,0,1,-1};
  rep(i,h){
    rep(j,w)cin>>paint[i][j];
  }
  rep(i,h){
    rep(j,w){
      if(paint[i][j]=='#'){
        bool part=false;
        rep(k,4){
          if(i+dy[k]>=0 && i+dy[k]<h && j+dx[k]>=0 && j+dx[k]<w){
            if(paint[i+dy[k]][j+dx[k]]=='#')part=true;
          }
        }
        ans&=part;
      }
    }
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
        

Measured memory_bytes: 256