akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i=0;i<n;i++) list.add(sc.nextInt());
		sc.close();
		Map<Integer,Integer> map = new HashMap<>();
		for(int tmp : list) {
			if(map.containsKey(tmp)) map.put(tmp,map.get(tmp)+1);
			else map.put(tmp, 1);
		}
		Map<Integer,Long> map2 = new HashMap<>();
		Map<Integer,Long> map3 = new HashMap<>();
		long sum = 0;
		for(int key : map.keySet()) {
			int tmp = map.get(key);
			if(tmp>=2) {
				map2.put(key, CalcUtil.nC2(tmp));
				sum += CalcUtil.nC2(tmp);
			}else {
				map2.put(key, 0L);
			}
			if(tmp>=3) {
				map3.put(key, CalcUtil.nC2(tmp-1));
			}else {
				map3.put(key, 0L);
			}
		}
		for(int tmp : list) {
			System.out.println(sum - map2.get(tmp) + map3.get(tmp));
		}
	}
	
	static class CalcUtil {
		public static long nC2(int n) {
			return (long)n * (long)(n-1) / 2;
		}
	}
}


Measured memory_bytes: 114472
from collections import Counter
x,n = map(int,input().split())
p = list(map(int,input().split()))

num_list = list(range(-200,201))
y = (num_list + p)

counter = Counter(y)
result =  [elem for elem in y if counter[elem] < 2]


ans = 10 *100000000000

for i in result:
    temp = abs(i - x)
    if ans > temp:
        ans = temp
        res = i
print(res)


Measured memory_bytes: 9516
#include <iostream>
#include <cmath>
#include <cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
  int n,m;
  cin >> n>> m;
  if (n == m)
    {
      cout << "Yes" <<endl;
    }
  else
    {
      cout << "No" << endl;
    }
}


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

const int inf = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };
int h, w;
string s[20];
int g[400][400];
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
  }
  
  const int n = h * w;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      g[i][j] = i == j ? 0 : inf;
    }
  }
  
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') continue;
      for (int k = 0; k < 4; ++k) {
        int ni = i + di[k];
        int nj = j + dj[k];
        if (ni < 0 || ni >= h) continue;
        if (nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        g[i * w + j][ni * w + nj] = 1;
        g[ni * w + nj][i * w + j] = 1;
      }
    }
  }
  
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (g[i][j] == inf) continue;
      mx = max(mx, g[i][j]);
    }
  }
  cout << mx << endl;
}

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

int main() {
	long long n,s;
	cin >> n >> s;
	for (int i = 2;i <= floor(sqrt(n));++i) {
		long long ret = 0,j = n;
		while (j != 0) {
			ret += j%i;
			j /= i;
		}
		if (ret == s) {
			cout << i << endl;
			exit(0);
		}
	}
	for (int i = ceil(sqrt(n+1));i > 0;--i) {
		long long tmp = n-s+i;
		if (tmp%i == 0 && tmp/i > i && s-i >= 0 && tmp/i > s-i) {
			cout << tmp/i << endl;
			exit(0);
		}
	}
	if (s == n) cout << n+1 << endl;
	else if (s == 1) cout << n << endl;
	else cout << -1 << endl;
	return 0;
}

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

#define REP(i, x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP1(i, x) for (int i = 1, i##_len = (int)(x); i <= i##_len; i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 9;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
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;
}

int main() {
    int N, M;
    cin >> N >> M;
    int t;
    priority_queue<double> pq;
    REP(i, N) {
        cin >> t;
        pq.push(t);
    }
    REP(i, M) {
        pq.push(pq.top() / 2);
        pq.pop();
    }
    ll ans = 0;
    REP(i, N) {
        cerr << i << " " << ans << endl;
        ans += int(pq.top());
        pq.pop();
    }
    cout << ans;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>
#define SORT(A) sort(A.begin(),A.end())

int main() {
    ll N; cin >> N;
    vl L(N);
    rep(i,N) cin >> L[i];

SORT(L);

    ll count = 0;
    rep(i,N){
        xrep(j,i,N){
            xrep(k,j,N){
                if(L[i] != L[j] && L[j] != L[k] && L[k] != L[i] && L[k] - L[i] < L[j] && L[j] < L[k] + L[i]){
                    count ++;
                }
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3628
import itertools

N = int(input())
S = input()

r_cnt = S.count("R")
g_cnt  = S.count("G")
b_cnt = S.count("B")

ans = r_cnt * g_cnt * b_cnt

for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            ans -= 1
print(ans)

Measured memory_bytes: 68056
#include <iostream>
#include<string>
#include<cmath>
using namespace std;
string s;
int main()
{
    cin >>s;
     int ans=s.size();
     int flag1=0,flag2=1;
     int sum1=0,sum2=0;
    for(int i=0;i<ans;i++)
    {
        if(s[i]-'0'!=flag1)
            sum1++;
        flag1=(flag1+1)%2;
    }
    for(int i=0;i<ans;i++)
    {
        if(s[i]-'0'!=flag2)
            sum2++;
        flag2=(flag2+1)%2;
    }
    cout << min(sum1,sum2) <<endl;
    return 0;
}


Measured memory_bytes: 512
N,M = gets.split.map &:to_i
is = Array.new(N,0)
os = Array.new(N,0)
M.times {
  i,o = gets.split.map &:to_i
  is[i-1] += 1
  os[o-1] += 1
}

ans = 0
n = 0
(0...N).each{ |k|
  n += is[k]
  ans += 1 if n == M
  n -= os[k]
}
p ans

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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

void solve(long long N) {
  cout << N * (N-1) / 2 << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 256
import copy

N, M, X = [int(x) for x in input().split()]

C = []
A = []

for i in range(N):
    _ = [int(x) for x in input().split()]
    C.append(_[0])
    A.append(_[1:])


def IsOver(a):
    return all([i >= X for i in a])


INT_MAX = 1000000000
res_min = INT_MAX


def dfs(b_list, index):
    if index is N:
        cost = 0
        a = [0] * M
        for i in range(N):
            if b_list[i]:
                cost += C[i]
                for j in range(M):
                    a[j] += A[i][j]
        if IsOver(a):
            global res_min
            res_min = min(res_min, cost)
        return

    for use in [True, False]:
        _tmp = copy.copy(b_list)
        _tmp.append(use)

        dfs(_tmp, index+1)


dfs([], 0)

print(str(res_min) if res_min is not INT_MAX else str(-1))


Measured memory_bytes: 9308
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, k, a[20];
bool bl[20];
int ans = INF;

signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i <= (1 << n); i++) {
		int cnt = 0;
		for (int j = 0; j < n; j++) {
			if (i&(1 << j)) {
				cnt++;
				bl[j] = true;
			}
			else bl[j] = false;
		}
		if (cnt < k)continue;
		int ma = 0;
		int cnt2 = 0;
		for (int i = 0; i < n; i++) {
			if (bl[i] && a[i] <= ma) {
				cnt2 += ma - a[i] + 1;
				ma++;
			}
			else if (ma < a[i])ma = a[i];
		}
		ans = min(ans, cnt2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[] array = readIntArray(reader);
            int N = array[0];
            int K = array[1];

            int c = (N - 1) * (N - 2) / 2 - K;

            if (c < 0) {
                System.out.println("-1");
                return;
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 2; i <= N; i++) {
                sb.append("1 ").append(i).append("\n");
            }

            for (int i = 2; i <= N; i++) {
                for (int j = i + 1; j <= N; j++) {
                    if (c == 0) {
                        break;
                    }

                    sb.append(i).append(" ").append(j).append("\n");
                    c--;
                }

                if (c == 0) {
                    break;
                }
            }

            System.out.println(N - 1 + (N - 1) * (N - 2) / 2 - K);
            System.out.print(sb.toString());
        }
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

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

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

map<ll,int> prime_factor(ll n) {
  map<ll,int> res;
  for(ll i=2;i*i<=n;i++) {
    while(n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if(n != 1)res[n] = 1;
  return res;
}

int n;
vector<ll> vec;
void compute() {
  vector<ll> pf;
  rep(i,n) {
    map<ll,int> tmp = prime_factor(vec[i]);
    for(auto v : tmp) {
      if( v.first > 1LL ) {
	pf.push_back(v.first);
      }
    }
  }
  sort(ALL(pf));
  pf.erase(unique(ALL(pf)),pf.end());

  ll maxi = 0;
  rep(i,(int)pf.size()) {
    ll p = pf[i];
    ll sum = 0;
    rep(j,n) {
      if( vec[j] % p == 0 ) sum += vec[j];
    }
    maxi = max(maxi,sum);
  }
  cout << maxi << endl;
}

int main() {
  cin >> n;
  vec.resize(n);
  rep(i,n) cin >> vec[i];
  compute();
  return 0;
}



Measured memory_bytes: 3220
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;
typedef pair<int,int> P;
string s;



int main(){
    int x,y,z;cin>>x>>y>>z;
    cout<<z<<' '<<x<<' '<<y<<endl;
}    

Measured memory_bytes: 888
#include <iostream>

using namespace std;

int main() {
    int c = 399;
    int n;  cin >> n;
    int *a = new int[n];
    int *ans = new int[9];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    for (int i = 0; i < n; i++) {
        int j = 0;
        int tmp = c;
        while (j < 8) {
            if (a[i] <= tmp) {
                ans[j]++;
                break;
            }
            j++;
            tmp += 1+c;
        }

        if (j == 8)
            ans[8]++;
    }

    int ans_1 = ans[8], ans_2 = 0;
    for (int i = 0; i < 8; i++) {
        if (ans[i] > 0) {
            ans_1++;
            ans_2++;
        }
    }

    if (ans_2 == 0 && ans[8] > 0)
        ans_2 = 1;
    cout << ans_2 << " " <<  ans_1 << endl;
    return 0;
}

Measured memory_bytes: 256
#UnionFind
#新しくUnion型みたいな箱を作って使っていると思うと分かりやすい
#最初に箱と要素を用意しておいて、箱同士をつなげてくれている
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):#対象の要素がどの箱に入っているか検索
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):#2つの箱を一緒の箱にする。箱の番号は前の番号に依存する
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):#箱の要素数を調べる
        return -self.parents[self.find(x)]

    def same(self, x, y):#同じ箱に入っているか調べる
        return self.find(x) == self.find(y)

    def members(self, x):#要素xが所属するグループ
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):#残っている箱を全て配列として表示
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):#箱の数を見ている
        return len(self.roots())

    def all_group_members(self):#全ての箱を辞書型でくれる
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
       return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N , M = map(int, input().split())
uf = UnionFind(N)
while True:
    try:
        listA = list(map(int,input().split()))
        uf.union(listA[0] - 1,listA[1] - 1)
    except:
        break

print(uf.group_count() - 1)

Measured memory_bytes: 75228
import java.util.*;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int t = sc.nextInt();
		long ret = 0;
		if (n==1) {
			System.out.println(t);
			return;
		}
		long s = sc.nextInt();
		long e = t;
		for (int i = 1;i < n;i++) {
			int tmp = sc.nextInt();
			if (tmp>e) {
				ret += e-s;
				s = tmp;
				e = tmp + t;
			} else {
				e = tmp + t;
			}
		}
		ret += e-s;
		System.out.println(ret);
	}
}


Measured memory_bytes: 62692
#include<bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  int result = 0;
  result = max(a, b);
  if(result == a) {
      result += max(a-1, b);
  } else {
      result += max(a, b-1);
  }
  cout << result << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<long>num(5,0);
    string s;
    for(int i=0;i<n;i++){
        cin >> s;
        if(s[0] == 'M')num[0]++;
        if(s[0] == 'A')num[1]++;
        if(s[0] == 'R')num[2]++;
        if(s[0] == 'C')num[3]++;
        if(s[0] == 'H')num[4]++;
    }
    long ans = 0;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                ans += num[i]*num[j]*num[k];
            }
        }
    }
    cout << ans << endl;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    cout << (n-1+k-2)/(k-1) << endl;

}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define MOD 998244353LL
using namespace std;
typedef long long int ll;

long long int powmod(long long int a, long long int k, long long int m){ //0<=a<=1e9, 0<k<=1e18, 0<m<=1e9
	if(a==0){
		return 0;
	}
	long long int apow[30], c[30];
	for(int i=0; i<30; i++){
		if(i==0){
			apow[i]=a;
			c[i]=1;
		}else{
			apow[i]=apow[i-1]*apow[i-1]%m;
			c[i]=c[i-1]*2;
		}
	}
	long long int ans=1;
	for(int i=29; i>=0; i--){
		if(k>=c[i]){
			ans=ans*apow[i]%m;
		}
		k=k%c[i];
	}
	return ans;
}

ll inv(ll x, ll p){
  return powmod(x, p-2, p);
}

int main()
{
	ll n, a, b, k;
  scanf("%lld %lld %lld %lld", &n, &a, &b, &k);
  ll f[300001], invf[300001];
  f[0]=1, invf[0]=1;
  for(ll i=1; i<=n; i++){
    f[i]=f[i-1]*i%MOD;
    invf[i]=inv(f[i], MOD);
  }
  ll ans=0;
  for(ll i=0; i<=n; i++){
    if((k-a*i)%b!=0) continue;
    ll j=(k-a*i)/b;
    if(j<0 || j>n) continue;
    ans=(ans+f[n]*invf[n-i]%MOD*invf[i]%MOD*f[n]%MOD*invf[n-j]%MOD*invf[j]%MOD)%MOD;
  }
  printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
    long long int n,mw,w,v,dp[100001]={};
    cin>>n>>mw;
    while(n--)
    {
        cin>>w>>v;
        for(int j=100000;j>=w;j--)
        {
            dp[j]=max(dp[j],dp[j-w]+v);
        }
    }
    cout<<dp[mw];
}


Measured memory_bytes: 1024
import sys
import itertools


def resolve(in_):
    N = int(next(in_))
    D = [tuple(map(int, line.split())) for line in itertools.islice(in_, N)]

    i = 0
    for a, b in D:
        if a == b:
            i += 1
            if i >= 3:
                return True
        else:
            i = 0

    return False



def main():
    answer = resolve(sys.stdin)
    print('Yes' if answer else 'No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int h, a;cin >> h >> a;
   if(h%a==0) {
       cout << h/a << endl;
   } else {
       cout << h/a+1 << endl;
   }

}

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

#define ll long long

int main()
{
    ll i, j, n, x, y, z, count;
    queue <ll> q[10];

    cin >> count;

    for(i=1; i<=9; i+=1)
        q[i].push(i);

    while(count!=0)
    {
        for(i=1; i<=9; i+=1)
        {
            n=q[i].size();
            for(j=0; j<n; j+=1)
            {
                x=q[i].front();
                q[i].pop();
                count-=1;
                if(count==0)
                {
                    cout << x << endl;
                    return 0;
                }

                y=x%10;
                z=x*10;
                if(y==0)
                {
                    q[i].push(z+0);
                    q[i].push(z+1);
                }
                else if(y<9)
                {
                    q[i].push(z+y-1);
                    q[i].push(z+y);
                    q[i].push(z+y+1);
                }
                else
                {
                    q[i].push(z+y-1);
                    q[i].push(z+y);
                }
            }
        }
    }
}

Measured memory_bytes: 5212
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
char str[1005],str1[1005],str2[1005];
int main()
{
	scanf("%s",str);
	int len = strlen(str);
	int l = len;
	for(int x = 0; x < l; x++){
		memset(str1,0,sizeof(str1));
		memset(str2,0,sizeof(str2));
		len = len - 1;
		if(len == 0) {
			printf("0\n");
			return 0;
		}
		if(len % 2 == 0){ 
			int a = len/2-1,b = len/2;
			for(int i = 0; i <= a; i++)
				str1[i] = str[i];
			for(int i = b; i < len; i++)
				str2[i-b] = str[i];
			if(strcmp(str1,str2) == 0) 
			{
				printf("%d\n", len);
				break;
			}
		}
	}
}

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

using namespace std;
typedef long long ll;

// マクロ
/// ループ
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);++i)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);--i)
#define REP(i,n) FOR(i,0,n) 
#define REPD(i,n) FORD(i,n,0)
/// コンテナ用
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
/// 定数
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5 配列の最大のRANGE
/// 略記
#define PB push_back
#define MP make_pair
#define F first
#define S second

auto main(int argc, char *argv[]) -> signed {
    string s;
    cin >> s;
    
    int cnt = 0;
    for (char c : s) {
        if (c == '1') cnt++;
    }
    
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

int N, M;
int ConstellationX[200], ConstellationY[200], StarX[1000], StarY[1000];
bool StarXInfo[2000001], StarYInfo[2000001];

void solve(int &dx, int &dy) {
	bool flag;

	for (int i = 0; i < N; ++i) {
		dx = StarX[i] - ConstellationX[0];
		dy = StarY[i] - ConstellationY[0];
		flag = true;
		for (int j = 1; j < M; ++j) {
			if (!StarXInfo[ConstellationX[j] + dx] || !StarYInfo[ConstellationY[j] + dy]) {
				flag = false;
				break;
			}
		}
		if (flag) {
			return;
		}
	}
}

int main() {
	int x, y;
	
	while (cin >> M, M) {
		memset(StarXInfo, false, sizeof(StarXInfo));
		memset(StarYInfo, false, sizeof(StarYInfo));
		for (int i = 0; i < M; ++i) {
			cin >> x >> y;
			ConstellationX[i] = x;
			ConstellationY[i] = y;
		}
		cin >> N;
		for (int i = 0; i < N; ++i) {
			cin >> x >> y;
			StarX[i] = x;
			StarY[i] = y;
			StarXInfo[x] = true;
			StarYInfo[y] = true;
		}
		solve(x, y);
		cout << x << " " << y << endl;
	}

	return 0;
}


Measured memory_bytes: 7024
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	int N, A;
	cin >> N >> A;
	cout << N * N - A << endl;
}


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

int main() {
	std::string s, t;
	std::cin >> s >> t;
	std::sort(s.begin(), s.end());
	std::sort(t.begin(), t.end(), std::greater<>());
	if (s < t) { std::cout << "Yes" << std::endl; }
	else { std::cout << "No" << std::endl; }
}

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

using namespace std;

int main(void) {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<int64_t> A(X), B(Y), C(Z), D(X*Y), E(3000*Z);
    for(int i=0; i<X; i++) {
        cin >> A[i];
    }
    for(int i=0; i<Y; i++) {
        cin >> B[i];
    }
    for(int i=0; i<Z; i++) {
        cin >> C[i];
    }

    for(int i=0; i<X; i++) {
        for(int j=0; j<Y; j++) {
            D[i*Y+j] = A[i] + B[j];
        }
    }

    sort(D.rbegin(), D.rend());
    for(int i=0; i<min(3000, X*Y); i++) {
        for(int j=0; j<Z; j++) {
            E[i*Z+j] = D[i] + C[j];
        }
    }
    sort(E.rbegin(), E.rend());

    for(int i=0; i<K; i++) {
        cout << E[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 31616
# F - Tree and Constraints

# Read input

n = int(input())
adj = {a: [] for a in range(1, n + 1)}
for i in range(n - 1):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
m = int(input())
ranges = []
for i in range(m):
    u, v = map(int, input().split())
    ranges.append((u, v))

# Subroutines

def normalized(u, v):
    return (min(u, v), max(u, v))

def findpath(u, v, visited=None):
    """uからvへの経路 (辺の集合)"""
    if visited is None:
        visited = set()
    if u == v:
        return set()
    if u in visited:
        return None
    visited.add(u)
    for x in adj[u]:
        p = findpath(x, v, visited)
        if p is not None:
            p.add(normalized(u, x))
            return p

def powerset(seq, bag):
    """(seqの部分集合s, bag[e] for e in s の和集合)"""
    if len(seq) <= 1:
        yield ((seq[0],), bag[seq[0]])
        yield ((), set())
    else:
        for s, b in powerset(seq[1:], bag):
            yield ((seq[0],) + s, b | bag[seq[0]])
            yield (s, b)

# Find paths

paths = {}
for u, v in ranges:
    paths[(u, v)] = findpath(u, v)

# いずれかの区間をすべて白にする塗り方の個数
coloring = 0
for s, b in powerset(ranges, paths):
    l = len(s)
    if l <= 0:
        continue
    # b中の辺をすべて白にする塗り方の個数
    c = 2 ** ((n - 1) - len(b))
    # 包除原理
    sign = -1 if l % 2 == 0 else 1    
    coloring += sign * c

# どの区間も黒を含む塗り方の個数
coloring = 2 ** (n - 1) - coloring
print(coloring)


Measured memory_bytes: 48092
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

ll ans;
int op[15];
string S;

void dfs(int depth,int depthmax){
	if(depth==depthmax){

		string str[15];

		int cnt=0;
		int pos=0;

		while(1){
			string s="";

			while(1){
				if(pos==S.length()-1){
					s+=S[pos];
					pos++;
					break;
				}
				if(op[pos]==1){
					s+=S[pos];
					pos++;
					break;
				}
				s+=S[pos];
				pos++;
			}
			str[cnt]=s;
			cnt++;
			if(pos==S.length()){break;}
		}
		int i;

		for(i=0;i<cnt;i++){
		ans+=stoll(str[i]);
		}
		return;
	}

	op[depth]=1;

	dfs(depth+1,depthmax);

	op[depth]=0;

	dfs(depth+1,depthmax);

}

int main(){

	cin>>S;

	dfs(0,S.length()-1);

	printf("%lld\n",ans);

	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);
            String x;
            while(true){
                x=sc.next();
                if(x.equals("0")) break;
                int sum=0;
                for(int i=0;i<x.length();i++){
                    sum+=x.charAt(i)-'0';
                }
                System.out.println(sum);
            }
        }
    }


Measured memory_bytes: 26396
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			String n = sc.nextLine();
			if(n.equals(".")) break;
			else calc(n);
		}
	}
	public void calc(String line){
		int ans = 0;
		LinkedList<Integer> list = new LinkedList<Integer>();
		for(int i = 0; i < line.length(); i++){
			char c = line.charAt(i);
			if(c == '(') list.push(0);
			else if(c == '[') list.push(1);
			else if(c == ')'){
				if(list.size() == 0){
					ans = 1;
					break;
				}
				int t = list.pop();
				if(t != 0){
					ans = 1;
					break;
				}
			}
			else if(c == ']'){
				if(list.size() == 0){
					ans = 1;
					break;
				}
				int t = list.pop();
				if(t != 1){
					ans = 1;
					break;
				}
			}
		}
		if(ans == 1 || list.size() != 0){
			System.out.println("no");
		}
		else{
			System.out.println("yes");
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 32688
#include <bits/stdc++.h>
#define lli long long int
using namespace std;

bool compare(const pair<lli, lli> &i, const pair<lli, lli> &j)
{
	if(i.first == j.first) return i.second < j.second;
	else return i.first < j.first;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n;
	lli a, b;
	
	cin >> n;
	
	vector< pair<lli, lli> > v;
	
	for(int i = 0; i < n; i++){
		cin >> a >> b;
		v.push_back({b, a});
	}
	
	sort(v.begin(), v.end(), compare);
	
	lli sum = 0;
	
	for(int i = 0; i < n; i++){
		sum += v[i].second;
		
		if(v[i].first < sum){
			cout << "No" << "\n";
			return 0;
		}
	}
	
	cout << "Yes" << "\n";
	
	return 0;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

ll on[100010];
ll off[100010];

int main(){
	string s; cin >> s;
	int n = s.size();
	on[0] = 2, off[0] = 1;
	for( int i = 0; i < n; ++i ){
		if( s[i+1] == '1' ){
			on[i+1] = on[i]*2;
			off[i+1] = on[i]+off[i]*3;
		} else {
			on[i+1] = on[i];
			off[i+1] = off[i]*3;
		}
		on[i+1] %= mod;
		off[i+1] %= mod;
	}
	cout << ( on[n-1] + off[n-1] ) % mod << endl;
}

Measured memory_bytes: 2048
/**	epsileer 11 January 2020  16:01:47  **/	
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TEST int t = 1; while(t--) solve()

void solve(){
	int n; cin>>n;
	map<string,int> mp;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		string s; cin>>s; cin>>a[i];
		mp[s] = i;
	}
	string s; cin>>s;
	int idx = mp[s], sum = 0;
	for(int i=idx+1;i<n;i++)
		sum += a[i];
	cout<<sum;
}

signed main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); TEST; return 0;
}

Measured memory_bytes: 256
num = (10 ** 9) + 7
n, k = map(int, input().split())
a = list(map(int, input().split()))

plus = []
minus = []
zero = 0
ans = 1

for i in a:
    if i > 0:
        plus.append(i)
    elif i < 0:
        minus.append(-i)
    else:
        zero += 1

plus.sort()
minus.sort()
p_l = len(plus)
m_l = len(minus)
cnt = 0


def tail_num(p):
    return p[-1] * p[-2]


if k == 1:
    print(max(a) % num)
elif zero > n - k:
    print(0)
elif zero == n - k:
    for i in plus:
        ans = (i * ans) % num
    for j in minus:
        ans = (ans * j) % num
    if m_l % 2 == 0:
        print(ans)
    else:
        print(-ans % num)
elif len(plus) == 0:
    if k % 2 == 0:
        for j in range(k):
            ans = ans * (minus[-(j + 1)]) % num
        print(ans % num)
    else:
        if 0 in a:
            print(0)
        else:
            for j in range(k):
                ans = ans * (minus[j]) % num
            print(-ans % num)
else:
    if k % 2 == 1:
        ans = ans * plus.pop() % num
        p_l -= 1
    for i in range(k//2):
        if p_l >= 2 and m_l >= 2:
            if tail_num(minus) >= tail_num(plus):
                ans = ans * tail_num(minus) % num
                minus.pop()
                minus.pop()
                m_l -= 2
            else:
                ans = ans * tail_num(plus) % num
                plus.pop()
                plus.pop()
                p_l -= 2
        else:
            if p_l <= 1:
                ans = ans * tail_num(minus) % num
                minus.pop()
                minus.pop()
                m_l -= 2
            else:
                ans = ans * tail_num(plus) % num
                plus.pop()
                plus.pop()
                p_l -= 2
    print(ans)



Measured memory_bytes: 31608
import sys

fin = sys.stdin.readline

n = int(fin())
p = list(map(int, fin().split()))

count = 0
for i in range(len(p)-2):
    if (p[i] - p[i + 1]) * (p[i+1]-p[i+2]) >0:
        count += 1

print(count)

Measured memory_bytes: 38384
import heapq


n = int(input())
a = [int(_) for _ in input().split()]
q = []
heapq.heapify(q)
i = 0
total = 0
minus = 0
while i < n:
    if a[i] < 0:
        heapq.heappush(q, -a[i])
        total -= a[i]
        minus += 1
    else:
        heapq.heappush(q, a[i])
        total += a[i]
    i += 1
if minus % 2 == 1:
    ans = total - 2 * heapq.heappop(q)
else:
    ans = total
print(ans)

Measured memory_bytes: 14412
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int s;
    cin >> s;
    set<int> all;
    all.insert(s);
    for(int i=2; i<INT_MAX; i++){
        if(s % 2 == 0) s /= 2;
        else s = 3 * s + 1;
        if(all.count(s) == 1){
            cout << i << endl;
            return 0;
        }
        all.insert(s);
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
struct node
{
    int to,next;
}e[MAX];
int head[MAX],cut;
void add(int u,int v)
{
    e[cut].to=v;
    e[cut].next=head[u];
    head[u]=cut++;
}
int f[MAX],dp[MAX],p[MAX],x[MAX],n;
int dfs(int u)
{
    for(int i=head[u];~i;i=e[i].next)//先遍历。
        dfs(e[i].to);
    memset(dp,0x3f,sizeof(dp));
    dp[0]=0;
    for(int i=head[u];~i;i=e[i].next)
    {
        int v=e[i].to;
        for(int j=x[u];j>=0;j--)
        {
            int temp=INF;
            if(j>=x[v]) //u,v同色。
                temp=min(temp,dp[j-x[v]]+f[v]);
            if(j>=f[v])//u,v不同色。
                temp=min(temp,dp[j-f[v]]+x[v]);
            dp[j]=temp;
        }
    }
    for(int i=0;i<=x[u];i++)
        f[u]=min(f[u],dp[i]);
}
int main()
{
    cut=0;
    memset(head,-1,sizeof(head));
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        scanf("%d",&p[i]);
        add(p[i],i);
    }
    for(int i=1;i<=n;i++)
        scanf("%d",&x[i]);
    memset(f,0x3f,sizeof(f));
    
    dfs(1);
    if(f[1]<INF)
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
  ll x; cin >> x;
  ll cnt = x/11*2;
  cnt += x%11/6+min(1LL, x%11%6);
  cout << cnt << endl;

}


Measured memory_bytes: 256
h, w = list(map(int, input().split()))
s = [list(input()) for _ in range(h)]

dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]

for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            continue
        else:
            cnt = 0
            for k in range(8):
                i += dx[k]
                j += dy[k]
                if (0<=i and i<h) and (0<=j and j<w):
                    if s[i][j]=='#':
                        cnt += 1
                i -= dx[k]
                j -= dy[k]
            s[i][j] = str(cnt)

for i in range(h):
    print(''.join(s[i]))

Measured memory_bytes: 3188
def move(direction, x, y):
    tmp_x, tmp_y = x, y
    if direction == 'U': tmp_y += 1
    if direction == 'D': tmp_y -= 1
    if direction == 'L': tmp_x -= 1
    if direction == 'R': tmp_x += 1
    print(direction, end = '')
    return tmp_x, tmp_y

sx, sy, tx, ty = map(int, input().split())

x, y = sx, sy

# 往路1
while x != tx:
    x, y = move('R', x, y)
while y != ty:
    x, y = move('U', x, y)
# 復路1
while x != sx:
    x, y = move('L', x, y)
while y != sy:
    x, y = move('D', x, y)
# 往路2
x, y = move('D', x, y)
while x != tx:
    x, y = move('R', x, y)
x, y = move('R', x, y)
while y != ty:
    x, y = move('U', x, y)
x, y = move('L', x, y)
# 復路2
x, y = move('U', x, y)
while x != sx:
    x, y = move('L', x, y)
x, y = move('L', x, y)
while y != sy:
    x, y = move('D', x, y)
x, y = move('R', x, y)

print('')


Measured memory_bytes: 4468
n,*c=map(int,open(0).readlines())
l=[-1]*2**18
b=[]
for i in range(n):
  b.append(l[c[i]])
  l[c[i]]=i
dp=[1]+[0]*n
for i in range(1,n):
  dp[i]=dp[i-1]
  if c[i]!=c[i-1]and b[i]>-1:
    dp[i]=(dp[i]+dp[b[i]])%(10**9+7)
print(dp[-2])

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

#define MAX 1001

int A[MAX][MAX];

int lcs(char *X, char *Y) {
	int i, j, lenX, lenY;
	lenX = strlen(&X[1]);
	lenY = strlen(&Y[1]);
	for (i = 1; i <= lenX; i++) {
		for (j = 1; j <= lenY; j++) {
			if (X[i] == Y[j]) {
				A[i][j] = A[i - 1][j - 1] + 1;
			}
			else if (A[i - 1][j] >= A[i][j - 1]) {
				A[i][j] = A[i - 1][j];
			}
			else {
				A[i][j] = A[i][j - 1];
			}
		}
	}
	return A[lenX][lenY];
}

int main(void) {
	int n, i;
	char X[MAX], Y[MAX];

	for (i = 0; i < MAX; i++) {
		A[i][0] = 0;
		A[0][i] = 0;
	}

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", &X[1]);
		scanf("%s", &Y[1]);
		printf("%d\n", lcs(X, Y));
	}

	return 0;
}


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

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

  int ans = 1;
  int a = 0, b = 0;
  for(int i = 0; i < n; i++){
    a = ans * 2;
    b = ans + k;
    ans = min(a,b);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define PI 3.1415926535

int main(){
    double a,b,c,d;
    int n;
    
    while(1){
        cin >> a >> b >> c;
        if(!a&&!b&&!c) break;
        
        double e = min(min(sqrt(pow(a,2)+pow(b,2)),sqrt(pow(a,2)+pow(c,2))),sqrt(pow(b,2)+pow(c,2)));
        
        cin >> n;
        for(int i = 0 ; i < n ; i++){
            cin >> d;
            if(d*2 <= e) cout << "NA" << endl;
            else cout << "OK" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int>>;

int N, M;

int main(){
    cin >> N >> M;
    cout << (N * (N - 1) + M * (M - 1)) / 2;
    return 0;
}

Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1e9+7;



int main(){

int N,sum=0;
cin>>N;
int s[N];
rep(i,N){
    
    cin>>s[i];
    sum+=s[i];

}
if(sum%10!=0){
    cout<<sum<<endl;
    return 0;
}
sort(s,s+N);
rep(i,N){
    if(s[i]%10!=0){
        sum-=s[i];
        cout<<sum<<endl;
        return 0;

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

Measured memory_bytes: 3604
from collections import Counter
from itertools import combinations


def prime_factors(n):
    c = Counter()
    while n > 1:
        for i in range(2, n + 1):
            if n % i == 0:
                c.update([i])
                n //= i
                break
    return c


def factrials(n):
    c = {}
    for i in range(2, n + 1):
        d = prime_factors(i)
        for k, v in d.items():
            if k in c:
                c[k] += v
            else:
                c[k] = v
    return c


def solve(N):
    facts = factrials(N)
    over2 = [k for k, v in facts.items() if v >= 2]
    over4 = [k for k, v in facts.items() if v >= 4]
    over14 = [k for k, v in facts.items() if v >= 14]
    over24 = [k for k, v in facts.items() if v >= 24]
    over74 = [k for k, v in facts.items() if v >= 74]

    sum = 0
    # 4 - 4 - 2
    sum += len([(d, d4) for d in over2 for d4 in combinations(over4, 2) if d not in d4])
    # 4 - 14
    sum += len([(d, d4) for d in over14 for d4 in over4 if d != d4])
    # 2 - 24
    sum += len([(d, d2) for d in over24 for d2 in over2 if d != d2])
    # 74
    sum += len(over74)

    return sum

if __name__ == "__main__":
    print(solve(int(input())))


Measured memory_bytes: 3444
N, C, K = map(int, input().split(" "))
T = sorted([int(input()) for _ in range(N)])

bus = 0
i = 0
while i < N:
    bus += 1
    start = i
    while i < N and T[i] - T[start] <= K and i - start < C:
        i += 1
print(bus)

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

using namespace std;

int main()
{
  string str;
  
  cin >> str;
  
  if(str.length() != 3){
    return -1;
  }
  
  int count = 0;
  for(int i=0; i<3; i++){
    if(str[i] == '1'){
      count++;
    }
  }
  
  cout << count;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if((0 <= x-r) && ( r+x <= W) && (0 <= y-r) && ( r+y <= H)){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
    
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k,q;
  cin >> n >> k >> q;
  vector<int> point(n,k-q);
  REP(qq,q){
    int a; cin >> a;
    a--;
    point[a]++;
  }
  REP(i,n) cout << (point[i]>0 ? "Yes\n" : "No\n");
  return 0;
}


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

int main() {
  int n;
  int p[100];
  int maxi = -1;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> p[i];

  for (int i = 1; i <= 100; ++i) {
    int a = i, cnt = 0;
    for (int j = 0; j < n; ++j) {
      cnt += (p[j] >= a);
    }
    maxi = max(maxi, (cnt >= a ? a : -1));
  }
  cout << maxi << endl;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {

    unsigned long long a = 0;

    int q;
    cin >> q;
    rep(i, q) {
        int query;
        cin >> query;
        if (query == 0) {
            int i;
            cin >> i;
            cout << ((a >> i) & 1ll) << endl;
        } else if (query == 1) {
            int i;
            cin >> i;
            a |= (1ll << i);
        } else if (query == 2) {
            int i;
            cin >> i;
            a &= (~(1ll << i));
        } else if (query == 3) {
            int i;
            cin >> i;
            a ^= (1ll << i);
        } else if (query == 4) {
            cout << (__builtin_popcountll(a) == 64) << endl;
        } else if (query == 5) {
            cout << (__builtin_popcountll(a) > 0) << endl;
        } else if (query == 6) {
            cout << (__builtin_popcountll(a) == 0) << endl;
        } else if (query == 7) {
            cout << __builtin_popcountll(a) << endl;
        } else if (query == 8) {
            cout << a << endl;
        }
    }

}



Measured memory_bytes: 3104
s = list(input())

ans = []
li = []

def calc(n):
    s = (n*(n+1))//2
    return s

cnt = 1
for i in range(1,len(s)):
    if s[i] == s[i-1]:
        cnt += 1

    elif s[i] != s[i-1]:
        li.append(cnt)
        cnt = 1
li.append(cnt)

ans = 0
if s[0] == "<":
    if len(li)%2 == 1:
        ans += calc(li.pop(-1))

    for i in range(0,len(li),2):
        a = max(li[i],li[i+1])
        b = min(li[i],li[i+1])

        ans += calc(a)
        ans += calc(b-1)

elif s[0] == ">":
    if len(li)%2 == 0:
        ans += calc(li.pop(-1))

    ans += calc(li[0])
    for i in range(1,len(li),2):
        a = max(li[i],li[i+1])
        b = min(li[i],li[i+1])

        ans += calc(a)
        ans += calc(b-1)

print(ans)

Measured memory_bytes: 9776
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n, a, b;
	string s;

	cin >> n >> a >> b;
	cin >> s;

	vector<bool> results(n, false);
	int pass_ab = 0;
	int pass_b = 0;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'a') {
			if (pass_ab < a + b) {
				pass_ab++;
				results[i] = true;
			}
		} else if (s[i] == 'b') {
			if (pass_ab < a + b && pass_b < b) {
				pass_ab++;
				pass_b++;
				results[i] = true;
			}
		}
	}

	for (auto b : results) {
		cout << (b ? "Yes" : "No") << endl;
	}
	return 0;
}


Measured memory_bytes: 896