akhauriyash/Code-Regression huggingface dataset:
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>

using namespace std;

int main()
{
int a,b,c;
int d;

cin >> a >> b >> c;

d = a * b;

if(d <= c){

cout << d;

}else{

cout << c;

}

 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int H, W;
  cin >> H >> W;
  vector<vector<char>> C(H, vector<char>(W));
  rep(i, H)
  {
    rep(j, W)
    {
      cin >> C.at(i).at(j);
    }
  }
  rep(i, H)
  {
    rep(j, W)
    {
      cout << C[i][j];
    }
    cout << endl;
    rep(j, W)
    {
      cout << C[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N, A, B;

int main() {

	cin >> N >> A >> B;

	ll ans = N / (A + B) * A;
	ans += min(N % (A + B), A);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1232

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

#define PRIME_MAX 100000

vector<int> init_prime()
{
	bool is_prime[PRIME_MAX];
	is_prime[0] = false;
	is_prime[1] = false;
	REP(i,2,PRIME_MAX) is_prime[i] = true;
	REP(i,2,PRIME_MAX) {
		if (is_prime[i]) {
			for (int j=i+i; j<PRIME_MAX; j+=i) is_prime[j] = false;
		}
	}

	vector<int> prime;
	rep(i,PRIME_MAX){ if(is_prime[i]){ prime.push_back(i); } }
	
	return prime;
}

int main()
{

	vector<int> prime = init_prime();

	int M;
	double A,B;
	while(cin >> M >> A >> B && M)
	{
		int p, q;
		int max_pq = 0;
		double a_b = A / B;

		rep(i,prime.size())
		{ 

			if(prime[i] > M){ break; }
		
			rep(j,prime.size()) 
			{
				
				if (prime[i] * prime[j] > M){ break; }	

				int pq = prime[i]*prime[j];
				double p_q = (double)prime[i] / prime[j];
				if (pq > max_pq && a_b <= p_q && p_q <= 1.0)
				{
					max_pq = pq;
					p = prime[i];
					q = prime[j];
				}
			}
		}
		cout << p << " " << q << endl;
	}
	return 0;
}

Measured memory_bytes: 1460
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

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

  int n;
  string s;
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  REP(i, c){
    b -= a;
    if(b < 0) break;
    ans++;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

ll power(ll x,ll n){
    if(n==0) return 1;
    ll res=power(x*x%mod,n/2);
    if(n&1) res=res*x%mod;
    return res;
}

int main(){
  int h,w,A,B;
  cin>>h>>w>>A>>B;
  ll a[h+w+1];
  a[0]=1;
  rep(i,1,h+w+1) a[i]=a[i-1]*i%mod;
  ll b[h+w+1];
  b[0]=1;
  rep(i,1,h+w+1) b[i]=power(a[i],1e9+5);
  ll ans=0;
  rep(i,0,h-A){
    ans+=(a[i+B-1]*b[i]%mod*b[B-1]%mod)*(a[h-1-i+w-B-1]*b[h-1-i]%mod*b[w-B-1]%mod)%mod;
    ans%=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

ll hb(ll x){
  ll l=-1,r=32,m;
  while(r-l>1){
    m=(l+r)/2;
    if(x<(1<<m)) r=m;
    else l=m;
  }
  return r;
}

int main(){
  ll n,k,a,b,ka,k2,ans=0;
  ll s[32]={};
  vector<P> v[32];
  cin>>n>>k;
  fr(i,n){
    cin>>a>>b;
    ka=hb(a);
    v[ka].pb(mp(a,b));
    s[ka]+=b;
  }
  ifr(i,32){
    if(i==0){ans=max(ans,s[0]);break;}
    if(1-((k>>(i-1))&1)) continue;
    ka=0;
    fr(j,i) ka+=s[j];
    ans=max(ans,ka);
    ka=1<<(i-1);
    fr(j,v[i].size()){
      k2=hb(v[i][j].ft-ka);
      v[k2].pb(mp(v[i][j].ft-ka,v[i][j].sd));
      s[k2]+=v[i][j].sd;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
	string o, p = "CODEFESTIVAL2016";
	cin >> o;
	int x = 0;
	rep(i, 16) {
		if (o[i] != p[i]) x++;
	}
	cout << x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  map<long long int, long long int> m;
  long long int s;
  cin>>s;
  m[s]=1;int i;
  for( i=2;i<=1000000;i++)
  {
    if(s%2==0)s=s/2;
    else s=3*s+1;
    if(m.find(s)!=m.end())break;
    m[s]=1;
  }
  cout<<i<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#define RE(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define SZ(x) ((int)(x.size()))
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using C = complex<double>;
const double PI = 3.14159265;
const double eps = 1e-8;
const int N = 1e6 +10;
const int M = 1e9 + 7;
const int inf = 1e9+7;
const ll INF = 1e18;
ll pw(ll a, ll b){ll t=1;a%=M;for(;b;b>>=1){if(b&1){t=t*a%M;}a=a*a%M;}return t;}
ll gcd(ll a, ll b){return b?gcd(b, a%b): a;}

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

    int n, m;
    cin>>n>>m;
    if(n==1&&m==0){
        cout<<"0\n";
        return 0;
    }
    vector<int> a(n, -1);
    int x, y;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        x--;
        if(a[x]==-1){
            a[x]=y;
        } else if(a[x]!=y){
            cout<<"-1\n";
            return 0;
        }
    }
    if(a[0]==0){
        if(n==1){
            cout<<"0\n";
        } else {
            cout<<"-1\n";
        }
        return 0;
    }

    if(a[0]==-1){
        a[0]=1;
    }
    for(int i=1;i<n;i++){
        if(a[i]==-1){
            a[i]=0;
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i];
    }
    puts("");
}

/*
#ifdef DEBUG
	cout<<"I Love Co shu Nie [ https://coshunie.com/ ]"
#endif
3 0

*/


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline

def warshall_floyd(d): #隣接行列を入れる
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

if __name__ == "__main__":
    n,e = map(int,readline().split()) #n:頂点数　e:辺の数
    matrix = [[float("inf") for i in range(n)] for j in range(n)]
    lst1 = []
    for i in range(e):
        x,y,w = map(int,readline().split())
        x,y = x-1,y-1
        matrix[x][y] = w
        matrix[y][x] = w
        lst1.append([x,y,w])
    for i in range(n):
        matrix[i][i] = 0
    matrix = warshall_floyd(matrix)

    ans = 0

    #全辺mについて全探索
    for i in range(e):
        flag = True
        for j in range(n):
            for k in range(n):
                if matrix[j][k] == matrix[j][lst1[i][0]] + lst1[i][2] + matrix[lst1[i][1]][k]:
                    flag = False
        if flag:
            ans += 1
    print(ans)



    

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

#define int ll
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  int cur = 0;
  for (int i = 0; i < 2e6; ++i) {
    cur = cur * 10 + 7;
    cur %= k;
    if (cur == 0) {
      cout << i + 1;
      return 0;
    }
  }
  cout << -1;
  return 0;
}


Measured memory_bytes: 3688
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;

public class Main {
	
	public static void update(int[] BIT, int idx, int val) {
		for (; idx < BIT.length; idx += idx & (-idx)) {
			BIT[idx] += val;
		}
	}
	
	public static int query(int[] BIT, int idx) {
		int ans = 0;
		for (; idx > 0; idx -= idx & (-idx)) {
			ans += BIT[idx];
		}
		return ans;
	}
	
    public static void main(String args[] ) throws Exception {
		PrintWriter out = new PrintWriter(System.out);
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] input;
		input = reader.readLine().split(" ");
		int n = Integer.parseInt(input[0]), q = Integer.parseInt(input[1]);
		input = reader.readLine().split(" ");
		int[] c = new int[n + 1];
		for (int i = 0; i < n; i++) {
			c[i + 1] = Integer.parseInt(input[i]);
		}
		List<ArrayList<int[]>> queries = new ArrayList<ArrayList<int[]>>();
		for (int i = 0; i <= n; i++) {
			queries.add(new ArrayList<int[]>());
		}
		for (int i = 0; i < q; i++) {
			input = reader.readLine().split(" ");
			int[] query = new int[3];
			query[0] = Integer.parseInt(input[0]);
			query[1] = Integer.parseInt(input[1]);
			query[2] = i;
			queries.get(query[1]).add(query);
		}
		int[] BIT = new int[n + 1];
		Map<Integer, Integer> map = new HashMap<>();
		int idx = 0;
		int[] ans = new int[q];
		for (int i = 1; i <= n; i++) {
			if (map.containsKey(c[i])) {
				update(BIT, map.get(c[i]), -1);
			}
			map.put(c[i], i);
			update(BIT, i, 1);
			idx = 0;
			while (idx < queries.get(i).size()) {
				ans[queries.get(i).get(idx)[2]] = query(BIT, queries.get(i).get(idx)[1]) - query(BIT, queries.get(i).get(idx)[0] - 1);
				idx++;
			}
		}
		for (int i = 0; i < q; i++) {
			out.println(ans[i]);
		}
		out.flush();
		out.close();
    }
	

}


Measured memory_bytes: 153212
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String s = scanner.next();
			int oneCount = (int) s.chars().filter(x -> x == '1').count();
			int zeroCount = s.length() - oneCount;
			System.out.println(2 * Math.min(oneCount, zeroCount));
		}
	}
}


Measured memory_bytes: 39252
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  double n;
  while(cin>>n){
    if(n<0) break;
    n *= 16;
    if(n==(int)n){
      int num = (int)n;
      vector<int> bit(12);
      REP(i,12){
        bit[i] = num%2;
        num/=2;
      }
      reverse(bit.begin(),bit.end());
      REP(i,8){
        cout<<bit[i];
      }
      putchar('.');
      REP(i,4){
        cout<<bit[8+i];
      }
      putchar('\n');
    }else{
      cout<<"NA"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.IOException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		new Main().run();
	}
	
	public void run() throws NumberFormatException, IOException
	{
		Scanner file = new Scanner(System.in);
		long N = file.nextLong();
		HashSet<Long> factors = new HashSet<Long>();
		for(long i = 2;i*i<=N;i++)
			if(N%i==0){
				factors.add((long) i);
				factors.add(N/i);
			}
		if(N!=1)
			factors.add(N);
		long sum = 0;
		for(long x:factors)
		{
			long M = x-1;
			if(N/M == N%M)
				sum+=M;
		}
		System.out.println(sum);
	}
	
}


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

#define MP make_pair
//#define int long long

#define REP(i, n) for(int i = 0;i <(n); ++i)
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, a, b) for (int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

void add(long long i, string &s, long long &n) {
    long long d = 26 - (s[i]-'a');
    //cout << d << endl;

    if(i == s.size() - 1) {
        n = n%26;
        while(n > 0) {
            s[i]++;
            if(s[i] > 'z') {
                s[i] = 'a';
            }
            n--;
        }
    }

    if(s[i] != 'a' && n > 0 && n >= d) {
        n-=d;
        s[i] = 'a';
    }
}

int32_t main() {
    //cout << (char)('z' - 25) << endl;
    string s;
    long long n;
    cin >> s;
    cin >> n;

    long long size = s.size();
    REP(i, size) {
        if(n == 0)
            break;
        add(i, s, n);
    }
    cout << s << endl;
    return 0;
}


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

template<typename T> inline int chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; }

const int MAXN = 2000;

int n, k, ans = 0x3f3f3f3f;

struct Graph {
    int ver[MAXN + 9 << 1], nxt[MAXN + 9 << 1];
    int head[MAXN + 9], edgecnt = 1;

    inline void AddEdge(int u, int v) {
        ver[++edgecnt] = v, nxt[edgecnt] = head[u], head[u] = edgecnt;
    }
} G;

int d[MAXN + 9], lim;

void Dfs(int u, int fa) {
    for (int i = G.head[u]; i; i = G.nxt[i]) {
        int v = G.ver[i];
        if (v == fa) continue;
        d[v] = d[u] + 1;
        Dfs(v, u);
    }
}

int Update() {
    int res = 0;
    for (int i = 1; i <= n; d[i] = 0, ++i)
        if (d[i] > lim)
            ++res;
    return res;
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        G.AddEdge(u, v), G.AddEdge(v, u);
    }

    if (!(k & 1)) {
        lim = k >> 1;
        for (int i = 1; i <= n; ++i) {
            Dfs(i, 0);
            chkmin(ans, Update());       
        }
    } else {
        lim = k - 1 >> 1;
        for (int i = 2; i <= G.edgecnt; i += 2) {
            int u = G.ver[i ^ 1], v = G.ver[i];
            int res = 0;
            Dfs(u, v); res += Update();
            Dfs(v, u); res += Update();
            chkmin(ans, res);
        }
    }

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

    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */


int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  size_t n;
  string s;
  size_t q;
  cin >> n >> s >> q;
  vector<size_t> query(q);
  cin >> query;

  vector<int64_t> a(n);
  for (size_t i = 0; i < n; ++i) {
    a[i] = s[i] == 'M';
  }
  partial_sum(a.begin(), a.end(), a.begin());

  for (size_t k: query) {
    --k;
    array<int64_t, 3> out = {0, 0, 0};
    for (size_t i = 0; i < n; ++i) {
      if (s[i] == 'D') {
        out[0] += 1;
      } else if (s[i] == 'M') {
        out[1] += out[0];
      } else if (s[i] == 'C') {
        out[2] += out[1];
      }
      if (k < i + 1 && s[i - k] == 'D') {
        out[0] -= 1;
        out[1] -= a[i] - a[i - k];
      }
    }
    cout << out[2] << '\n';
  }

  return EXIT_SUCCESS;
}


Measured memory_bytes: 9244
#include<stdio.h>
#define MAX 100000

int A[MAX],n;
int par(int p, int r){
  int x,i,j,tmp;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;

  return i+1;
}

int main(){
  int i,q;

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

  q=par(0,n-1);
  for(i=0;i<n;i++){
    if(i!=0)printf(" ");
    if(i==q)printf("[");
    printf("%d",A[i]);
    if(i==q)printf("]");

  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2108
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;

public class Main{  
  public static void main(String[] args){   
    Scanner scn = new Scanner(System.in);
    int n = scn.nextInt();
    int m = scn.nextInt();   
    ArrayList<Integer> a = new ArrayList<>();
    for(int i=0; i<n ; i++){
      int k = scn.nextInt();
      int[] b = new int[k];
       for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       }   
    }
    Collections.sort(a);
    ArrayList<Integer> c = new ArrayList<>();
    int count = 0;
    for(int i=1; i<=m  ; i++){
      for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      }
      c.add(count);
      count = 0;
    }
      
    int count2 = 0;
    for(int i=0; i<c.size(); i++){
      if(c.get(i) == n){
        count2 = count2 + 1;
      }
    }
    System.out.println(count2);   
  }  
}


Measured memory_bytes: 38600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;

int main (void) {
  ios::sync_with_stdio(false);cin.tie(0);
  ll n,a,b; cin >> n >> a >> b;
  ll ans = 0;
  ans += n/(a+b)*a;
  n -= n/(a+b)*(a+b);
  ans += min(n,a);
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int k = scanner.nextInt();
		List<Pair>[] list = new List[n];
		for (int i = 0; i < n; i++)
			list[i] = new ArrayList<Pair>();
		while (m-- > 0) {
			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;
			int l = scanner.nextInt();
			list[a].add(new Pair(b, l));
			list[b].add(new Pair(a, l));
		}
		int[] dp = new int[n];
		Arrays.fill(dp, 1 << 25);
		PriorityQueue<Pair> pq = new PriorityQueue<Main.Pair>();
		for (int i = 0; i < k; i++) {
			int s = scanner.nextInt() - 1;
			dp[s] = 0;
			pq.offer(new Pair(0, s));
		}
		while (!pq.isEmpty()) {
			Pair pair = pq.poll();
			int f = pair.f;
			int s = pair.s;
			if (dp[s] < f)
				continue;
			for (Pair p : list[s]) {
				if (dp[p.f] <= f + p.s)
					continue;
				dp[p.f] = f + p.s;
				pq.offer(new Pair(f + p.s, p.f));
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if(dp[i]==0)
				continue;
			for (Pair p : list[i]) {
				if(dp[p.f]==0)
					continue;
				int b = dp[i] + (p.s - Math.abs(dp[i] - dp[p.f]) + 1) / 2;
				ans = Math.max(ans, b);
			}
		}
		System.out.println(ans);
	}

	class Pair implements Comparable<Pair> {
		int f, s;

		public Pair(int f, int s) {
			super();
			this.f = f;
			this.s = s;
		}

		@Override
		public String toString() {
			return "Pair [f=" + f + ", s=" + s + "]";
		}

		@Override
		public int compareTo(Pair o) {
			return f - o.f;
		}

	}
}

Measured memory_bytes: 109060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <limits>
#include <bitset>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

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;
}



signed main() {
    int N,K; cin >> N  >> K;
    int a, b, c, ans = 0;;
    for (int i = 1; i * K / 2 <= N; i++) {
        if (i * K % 2 == 1)continue;

        a = i * K / 2;
        int nMax, nMin;
        nMin = (a) / K+1;
        nMax = (N + a) / K;
        ans += (nMax - nMin + 1) * (nMax - nMin + 1);
        b = nMax * K - a;
        c = nMin * K - a;
        //cout << a << " " << b << " " << c << endl;
        //cout << nMin << " " << nMax << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 2000
#define INF 1000000
#define WHITE 0
#define BLACK 1
int G[N][N],d[N],pi[N],color[N];
int n,k;

void dijkstra(){
  int i,j,u,v;
  int c,mincost;
  for(i=0;i<n;i++){
    d[i]=INF;
    pi[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){ 
    mincost = INF;
    for(i=0;i<n;i++){
      if (color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if (mincost == INF)
      break;
    color[u] = BLACK;
    c++;
    for (v=0;v<n;v++){
      if (color[v] != BLACK && (G[u][v] +d[u])< d[v]){
	d[v] = G[u][v]+d[u];
	pi[v] = u;
      }
    }
    if(c==n)break;
  }
}
  
int main(){
  int i,j,u,c,v;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=INF;
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
	scanf("%d%d",&v,&c);
	G[u][v]=c;
    }
  }
	
  dijkstra();
  for(i=0;i<n;i++){
  printf("%d ",i);
  printf("%d\n",d[i]);
  } 
  return 0;
}

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




int main(){
	int N,Q;
	string S;
	cin>>N>>Q>>S;
	
	int cnt[N+1]={};
	for(int i=0;i<S.size();i++){
		if(i==0)continue;
		if(S[i]=='C'&&S[i-1]=='A')cnt[i+1]=1;
		cnt[i+1]+=cnt[i];
	}
	
	for(int i=0;i<Q;i++){
		int l,r;
		cin>>l>>r;
		int ans = cnt[r]-cnt[l-1];
		if(l!=1){
			if(S[l-1]=='C'&&S[l-2]=='A')ans--;
		}
		cout<<ans<<endl;
	}
		
	
	return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>

using namespace std;
int main(){
	int w,h,x,y;
	int is=0;

	scanf("%d %d %d %d",&w,&h,&x,&y);

	if(x+x==w && y+y==h)is=1;
	printf("%lf %d",(double)w*(double)h*0.5,is);


	return 0;
}

Measured memory_bytes: 256
n=int(input())
s=input()

s=list(map(int,list(s)))

password=[str(i).zfill(3) for i in range(1000)]

cnt=0
can=[]
for word in password:
    w1=int(word[0])
    w2=int(word[1])
    w3=int(word[2])

    i=0
    while i<n-2:
        if s[i]==w1:
            i_1=i
            break
        else:
            i+=1

        if i==n-3 and s[i]!=w1:
            i_1=-1
            break
    
    if i_1==-1:
        continue

    j=i+1
    while j<n-1:
        if s[j]==w2:
            i_2=j
            break
        else:
            j+=1

        if j==n-2 and s[j]!=w2:
            i_2=-1
            break
    
    if i_2==-1:
        continue

    k=j+1
    while k<n:
        if s[k]==w3:
            i_3=k
            break
        else:
            k+=1
        
        if k>=n-1 and s[n-1]!=w3:
            i_3=-1
            break

    if i_3==-1:
        continue
    elif i_1<i_2 and i_2<i_3:
        cnt+=1
        can.append(word)


print(cnt)


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

int main(void){
    // Your code here!
    
	string S, T;
    int a, b;
    string U;
  
    cin >> S >> T;
    cin >> a >> b;
    cin >> U;

    if(U == S){
        a--;
    }
    else{
        b--;
    }

    cout << a << " " << b << endl; 

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#define ld long double
using namespace std;
const int maxn = 100000;
int n,m;
int cnt[maxn+1];
bool red[maxn+1];
int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("input.inp","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> m;
	for (int i=1; i<=n; i++)
		cnt[i]=1;
	memset(red,false,sizeof(red));
	red[1]=true;
	for (int i=1; i<=m; i++)
	{
		int x,y;
		cin >> x >> y;
		cnt[y]++;
		if (red[x]) red[y]=true;
		cnt[x]--;
		if (cnt[x]==0) red[x]=false;
		/*for (int j=1; j<=n; j++)
			cout << red[j] << ' ';
		cout << '\n';*/
	}
	int res=0;
	for (int i=1; i<=n; i++)
		res+=red[i];
	cout << res;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


int main(){
	string s;
	cin >> s;
	int x,y;
	cin >> x >> y;
	vector<int> to_x,to_y;

	int cnt=0,to=0;


	//to_x[0]は必ず正の方向

	for(auto c:s){
		if(c=='F'){
			cnt++;
		}else{
			if(to%2){
				to_y.push_back(cnt);
			}else{
				to_x.push_back(cnt);
			}
			cnt = 0;
			to++;
		}
	}
	if(to%2){
		to_y.push_back(cnt);
	}else{
		to_x.push_back(cnt);
	}

	bitset<16001> A,B;
	A[8000+to_x[0]] = true;
	B[8000] = true;

	for(int i=1;i<to_x.size();i++){
		A = (A<<(to_x[i])) | (A>>(to_x[i]));
	}
	for(int i=0;i<to_y.size();i++){
		B = (B<<(to_y[i])) | (B>>(to_y[i]));
	}

	if(A[8000+x] && B[8000+y]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const llong MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int main() {
	int n, x, y;
	cin >> n >> x >> y;
	VE cnt_vec(n - 1,0);
	REP(i, n) {
		for (int k = i + 1; k < n; ++k) {
			int dist = min(k - i, abs(x-1 - i) + 1 + abs(y-1 - k));
			cnt_vec[dist - 1]++;
		}
	}
	REP(i, n - 1) {
		cout << cnt_vec[i] << endl;
	}
	return 0;
}


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

int main(){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    //N:Xが欲しい都市の数
    //M:Yがほしい都市の数
    //X:Xの座標
    //Y:Yの座標
    vector<int>A(N);
    vector<int>B(M);
    rep(i,N)cin>>A[i];
    rep(i,M)cin>>B[i];
    int XMAX = X;
    int YMIN = Y;
    for(int i = 0; i < N; i++){
        XMAX = max(XMAX, A[i]);
    }
    for(int i = 0; i < M; i++){
        YMIN = min(YMIN, B[i]);
    }
    if(XMAX < YMIN)cout<<"No War"<<endl;
    else cout<<"War"<<endl;
}


Measured memory_bytes: 256
#N=input()
#N,M=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

total=sum(B)

for j in range(N):
  if j+1!=N:
    if A[j]+1==A[j+1]:
      total+=C[A[j]-1]
      
print(total)

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

int main(){
  ll x,y;
  cin>>x>>y;
  
  ll res = x;
  int ans = 0;
  while(res <= y){
    res *= 2;
    ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))

h.sort()
# 必殺技の回数だけ体力の高い敵から倒す
# 最後に残ったやつが0になる攻撃回数を出力する
for i in range(k):
    h.pop()
    if len(h) == 0:
        break
print(0 if len(h) == 0 else sum(h))

Measured memory_bytes: 26020
import java.math.BigInteger
import java.util.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main(args: Array<String>) {
    val s = readLn().toCharArray().toCollection(LinkedList())
    val q = readInt()
    var reversed = false
    for (i in (1..q)) {
        val line = readStrings()
        val op = line[0]
        if (op == "1") {
            reversed = !reversed
        } else {
            var head = (line[1] == "1")
            if (reversed) head = !head
            if (head) {
                s.addFirst(line[2][0])
                //s = line[2] + s
            } else {
                s.addLast(line[2][0])
                //s += line[2]
            }
        }
    }
    //if (reversed) s = s.reversed()
    //println(s)
    var st = s.joinToString(separator = "")
    if (reversed) st = st.reversed()
    println(st)
}


Measured memory_bytes: 79300
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

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

  int M, T, P, R;
  while (true) {
    cin >> M >> T >> P >> R;
    if (M == 0 && T == 0 && P == 0 && R == 0) break;
    //正解数、チームid、経過時間、問題番号、不正解数
    vector<tuple<int, int, int, map<int, int>>> rec(T);
    rep(i, T) get<1>(rec[i]) = i + 1;
    rep(i, R) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;
      if (j == 0) {
        get<0>(rec[t]) += 1;
        get<2>(rec[t]) += m + get<3>(rec[t])[p] * 20;
      } else {
        get<3>(rec[t])[p]++;
      }
    }

    vector<vector<pair<int, int>>> ans(11);
    rep(i, T) {
      int tt = get<2>(rec[i]);
      int id = get<1>(rec[i]);
      ans[get<0>(rec[i])].push_back(make_pair(tt, -id));
    }

    rep(i, 11) sort(all(ans[i]));
    int e = 0;
    rep(i, 11) {
      if (ans[i].size() == 0)
        e++;
      else
        break;
    }
    for (int i = 10; e <= i; i--) {
      for (int j = 0; j < ans[i].size(); j++) {
        cout << -ans[i][j].second;
        if (ans[i][j].first == ans[i][j + 1].first && j + 1 < ans[i].size())
          cout << "=";
        else {
          if (j + 1 != (int)ans[i].size()) cout << ",";
        }
      }
      if (ans[i].size() != 0 && e != i) cout << ",";
    }
    cout << "\n";
  }

  return 0;
}


Measured memory_bytes: 3212
N = int(input())
W = list(map(int, input().split()))
T = 0
best_diff = 0
for t in range(N):
    diff = sum(W[t:]) - sum(W[:t])
    if diff < 0:
        if abs(diff) < best_diff:
            best_diff = abs(diff)
        break
    best_diff = diff
print(best_diff)
    

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define smin(x,y) ((x)=min((x),(y)))
#define smax(x,y) ((x)=max((x),(y)))
#define all(x) x.begin(),x.end()
#define CS ios_base::sync_with_stdio(false);
#define show(x) cerr << #x << " is " << x <<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi; 
int32_t main()
{
	string s; cin>>s;
	for(auto c:s) if(c==',') cout<<' '; else cout<<c;
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }

//相手の出した手に応じて自分の出す手を決める
char select(char h){
    if(h=='r') return 'p';
    if(h=='p') return 's';
    if(h=='s') return 'r';
}

int rsp[3]; 
//自分の出した手に応じて得点を得る
int point(char h){
    if(h=='r') return rsp[0];
    if(h=='s') return rsp[1];
    if(h=='p') return rsp[2];
}

int main(){ 
    int n, k; cin >> n >> k;
    rep(i, 3) cin >> rsp[i];
    string t; cin >> t;

    int res = 0;
    vector<char> his;//出した手
    rep(i, k){
        char c = select(t[i]);
        res += point(c);
        his.push_back(c);
    }
    rept(i, k, n){
        char c = select(t[i]);
        if(his[i-k] == c) his.push_back('?');
        else{
            res += point(c);
            his.push_back(c);
        }
    }
    cout << res << ln;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

int main()
{
    int n, q;
    std::cin >> n >> q;

    std::string s;
    std::cin >> s;

    std::vector<int> pos_ac;
    for (int i = 0; i < s.length() - 1; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            pos_ac.push_back(i);
        }
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        std::cin >> l >> r;
        l--;
        r--;

        auto l_itr = lower_bound(pos_ac.begin(), pos_ac.end(), l);
        auto r_itr = lower_bound(pos_ac.begin(), pos_ac.end(), r);

        int count = r_itr - l_itr;

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


Measured memory_bytes: 1404
#include <stdio.h>
#include <stdlib.h>

int GCD(int a, int b) {
    int r, tmp;
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main() {
    int K, a, b, c, ans = 0;
    scanf("%d", &K);

    for (a = 1; a <= K; a++) {
        for (b = 1; b <= K; b++) {
            for (c = 1; c <= K; c++) {
                ans = ans + GCD(GCD(a, b), c);
            }
        }
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

#define rep(i, n) for (int i=0; i< (n); ++i)
typedef long long ll;
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; }

using namespace std;

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

    set<int> s;

    int a;
    rep(i, n) {
        cin >> a;
        s.insert(a);
        if (s.size() != i+1) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  ll n,a=0;
  cin >> n;
  vector<pair<ll,ll>> v(n);
  rep(i,n)
  cin>> v[i].second >> v[i].first;
  sort(v.begin(),v.end());
  rep(i,n){
      a+=v[i].second;
      if(a>v[i].first){
         cout << "No";
         return 0; 
      }
  }
  cout << "Yes";
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

//文字から数値に変換
int getChar (char ch){
	if( ch == 'A') return 1;
	else if( ch == 'C' ) return 2;
	else if( ch == 'G' ) return 3;
	else if( ch == 'T' ) return 4;
	else return 0;
}

//文字列から数値へ変換してkeyを生成する
long long getKey(char str[]){
	long long sum=0, p=1, i;
	for( i=0; i<strlen(str); i++ ){
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
	long long key, i, h;
	key = getKey(str); //文字列を数値に変換
	for(i=0;; i++){
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h],str) == 0 ) return 1;
		else if( strlen(H[h]) == 0 ) return 0;
	}
	return 0;
}

int insert(char str[]){
	long long key, i, h;
	key = getKey(str); //文字列を数値に変換
	for(i=0;; i++){
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h],str) == 0 ) return 1;
		else if( strlen(H[h]) == 0 ) {
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
	int i, n, h;
	char str[L], com[9];
	for( i=0; i<M; i++) H[i][0] ='\0';
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%s %s", com, str); //より高速な入力 scanfを使用
		
		if (com[0] == 'i' ){
			insert(str);
		}else{
			if ( find(str) ){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 16088
#include<bits/stdc++.h>
#define ll long long
#define forn(i,n) for(ll i=0;i<(n);i++)
#define maxx ((ll)1e6+5)
using namespace std;
int main()
{
  ll n;
  cin>>n;
  set<ll>s;
  int i=1;
  while(1)
  {
  	if(s.count(n)==1){
  	cout<<i;return 0;}
  	s.insert(n);
  	if(n%2==0)
  	n/=2;
  	else
  	n=(3*n+1);
  	i++;
  }
  cout<<i;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define ll long long
using namespace std;

ll A[111111];
ll S[111111];
bool can[111111];

int main() {
    int N;
    cin>>N;
    for(int i=0;i<N;i++) {
        cin>>A[i];
    }
    
    
    sort(A,A+N);
    
    for(int i=0;i<N;i++) {
        S[i]=A[i]+(i>0?S[i-1]:0);
    }
    
    for(int i=N-1;i>=0;i--) {
        if (i == N-1)
            can[i]=true;
        else {
            can[i]=(2*S[i] >= A[i+1]);
        }
    }
    
    for(int i=N-2;i>=0;i--) {
        can[i] &= can[i+1];
    }
    
    
    
    int ans=0;
    for(int i=0;i<N;i++) {
        // A[0]+...+A[i] and A[i+1]...A[N-1]
        
        // 2*(S[i]+A[i+1]+...A[j]) < A[j+1]
        // 2*(S[j]) < A[j+1]
        // 2*S[j] >= A[j+1] for all j >= i
        
        if (can[i])
            ans++;
        
        
    }
    
    
    cout << ans << endl;
    
    
    
    
}

Measured memory_bytes: 1920
#include <stdio.h>

int main(void)
{
	char string[128];
	int number = 0;
	int tmpNum = 0;
	int i;
	
	while( scanf( "%s", string ) != EOF )
	{
		
		for( i = 0; string[i] != '\0'; i++ )
		{
			if( string[i] >= '0' && string[i] <= '9' )
			{
				tmpNum = tmpNum * 10 + (string[i] - '0');
			}
			else
			{
				number += tmpNum;
				tmpNum = 0;
			}
		}
		number += tmpNum;
		tmpNum = 0;
	}
	
	printf("%d\n", number);
	
	return (0);
}

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

int main(void){
	string n,ans="";
	cin >> n;
	for(int i=0;i<n.length();i++){
		ans+=n[n.length()-1-i];
	}

	if(n==ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    string S; cin>>S;
    ll Q; cin>>Q;
    rep(i,Q){
        ll k; cin>>k;
        ll D=0,M=0,DM=0,ans=0;
        rep(i,N){
            if(i-k>=0){
                if(S[i-k]=='D'){
                    --D;
                    DM-=M;
                }
                if(S[i-k]=='M'){
                    --M;
                }
            }
            if(S[i]=='D'){
                ++D;
            }
            if(S[i]=='M'){
                ++M;
                DM+=D;
            }
            if(S[i]=='C'){
                ans+=DM;
            }
        }

        cout<< ans <<"\n";
    }
    
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9 + 7;

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

    string s;
    cin >> s;
    ll n = s.size() + 1;

    vll r, l;
    ll tr = 0, tl = 0;
    if (s[0] == '<') l.push_back(0LL);
    REP(i, n - 1) {
        if (s[i] == '<') {
            tr++;
            if (i && s[i - 1] == '>'){
                l.push_back(tl);
                tl = 0;
            }
        }
        else {
            tl++;
            if (i && s[i - 1] == '<') {
                r.push_back(tr);
                tr = 0;
            }
        }
    }
    if (tr) r.push_back(tr);
    if (tl) l.push_back(tl);
    if (s[n - 2] == '>') r.push_back(0LL);
    ll xr = r.size(), xl = l.size();

    ll res = 0;
    REP(i, xr) {
        ll rr = r[i] * (r[i] + 1) / 2;
        ll ll = l[i] * (l[i] + 1) / 2;
        res += rr + ll;
    }
    REP(i, xr - 1) {
        ll q = min(r[i], l[i + 1]);
        res -= q;
    }
    cout << res << endl;
    return 0;
}

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


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

    int N, M;
    cin >> N >> M;
    int A[N];
    for (auto &a: A) {
        cin >> a;
    }
    sort(A, A + N);
    vector<pair<int, int>> CB;
    for (int i = 0; i < M; ++i) {
        int b, c;
        cin >> b >> c;
        CB.emplace_back(c, b);
    }
    sort(CB.rbegin(), CB.rend());
    long long sum = 0;
    int idx = 0;
    int prev_c;
    for (auto cb: CB) {
        bool change = false;
        for (int i = idx; i < N; ++i) {
            if (cb.first > A[idx]) {
                A[idx] = cb.first;
                cb.second--;
                idx = i + 1;
                if (cb.second == 0) break;
            } else if (cb.second > 0) {
                break;
            }
        }
    }

    for (auto a: A) {
        sum += a;
    }

    cout << sum << '\n';

    return 0;
}


Measured memory_bytes: 1784