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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

string S;
ll dp[101010][15];

int main()
{
    cin >> S;

    dp[0][0] = 1;
    rep(i, 0, S.size())
    {
        int c = 0;
        if (S[i] == '?')
        {
            c = -1;
        }
        else
        {
            c = S[i] - '0';
        }

        rep(j, 0, 10)
        {
            if (c != -1 && c != j)
            {
                continue;
            }
            rep(k, 0, 13)
            {
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
            }
        }
        rep(j, 0, 13)
        {
            dp[i + 1][j] %= MOD;
        }
    }

    cout << dp[S.size()][5] << endl;
}


Measured memory_bytes: 12160
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toLong).filter { it % 2 == 0L }
    if (aList.filter { it % 3 != 0L && it % 5 != 0L }.size > 0) {
        println("DENIED")
    } else {
        println("APPROVED")
    }
}


Measured memory_bytes: 36512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
inline void write(int x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
int main()
{
    int n;
    cin>>n;
    int a=0,b=0,c=0;
    for(int i=0;i<n;i++)
    {
        ll x;
        x=read();
        if(x%4==0)
            a++;
        else if(x%2==0)
            b++;
        else c++;
    }
    if(b>0)
        c++;
    if(a+1>=c)
        cout<<"Yes"<<endl;
    else 
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cost = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    if cost > a[x-1] + b[y-1] - c:
        cost = a[x-1] + b[y-1] - c
print(cost)

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

int main(void){
  string s1;
  string s2;
  cin >> s1;
  if(s1 == "ABC"){
    s2 ="ARC";
  }else{
    s2 ="ABC";
  }
  cout << s2<<endl;
  return 0;
}



Measured memory_bytes: 3132
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() (int, int) {
	return scanInt(sc), scanInt(sc)
}

func resolve(d, n int) int {
	if n%100 != 0 {
		return n * factor(d)
	} else {
		return 101 * factor(d)
	}
}

func factor(d int) int {
	r := 1
	for i := 0; i < d; i++ {
		r *= 100
	}
	return r
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

int main() {
    int n, k;
    cin >> n >> k;
    int a[n], sum = 0, result = 1;
    for (int i = 0; cin >> a[i]; i++) {
        sum += a[i];
    }
    auto solve = [&](int num) {
        int r[n], suffix[n + 1];
        for (int i = 0; i < n; i++) {
            r[i] = a[i] % num;
        }
        sort(r, r + n);
        suffix[n] = 0;
        for (int i = n - 1; i >= 0; i--) {
            suffix[i] = suffix[i + 1] + num - r[i];
        }
        for (int prefix = 0, i = 0; i < n; i++) {
            prefix += r[i];
            if (prefix == suffix[i + 1] && prefix <= k) {
                return true;
            }
        }
        return false;
    };
    for (int i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            if (solve(i)) {
                result = max(result, i);
            }
            if (solve(sum / i)) {
                result = max(result, sum / i);
            }
        }
    }
    cout << result;
    return 0;
}


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

int main()
{
	int N;
	cin >> N;
	int d[N];
	for(int i = 0; i < N; i++)
		cin >> d[i];

	int j,i,v;
	for(i = 1; i < N; i++){
		v = d[i];
		j = i - 1;
		while(j >= 0 && d[j] > v){
			d[j + 1] = d[j];
			j--;
		}
		d[j+1] = v;
	}

	int size = 0;
	int X = 0;

	for(i = 0; i < N; i++){
		if(size != d[i]){
			X++;
			size = d[i];
		}
	}

	cout << X << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n,k;
  cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  sort(all(a));
  ll ans=0;
  rep(i,n-k){
    ans+=a[i];
  }
  COUT(ans);
}

Measured memory_bytes: 1792
import bisect

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

ans = 0
for b in B:
    na = bisect.bisect_left(A, b)
    nb = N - bisect.bisect_right(C, b)
    ans += na * nb

print(ans)


Measured memory_bytes: 23360
#include <bits/stdc++.h> 
using namespace std; 
 
int main() {
  int n, k, *height, i, answer = 0;
  cin >> n >> k;
  height = new int[n];
  for(i = 0; i < n; i++)
    cin >> height[i];
  for(i = 0; i < n; i++) {
    if(height[i] >= k) 
      answer++;
  }
  delete []height;
  height = NULL;
  cout << answer;
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#ifdef TEST
#include <mytest.h>
#else
#define open(...) 0
#define print(...) 42
#endif // TEST
using namespace std;
const int N = 1e5 + 5;
int nex[N][30], n;
char s[N], t[N];
long long solve() {
  long long ans = 0, cnt = 0, las = -1;
  for (int i = 0, cur = 0; t[i]; i++) {
    int tmp = nex[cur][t[i] - 'a'];
    if (tmp >= 0) {
      if (tmp <= las) cnt++;
      las = tmp;
      cur = (tmp + 1) % n;
    } else return -1;
  }
  return cnt * strlen(s) + las + 1;
}
int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> s >> t;
  n = strlen(s);
  memset(nex, -1, sizeof nex);
  for (int i = 2 * n - 1; i >= 0; i--) {
    int idx = i % n;
    for (int j = 0; j < 26; j++)
      nex[idx][j] = nex[(i + 1) % n][j];
    nex[idx][s[idx] - 'a'] = idx;
  }
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 12160
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        Map<Integer, Integer> map = new TreeMap<>();
        for (int i = 0; i < N; i++) {
            int e = sc.nextInt();
            if (map.containsKey(e)) {
                map.put(e, map.get(e) + 1);
            } else {
                map.put(e, 1);
            }
        }

        Map<Integer, Integer> sorted = map.entrySet().stream()
                .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
                .collect(Collectors.toMap(s -> s.getKey(), s -> s.getValue(), (s1, s2) -> s2,
                        LinkedHashMap::new));

        int ans = 0;
        for (Entry<Integer, Integer> ent : sorted.entrySet()) {
            if (K <= 0) {
                ans += ent.getValue();
            }

            K--;
        }

        System.out.println(ans);

    }
}


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

int main() {
	int a, b, c, d;
		cin >> a >> b >> c;
		if (a > b) {
			d = a;
			a = b;
			b = d;
		}
		if(b > c) {
			d = b;
			b = c;
			c = d;
		}
		if (a > b) {
			d = a;
			a = b;
			b = d;
	}
		cout << a << " " << b << " " << c << endl;
		
}


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

int main() {
  string w;
  cin>>w;
  int n=w.size();
  vector<int>a(26);
  for(int i=0;i<n;i++){
    a[w[i]-'a']++;
  }
  string ans="Yes";
  for(int i=0;i<26;i++){
    if(a[i]%2==1) ans="No";
  }
  cout<<ans<<endl;
}


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

#define oo 1e9
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;

string s;
ll k,i;

int main(){
    IO;
    cin>>k;
    cin>>s;
    if (s.length()<=k) {
        cout<<s;
    }
    else {
        for (i=0;i<k;i++) {
            cout<<s[i];
        }
        cout<<"...";
    }
}
    

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;
int main(){
	string a,b;
	cin>>a>>b;
	ll x,y;
	cin>>x>>y;
	string c;
	cin>>c;
	if(c==a)
		cout<<x-1<<" "<<y<<endl;
	else
		cout<<x<<" "<<y-1<<endl; 
}


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

int main(){
	for (int i = 0; i < 5; i++)
	{
		int x;
		cin >> x;
		if(x != i+1){
			cout << i+1 << endl;
			return 0;
		}
	}
	
}


Measured memory_bytes: 3592
import sys
m,k=map(int,input().split())
if k>=2**m:
    print(-1)
    sys.exit()
if m==1:
    if k==0:
        xor=[0,0,1,1]
        print(' '.join(map(str,xor)))
    else:
        print(-1)
    sys.exit()
idx=0
xor=[0]*(2**(m+1))

for i in range(2**m-1):
    if idx==k:
        idx+=1
    xor[i]=idx
    idx+=1
xor[2**m-1]=k
idx=2**m-1
for i in range(2**m,2**(m+1)-1):
    if idx==k:
        idx-=1
    xor[i]=idx
    idx-=1
xor[-1]=k
print(' '.join(map(str,xor)))

Measured memory_bytes: 91996
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;
int ans;
string s1,s2;

int main()
{
	int i,j,l1,l2,f=0;
	cin>>s1>>s2;
	if(s1==s2)
	{
		printf("0\n");
		return 0;
	}
	l1=s1.size(),l2=s2.size();
	ans=l2;
	for(i=0;i<l1-l2+1;i++)
	{
		int sum=0;
		string ts=s1.substr(i,l2);
		if(ts==s2)
		{
			printf("0\n");
			return 0;
		}
		for(j=0;j<l2;j++)
		{
			if(sum>=ans) break;
			if(ts[j]!=s2[j]) sum++;
		}
		if(sum) ans=min(ans,sum);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rrep(i,n) for (int i=1; i<=(n); ++i)
#define drep(i,n) for (int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i=s; i<t; ++i)ß
#define pi (acos(-1))
//#define pii pair<int,int>
//#define pll pair<ll,ll>
//#define vec vector
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int, int> P;
const int INF = 1001001001;

// Gcd & Lcm
ll gcd (ll a, ll b) {
  return b ? gcd(b, a%b) : a;
}
ll lcm (ll a, ll b) {
  return a/gcd(a,b)*b;
}

int main(void) {
  string s,t;
	cin >> s >> t;
	int ans = 0;
	for (int i=0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			ans++;
		}
	  else {
			continue;
		}
	}
	cout << ans << endl;
	return 0;
}








  



Measured memory_bytes: 3920
#include <iostream>
#include <queue>
#include <string>
#define MAX 5100
#define MAX_TIMES 50
using namespace std;

typedef pair<int, string> P;
const string final_str = "01234567";

string str[8][MAX];
int str_times[8][MAX];
int count[8];

bool match(string s) {
  int t = s[0] - '0';
  for (int i = 0; ; i++) {
    if (str[t][i] == s) return true;
    if (str[t][i] == "\0") break;
  }
  return false;
}

string s_swap(int a, int b, string s) {
  string k = s;
  char t = k[a];
  k[a] = k[b];
  k[b] = t;
  
  return k;
}

void bfs() {
  queue<P> q;
  P temp;
  temp.first = 0;
  temp.second = final_str;
  q.push(temp);
  str[0][0] = temp.second;
  str_times[0][0] = temp.first;
  count[0]++;

  while (q.empty() == false) {
    temp = q.front();
    q.pop();
    string s = temp.second;
    for (int i = 0; i < 8; i++) {
      if (s[i] == '0') {
	string k[4];
	for (int j = 0; j < 4; j++) {
	  k[j] = "\0";
	}
	
	if (i != 0 && i != 4) {
	  k[0] = s;
	  k[0] = s_swap(i - 1, i, k[0]);
	}
	if (i != 3 && i != 7) {
	  k[1] = s;
	  k[1] = s_swap(i, i + 1, k[1]);
	}
	if (i <= 3) {
	  k[2] = s;
	  k[2] = s_swap(i, i + 4, k[2]);
	}
	if (i >= 4) {
	  k[3] = s;
	  k[3] = s_swap(i - 4, i, k[3]);
	}
	for (int j = 0; j < 4; j++) {
	  if (k[j] == "\0") continue;
	  if (match(k[j]) == false) {
	    P temp2;
	    temp2.first = temp.first + 1;
	    temp2.second = k[j];
	    int n = temp2.second[0] - '0';
	    str[n][count[n]] = temp2.second;
	    str_times[n][count[n]] = temp2.first;
	    count[n]++;
	    q.push(temp2);
	  }
	}
      }
    }
  }
}

void init() {
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < MAX; j++) {
      str[i][j] = "\0";
      str_times[i][j] = 0;
    }
  }
  for (int i = 0; i < 8; i++) {
    count[i] = 0;
  }
}

int main() {
  init();
  bfs();
  
  int a[8];
  while (cin >> a[0]) {
    for (int i = 1; i < 8; i++)
      cin >> a[i];

    string s;
    for (int i = 0; i < 8; i++) {
      s.push_back(a[i] + '0');
    }

    int t = s[0] - '0';
    for (int i = 0; ; i++) {
      if (str[t][i] == "\0") break;
      if (str[t][i] == s) {
	cout << str_times[t][i] << endl;
	break;
      }
    }
  }
  return 0;
}

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

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



Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;



int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	vector<int> task(n+1);
	for (int i = 0; i < n; i++) cin >> a[i];

	if (k > 1000){
		for (int i = 0; i < n; i++) cout << n << " ";
		cout << endl;
		return 0;
	}

	for (int i = 0; i < k; i++){
		for (int j = 0; j <= n; j++){
			task[j] = 0;
		}
		int temp = 0;
		for (int now = 0; now < n; now++){
			task[max(0, now - a[now])] += 1;
			task[min(n, now + a[now] + 1)] -= 1;
		}
		for (int now = 0; now < n; now++){
			temp += task[now];
			a[now] = temp;
		}
	}
	for (int i = 0; i < n; i++){
		cout << a[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 4844
import java.util.Scanner;

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

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int H = scanner.nextInt();
        int M = scanner.nextInt();

        // H * (360 / 12) + M * (30 / 60);
        double theta1 = Math.toRadians(H * 30.0 + M * 0.5);
        // M * (360 / 60);
        double theta2 = Math.toRadians(M * 6.0);
        double dist = 0.0;
        if (theta1 > theta2) {
            dist = Math.sqrt(A * A + B * B - 2 * A * B * Math.cos(theta1 - theta2));
        } else {
            dist = Math.sqrt(A * A + B * B - 2 * A * B * Math.cos(theta2 - theta1));
        }
        System.out.println(dist);
    }
}


Measured memory_bytes: 35836
#include <iostream>
#include <bits/stdc++.h>
#define maxn 200005
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
ll fac[maxn],inv[maxn];
ll pow_mod(ll a,ll n)
{
    ll ret =1;
    while(n)
    {
        if(n&1) ret=ret*a%mod;
          a=a*a%mod;
          n>>=1;
    }
    return ret;
}
void init()
{
    fac[0]=1;
    for(int i=1;i<maxn;i++)
    {
        fac[i]=fac[i-1]*i%mod;
    }
}
ll Cc(ll x, ll y)
{
    return fac[x]*pow_mod(fac[y]*fac[x-y]%mod,mod-2)%mod;
}
ll f[maxn];
int main(){
	
	init();
	ll n,k;
	cin>>n>>k;
	f[1] = 1;
	for(int i=2;i<maxn;i++)
		f[i] = (f[i-1]*i%mod); 
	ll sum = 0;
	for(ll i=0;i<=min(n,k);i++){
		sum+=(Cc(n,i)*Cc(n-1,(n-i-1))%mod);
		sum%=mod;
	}
	cout<<(sum+mod)%mod<<endl;
}

Measured memory_bytes: 4480
import java.util.*;
import java.io.*;

public class Main {
	public static String repeat(String piece, int times){
		String r = "";
		for(int i=0;i<times;i++) r = r+piece;
		return r;
	}
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        sc.nextLine();
        
        System.out.println(repeat("#",W+2));
        for(int h=0;h<H;h++){
        	String pic = sc.nextLine();
        	System.out.println("#"+pic+"#");
        }
        System.out.println(repeat("#",W+2));
    }
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

struct BellmanFordMax {
	BellmanFordMax() {}
	BellmanFordMax(int n) { init(n); }
	vector<vector<pair<int, int> > > E; 
    int N;
	void init(int n) { N = n; E.resize(0); E.clear(); E.resize(n); }
	void add(int a, int b, int c) { E[a].push_back({ b, c }); }
	vector<ll> solve(int s) {
		vector<ll> res(N, -L_INF); //最終的なコスト
		res[s] = 0;
 
        //最長経路を求める (辺に-1をかけると最短経路になる？)
		rep(i, N - 1) {
			rep(cu, N){
                if (-L_INF < res[cu]){
                    for(auto p:E[cu]) {
                        chmax(res[p.first], res[cu] + p.second);
                    }
                }
            }
		}

        //最長経路において正のサイクルの見つける
		vector<bool> pos(N);
		rep(i, N) {
			rep(cu, N) {
                if (-L_INF < res[cu]) {
                    for(auto p:E[cu]) {
                        if (chmax(res[p.first], res[cu] + p.second)) {
                            pos[p.first] = true;
                        }
                        if (pos[cu]) pos[p.first] = true;
                    }
                }
			}
		}
 
		rep(cu, N) if (pos[cu]) res[cu] = L_INF;
 
		return res;
	}
};
//参考 はまやんさんのサイト
//https://www.hamayanhamayan.com/entry/2019/08/14/131217
//問題 ABC137 E https://atcoder.jp/contests/abc137/tasks/abc137_e
signed main()
{   
    gearup;
    int N, M, P; cin >> N >> M >> P;
	BellmanFordMax bf(N);
	rep(i, M) {
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		bf.add(a, b, c - P);
	}
 
	ll ans = bf.solve(0)[N - 1];
 
	if (ans == L_INF) ans = -1;
	else if (ans < 0) ans = 0;
 
	cout << ans << endl;
}


Measured memory_bytes: 3812
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<iterator>

using namespace std;
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef vector<int> VE;
#define int long long
#define INF 1000000009
#define INFL 1000000000000000018
#define mod 1000000007
#define pb push_back
#define MAXN 100005

int n, m, toa[200010], tob[200010];
string s;
vector<int> G[200010];
bool used[200010];

signed main()
{
    cin >> n >> m >> s;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        G[a].pb(b);
        G[b].pb(a);
        if(s[a - 1] == 'A') toa[b]++;
        else tob[b]++;
        if(s[b - 1] == 'A') toa[a]++;
        else tob[a]++;
    }
    queue<int> que;
    for(int i = 1; i <= n; i++){
        if(toa[i] == 0 || tob[i] == 0){
            que.push(i);
            used[i] = true;
        }
    }
    int cnt = 0;
    while(!que.empty()){
        int pos = que.front();
        que.pop();
        cnt++;
        for(int i = 0; i < (int)G[pos].size(); i++){
            int to = G[pos][i];
            if(!used[to]){
                if(s[pos - 1] == 'A') toa[to]--;
                else tob[to]--;
                if(toa[to] == 0 || tob[to] == 0){
                    used[to] = true;
                    que.push(to);
                }
            }
        }
    }
    if(cnt == n){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }

    return 0;
}


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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V)                                                           \
    for (auto v : (V))                                                         \
        cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    REP(i, M) { cin >> A[i]; }
    auto sum = accumulate(A.begin(), A.end(), 0);
    if (sum > N) {
        cout << -1 << endl;
    } else {
        cout << N - sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3668
import qualified Data.ByteString.Char8 as BC
import Data.IORef
import Control.Monad(when)
import Data.Foldable(for_)
import Data.Maybe(fromJust)

main :: IO()
main = BC.getContents >>= solve.map (fst.fromJust.BC.readInt).BC.lines >>= print

solve :: [Int] -> IO Int
solve (_:x:y:xs) = do
                a <- newIORef (y - x)
                b <- newIORef (min x y)
                for_ xs $ \z -> do
                    a' <- readIORef a
                    b' <- readIORef b
                    when (z - b' > a') $ writeIORef a (z - b')
                    when (z < b')      $ writeIORef b z
                readIORef a

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

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

    int vec[N];

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

    int min = 10000000;
    for (int i = 0; i < N; i++) {
        if (min > vec[i]) {
            min = vec[i];
        }
    }

    for (int i = 0; i < N; i++) {
        X -= vec[i];
    }

    int num = 0;

    while (X >= 0) {
        X -= min;
        num++;
    }

    std::cout << N + num - 1 << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string n;
    cin >> n;
    int chk = 0;
    rep(i, n.size()) {
        chk += n[i] - '0';
        chk %= 9;
    }
    if(chk%9==0) cout << "Yes" << "\n";
    else         cout << "No" << "\n";
	return 0;
}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	sort(v.rbegin(),v.rend());
	int sum=0;
	for(int i=1;i<n;i++)
	{
		sum=sum+v[i];
	}
	if(sum>v[0])
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
using namespace std;
double tb[100][100], dp[2][100][100];
int main() {
	int n,m;
	while(scanf("%d %d",&n,&m),n) {
		for(int i=0;i<n;i++) for(int j=0;j<n;j++) {
			scanf("%lf",&tb[i][j]);
		}
		fill((double*)dp[1],(double*)dp[2],1);
		for(int i=2;i<=m;i++) for(int j=0;j<n;j++) for(int k=0;k<n;k++) {
			double mv=0;
			for(int l=0;l<n;l++) mv=max(mv,dp[(i-1)%2][k][l]);
			dp[i%2][j][k]=mv*tb[j][k];
		}
		double mv=0;
		for(int i=0;i<n;i++) for(int j=0;j<n;j++) {
			mv=max(mv,dp[m%2][i][j]);
		}
		printf("%.2lf\n",mv);
	}
}

Measured memory_bytes: 1324
N, M = map(int, input().split())
#tmp = [[] for i in range(N)]
tmp = []
res = ['' for i in range(M)]
count = [1 for i in range(N+1)]
for i in range(M):
    A, B = map(int, input().split())
    tmp.append([A,B,i])

tmp.sort(key=lambda tmp: tmp[1])

for i in range(M):
    res[tmp[i][2]] += '0'*(6-len(str(tmp[i][0]))) + str(tmp[i][0]) + '0'*(6-len(str(count[tmp[i][0]]))) + str(count[tmp[i][0]])
    count[tmp[i][0]] += 1

for i in range(M):
    print(res[i])



Measured memory_bytes: 32176
#include <stdio.h>
int main(void){
    int ans[100],temp,i=0,j;
    while(scanf("%d",&temp)!=EOF) {
        ans[i] =temp*(temp+1)/2 + 1;
        i++;
    }
    for(j=0;j<i;j++) printf("%d\n",ans[j]);
    return 0;
}

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

'''
Author: andyli
Time: 2020-07-25 19:57:02
'''

import os
from io import BytesIO, IOBase
import sys


def main():
    n = int(input())
    A = list(map(int, input().split()))

    a, b, p = 1000, 0, 0
    while p+1 < n and A[p] >= A[p+1]:
        p += 1
    while p < n-1:
        t = a//A[p]
        b += t
        a -= t*A[p]
        while p+1 < n and A[p] <= A[p+1]:
            p += 1
        a += b*A[p]
        b = 0
        if p == n:
            break
        while p+1 < n and A[p] >= A[p+1]:
            p += 1
    print(a)
    return


# region fastio
BUFSIZE = 1048576


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode('ascii'))
        self.read = lambda: self.buffer.read().decode('ascii')
        self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip('\r\n')

# endregion


if __name__ == '__main__':
    main()


Measured memory_bytes: 62776
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)

int main() {
  int a,b,c;cin>>a>>b>>c;
  int ans = a==b?c:(b==c?a:b);
  cout << ans << endl;
}


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

int main(int argc, char **argv)
{
    enum String {A, B, C};
    enum Count {AB, BC, CA};
    std::vector<std::string> string;
    std::vector<int> count;
    string.resize(3);
    count.resize(3);

    int N;

    std::cin >> N;
    for (int i=0; i<3; ++i) 
    {
        std::cin >> string[i];
        count[i] = 0;
    }

    for (int i=0; i<N; ++i)
    {
        if (string[A][i] == string[B][i]) {++count[AB];}
        if (string[B][i] == string[C][i]) {++count[BC];}
        if (string[C][i] == string[A][i]) {++count[CA];}        
    }

    int max_count = 0;
    for (int i=0; i<3; ++i) 
    {
        if (max_count < count[i]) {max_count = count[i];}
    }

    int answer_count = 0;
    std::vector<bool> same;
    same.resize(3);
    int judge;

    for (int i=0; i<N; ++i)
    {
        judge = 0;
        if (string[A][i] == string[B][i]) {same[AB] = true;}
        else {same[AB] = false;}
        if (string[B][i] == string[C][i]) {same[BC] = true;}
        else {same[BC] = false;}
        if (string[C][i] == string[A][i]) {same[CA] = true;}
        else {same[CA] = false;}
        
        for (int j=0; j<3; ++j)
        {
            if (same[j] == true) {++judge;}
        }    
        
        switch (judge)
        {
            case 0:
                answer_count += 2;
                break;
            case 1:
                answer_count += 1;
                break;
            case 3:
                answer_count += 0;
        }
    }

    std::cout << answer_count << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
//#include <stack>
//#include <queue>
//#include <map>
#include <cmath>
//#include <string>
//#include <sstream>
#include <iomanip>
//#include <complex>
#include <stdio.h>
//小数制度 	cout << fixed << setprecision(5) << tmp << endl;
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int st[10001];
int en[10001];
vector < pair <int , int > > v;
int main(){
 int n;
  while(cin >> n,n){
  	int h,m,s;
  	v.clear();
  	REP(i,n){
	  	scanf("%d:%d:%d",&h,&m,&s);
  		v.push_back(make_pair(h*3600+m*60+s,1));
	  	scanf("%d:%d:%d",&h,&m,&s);
  		v.push_back(make_pair(h*3600+m*60+s,-1));
  	}
  	sort(All(v));
  	//for(int i = 0 ; i < v.size();++i) cout << v[i].first << ":" << v[i].second << endl;
  	//event処理
  	int res , ans ;

    res = ans = 0;
    for(int i = 0 ; i < v.size();++i){
      res += v[i].second;
      ans = max(ans,res);
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1532
s=input()
n=len(s)

if n%2==0:
  m=n//2
  ans1=(4**m-1)//3
  ans2=2*ans1
else:
  m=(n-1)//2
  ans1=(4**(m+1)-1)//3
  ans2=2*(4**m-1)//3

  
s=int(s,2)
tmp1=bin(ans1^s).count('1')
tmp2=bin(ans2^s).count('1')
print(min(tmp1,tmp2))


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


struct cir{
    int x,y,r,c;
};

bool same(cir a,cir b){
    double r2 = (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
    if((a.r+b.r)*(a.r+b.r)>r2)return true;
    else return false;
}

bool used(int n,const vi &vec){
    rep(i,vec.size()){
        int to = vec[i];
        if( (n&(1<<to)) != 0 )return false;
    }
    return true;
}

int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        vector<cir> data;
        
        rep(i,n){
            int x,y,r,c;
            cin>>x>>y>>r>>c;
            data.pb(cir{x,y,r,c});
        }
        
        
        vector<int> G[30];
        
        for(int i=data.size()-1;i>=0;i--){
            for(int j=i-1;j>=0;j--){
                if(same(data[i],data[j])){
                    G[i].pb(j);
                }
            }
        }
        
        static bool dp[1<<24];
        rep(i,1<<n)dp[i]=false;
        dp[(1<<n)-1]=true;
        
        
        for(int i=(1<<n)-1;i>=0;i--){
            if(dp[i]==false)continue;
            rep(j,n){
                for(int k=j+1;k<n;k++){
                    if( (i&(1<<j) )==0 || (i&(1<<k) )==0)continue;
                    if( data[j].c==data[k].c && used(i,G[j]) && used(i,G[k]) ) dp[(i^(1<<j))^(1<<k)] = true;
                }
            }
        }
        
        int ans=100;
        for(int i=(1<<n)-1;i>=0;i--){
            if(dp[i]==false)continue;
            ans = min(ans,__builtin_popcount(i));
        }
        cout<<n-ans<<endl;
    }
}

Measured memory_bytes: 19432
#include<stdio.h>

int A[2000001],B[2000001];

int main(){
  int C[10001];
  int n,i,j;

  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&A[i]); 

  for(i = 0; i < 10001; i++) C[i]=0;
  for(i = 0; i < n; i++) C[A[i]]++;
  for(i = 1; i < 10001; i++) C[i] = C[i] + C[i-1];

  for(i = n-1;i >= 0 ; i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
  for(i = 0; i < n; i++){
    if(i) printf(" ");
    printf("%d",B[i+1]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 17448
#include <stdio.h>
#include <math.h>

int main()
{
    double t, a;
    int n, k;
    scanf("%d%lf%lf", &n, &t, &a);
    int h[n];
    double min = 10000000;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &h[i]);
        if (min > fabs((t - h[i] * 0.006) - a))
        {
            min = fabs((t - h[i] * 0.006) - a);
            k = i;
        }
    }
    printf("%d\n", k + 1);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
#define INF 100000000
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rep(i, n) for(int (i)=1; (i)<=(n); (i)++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int N;
    cin >> N;
    int c;
    int ans = 0;
    for(int i = 1; i <= N; i++){
        c = 0;
        if(i % 2 != 0){
            for(int j = 1; j <= i; j++){
                if(i % j == 0){
                    c++;
                }
            }
            if(c==8){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, m;

vector<pll> rem[MAXN];

ll tree[MAXN], t[4*MAXN], lazy[4*MAXN];
ll dp[MAXN];

ll get(int ind){
    ll res = 0;
    for(;ind > 0; ind -= (ind & -ind)){
        res += tree[ind];
    }
    return res;
}
void push(int v){
    t[2*v] += lazy[v];
    t[2*v + 1] += lazy[v];
    lazy[2*v] += lazy[v];
    lazy[2*v + 1] += lazy[v];
    lazy[v] = 0;
}

void build(int v, int l, int r){
    if(l == r){
        t[v] = -INF;
    }else{
        int m = (l + r)  / 2;
        build(2*v, l, m);
        build(2*v + 1, m + 1, r);
        t[v] = -INF;
    }
}

void upd1(int v, int tl, int tr, int pos, ll val){
    if(tl == tr){
        t[v] = val;
    }else{
        push(v);
        int m = (tl + tr) / 2;
        if(pos <= m)
            upd1(2*v, tl, m, pos, val);
        else upd1(2*v + 1, m + 1, tr, pos, val);
        t[v] = max(t[2*v], t[2*v + 1]);
    }
}

void upd2(int v, int tl, int tr, int l, int r, ll val){
    if(l > r) return;
    if(tl == l && tr == r){
        t[v] += val;
        lazy[v] += val;
    }else{
        push(v);
        int m = (tl + tr) / 2;
        upd2(2*v, tl, m, l, min(m, r), val);
        upd2(2*v + 1, m + 1, tr, max(m + 1, l), r, val);
        t[v] = max(t[2*v], t[2*v + 1]);
    }
}

ll qu(int v, int tl, int tr, int l, int r){
    if(l > r)
        return -INF;
    if(tl == l && tr == r){
        return t[v];
    }else{
        push(v);
        int tm = (tl + tr) / 2;
        ll ans1 = qu(2*v, tl, tm, l, min(r, tm)), ans2 = qu(2*v + 1, tm + 1, tr, max(l, tm + 1), r);
        return max(ans1, ans2);
    }
}

void upd(int ind, ll val){
    for(; ind <= n; ind += (ind & -ind))
        tree[ind] += val;
}

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

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n>>m;

    for(int i = 0; i < m; i++){
        ll l, r, a;
        cin>>l>>r>>a;
        rem[r].push_back({l, a});
        upd(l, a);
    }
    ll ans = 0;
    build(1, 1, n);
    for(int i = 1; i <= n; i++){
        dp[i] = -INF;
    }
    for(int i = 1; i <= n; i++){
        ll a = get(i);
        ll b = max(0LL, qu(1, 1, n, 1, i - 1));
        dp[i] = max(dp[i], a + b);
        ans = max(ans, dp[i]);
        for(auto j: rem[i]){
            upd(j.ff, -j.ss);
            upd2(1, 1, n, j.ff, n, j.ss);
        }
        upd1(1, 1, n, i, dp[i] - get(i));
    }
    cout<<ans<<endl;

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 30336
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        long lengths[] = new long[n];
        for(int i = 0; i < n; ++i) {
            lengths[i] = s.nextInt();
        }
        int count =0;
        for(int i = 0; i < n; ++i) {
            for(int j = i+1; j < n ; ++j) {
                for(int k = j+1; k < n; ++k) {
                    if(lengths[i] == lengths[j] || lengths[i] == lengths[k] || lengths[j] == lengths[k])
                        continue;
                    if(lengths[i] + lengths[j] > lengths [k] &&
                            lengths[i] + lengths[k] > lengths[j] &&
                            lengths[k] + lengths[j] > lengths[i])
                        count++;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 36832
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define REP(i,n) for(int i=0; i<n; i++)
#define REP_R(i,n,m) for(int i=m; i<n; i++)
#define MAX 100

int N;
ll a[3001];
ll sum = 0;

int main() {
  cin >> N;
  REP(i,N) {
    ll a;
    cin >> a;
    sum += a-1;
  }
  cout << sum << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int k[n];
  int a[n][m];
  int like[m] = {};
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> k[i];
    for (j = 0; j < k[i]; j++) {
      cin >> a[i][j];
      like[a[i][j] - 1]++;
    }
  }

  int count = 0;
  for (i = 0; i < m; i++) {
    if (like[i] == n) {
      count++;
    }
  }

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


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

ll rec(ll n){
  if(n==1) return 1;
  return rec(n/2)*2 + 1;
}
int main(){
  ll h;
  cin >> h;
  cout << rec(h) << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
const ll M = 998244353;
 
vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main(){
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    ll N, A, B, K; cin >> N >> A >> B >> K;
    ll ans = 0;
    rep(i, 0, N+1){
        ll a = i;
        if((K-a*A)%B == 0){
            ll b = (K - a*A)/B;
            if(0 <= b&&b <= N){
                //prt(a); prt(" "); prtl(b);
                //prtl(comb(N, a)*comb(N, b));
                ans += comb(N, a)*comb(N, b);
                ans %= M;
            }
        }
    }
    prtl(ans);
}

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

using namespace std;

#define mod 1000000007
// #define mod1 9982
#define int  long long int
#define pii pair<int,int>
#define vpii vector<pii>
#define vi vector<int>
#define fi first
#define se second
#define psb push_back
#define ppb pop_back
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define endl "\n"

const int maxn=2e5+5;

void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int i=0,j=n-1;
        
    int cnt=0;
    while(i<=j)
    {
        while(i<=j && s[i]=='R')
            i++;
        while(j>=i && s[j]=='W')
            j--;
        if(i<=j)
            cnt++;
        i++;
        j--;
    }
    cout<<cnt<<endl;

}

int32_t main()
{
    fio;
    int t;
    // cin>>t;
    t=1;
    while(t--)
        solve(); 
}

/*
./a.out <input.txt > output.txt
*/


Measured memory_bytes: 3788
#include <iostream>
#include <cstdio>
using namespace std;

int main(){
    long long n;
    cin >> n;

    long long x[n];
    for(long long i = 0; i < n; i++) cin >> x[i];

    long long minv = 1e9;

    for(long long i = -1000; i <= 1000; i++){
        long long sum = 0;
        for(long long j = 0; j < n; j++){
            sum += (x[j]-i)*(x[j]-i);
        }
        minv = min(minv, sum);
    }
    cout << minv << endl;
    return 0;
}

Measured memory_bytes: 3544
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
void read(int &x){
	char ch;bool ok;
	for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
	for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=1e5+10;bool flag;
int n,m,x[maxn*4],y[maxn*4],z[maxn*4],mp[4][maxn];
int f[maxn*4],w[maxn*4],tot,ans,ans1,s[2],ss[2];
#define lowbit(i) (i&(-i))
void add(int x){for(rg int i=x;i<=m;i+=lowbit(i))f[i]++;}
int get(int x){int ans=0;for(rg int i=x;i;i-=lowbit(i))ans+=f[i];return ans;}
int main(){
	read(m),n=3;
	for(rg int i=1;i<=n;i++)
		for(rg int j=1;j<=m;j++)
		    x[i+3*j-3]=i&1,y[i+3*j-3]=j&1,z[i+3*j-3]=j;
	for(rg int i=1;i<=n;i++)for(rg int j=1;j<=m;j++)read(mp[i][j]);
	for(rg int i=1;i<=n;i++)
		for(rg int j=1;j<=m;j++){
		    int u=1+z[mp[i][j]]*3-3,v=2+z[mp[i][j]]*3-3,w=3+z[mp[i][j]]*3-3;
			bool ok1=0,ok2=0,ok3=0;
			if(mp[1][j]==u||mp[2][j]==u||mp[3][j]==u)ok1=1;
			if(mp[1][j]==v||mp[2][j]==v||mp[3][j]==v)ok2=1;
			if(mp[1][j]==w||mp[2][j]==w||mp[3][j]==w)ok3=1;
			if(!(ok1&ok2&ok3))flag=1;
			if(((i&1)^x[mp[i][j]])||((j&1)^y[mp[i][j]]))flag=1;
		}
    if(flag){printf("No\n");return 0;}
	for(rg int i=1;i<=m;i+=2)if(mp[1][i]!=1+3*z[mp[1][i]]-3)s[1]^=1;
	for(rg int i=2;i<=m;i+=2)if(mp[1][i]!=1+3*z[mp[1][i]]-3)s[0]^=1;
	for(rg int i=1;i<=m;i+=2)w[++tot]=z[mp[1][i]];
	for(rg int i=1;i<=tot;i++)ans+=i-get(w[i])-1,add(w[i]);
	for(rg int i=1;i<=m;i++)f[i]=0;tot=0;
	for(rg int i=2;i<=m;i+=2)w[++tot]=z[mp[1][i]];
	for(rg int i=1;i<=tot;i++)ans1+=i-get(w[i])-1,add(w[i]);
	s[1]^=(ans1&1),s[0]^=(ans&1);
	//	printf("%d %d %d %d\n",s[0],s[1],ans,ans1);
    if(s[0]||s[1])printf("No\n");
	else puts(s[0]!=s[1]?"No":"Yes");
}


Measured memory_bytes: 7808