akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
	using namespace std;
	#define IOS ios::sync_with_stdio(false), cin.tie(0)
	#define REP(i, n) for (int i = 0; i < n; i++)
	#define FOR(i, a, b) for (int i = a; i < b; i++)
	#define ALL(x) (x).begin(), (x).end()
	#define dump(x) cout << (x) << endl
	#define LMAX 9223372036854775807LL
	#define LMIN -9223372036854775807LL

	using ll = long long;
	template<typename T>
	using vec = vector<T>;
	using P = pair<ll, ll>;

	template <typename A, size_t N, typename T>
	void Fill(A (&array)[N], const T &val){
		fill((T *)array, (T *)(array + N), val);
	}
	
	const ll INF = 1e16;
	const ll MOD = 1e9 + 7;

	//int dx[4] = {1,0,-1,0};
	//int dy[4] = {0,1,0,-1};
	//ll pas[51][52];
	template <class Abel> struct UnionFind {
		vector<ll> par, rank;
		vector<Abel> dif_weight;
		UnionFind(int n = 1, Abel SUM_UNIT = 0){
			par.resize(n);rank.resize(n);dif_weight.resize(n);
			for(int i = 0;i < n;i++){
				par[i] = i;rank[i] = 0;
				dif_weight[i] = SUM_UNIT;
			}
		}
		Abel weight(int i){
			root(i);
			return dif_weight[i];
		}
		bool merge(int x, int y, Abel w) {
			w += dif_weight[x]; w-= dif_weight[y];
			x = root(x), y = root(y);
			if(x == y)return false;
			if(rank[x] < rank[y])swap(x, y), w = -w;
			if(rank[x] == rank[y])++rank[x];
			par[y] = x;
			dif_weight[y] = w;
			return true;
		}
		bool isSame(int x, int y) {
			return root(x) == root(y);
		}
		int root(int x) {
			if(x == par[x])return x;
			else {
				int r = root(par[x]);
				dif_weight[x] += dif_weight[par[x]];
				return par[x] = r;
			}
		}
		Abel dif(int x, int y){
			return dif_weight[y] - dif_weight[x];
		}
	};
	signed main(){
		IOS;
		int n;
		cin >> n;
		vec<ll> p(n);
		REP(i, n)cin >> p[i],p[i]--;
		ll cnt = 0;
		REP(i, n - 1){
			if(i == p[i])swap(p[i],p[i + 1]),cnt++;
		}
		if(p[n - 1] == n - 1)cnt++;
		dump(cnt);
	}

Measured memory_bytes: 1024
import java.io.*;
public class Main {
	
	public static void main(String[] args)throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String[] str =  br.readLine().split(" ");
		
			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[2]);
		
			if(str[1].equals("+")){
				System.out.println(a+b);
			}else if(str[1].equals("-")){
				System.out.println(a-b);
			}else if(str[1].equals("*")){
				System.out.println(a*b);
			}else if(str[1].equals("/")){
				System.out.println(a/b);
			}else if(str[1].equals("?")){
				break;
			}
		
		}
		
	}
}

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

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N, 1);
    for(int i = 0; i < K; ++i) {
        int d; cin >> d;
        while(d--) {
            int a; cin >> a;
            a--;
            A[a] = 0;
        }
    }
    int ans = count(A.begin(), A.end(), 1);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
 
int main() {
    //??\???
    int N[31] = { 0 };
    int i, j;
    for (i = 1; i < 29; i++) {
        scanf("%d", &j);
        N[j] = 1;
    }
    for (i = 1; i < 31; i++) {
        if (N[i] == 0)
            printf("%d\n", i);
    }
    return 0;
}

Measured memory_bytes: 1808
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

l = [0]*n

for i in range(q):
    l[a[i]-1] += 1

for j in range(n):
    if k > q - l[j]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 8688
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

signed main(){
	int i;
	string L;
	cin >> L;
	vector<int> dp1(L.size() + 1, 1), dp2(L.size() + 1, 1);
	for(i = L.size() - 1; i >= 0; i--){
		dp1[i] = MOD(dp1[i + 1] * 3);
		if(L[i] == '0'){
			dp2[i] = dp2[i + 1];
		}
		else{
			dp2[i] = MOD(dp1[i + 1] + 2 * dp2[i + 1]);
		}
	}
	printf("%lld\n", dp2[0]);
	return 0;
}

Measured memory_bytes: 2048
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    const ll INF = 10e9;
    ll N, M, X;
    cin >> N >> M >> X;
    vl C(N);
    vll A(N, vl(M));
    rep(i, N){
        cin >> C[i];
        rep(j, M){
            cin >> A[i][j];
        }
    }
    //参考書の買い方をbit全探索
    ll ans = INF;
    rep(bit, 1<<N){
        ll tmp = 0;
        vl rikai(M, 0);
        rep(i, N){
            if(bit & (1<<i)){
                tmp += C[i];
                rep(j, M){
                    rikai[j] += A[i][j];
                }
            }
        }
        bool f = false;
        rep(i, M){
            if(rikai[i] < X){
                f = true;
                break;
            }
        }
        if(f) continue;
        ans = min(ans, tmp);
    }

    if(ans == INF){
        cout << -1;
    }else{
        cout << ans;
    }
}

Measured memory_bytes: 3640
program main;
var 
    a : QWord;
    i : integer;
    check : boolean;
    final : boolean;
begin
    final := false;
    readln(a);
    while final = false do
        begin
            check := false;
            for i := 2 to a-1 do 
                if (( a mod i ) = 0) then 
                    check := true;
            if check = false then 
                final := true;
            if check = true then 
                inc(a);
        end;
        writeln(a);
end.

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

int nondiv(int p) { // p%x != 0となるxを求める。
    for(int i = 1; i < p; ++i) if(p%i) return i;
}

int main()
{
    int N, K, S;
    scanf("%d %d %d", &N, &K, &S);
    for(int i = 0; i < K; ++i) printf("%d ", S);
    int p = nondiv(S);
    for(int i = K; i < N; ++i) printf("%d ", p);
    printf("\n");
    return 0;
}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace AtCoder_Grand_Contest_034 {
	class Program {
		static void Main(string[] args) {
			var n = Helper<int>.Read(1)[0];
			var wList = Helper<int>.ReadLine();

			var s1 = 0;
			var result = int.MaxValue;
			for (int index = 0; index < n; index++) {

				s1 += wList[index];

				var s2 = 0;
				for (int index2 = index + 1; index2 < n; index2++) {

					s2 += wList[index2];
				}

				var diff = Math.Abs(s1 - s2);

				if (result > diff) {
					result = diff;
				}
			}
			Console.WriteLine(result);
		}
	}

	public static class Helper<T> {
		public static T[] Read(int count) {
			var result = new T[count];
			for (int index = 0; index < count; index++) {
				result[index] = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(Console.ReadLine());
			}
			return result;
		}

		public static T[] ReadLine() {
			var input = Console.ReadLine();
			var inputs = input.Split(' ');
			var result = new T[inputs.Count()];
			for (int index = 0; index < inputs.Count(); index++) {
				result[index] = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(inputs[index]);
			}
			return result;
		}
	}
}


Measured memory_bytes: 15328
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  map<st, int> A;
  int N;
  ci(N);
  ve<st> s(N);
  rep(i, N){
    ci(s.at(i));
    A[s.at(i)]++;
  }
  int M;
  ci(M);
  ve<st> t(M);
  rep(i, M){
    ci(t.at(i));
    A[t.at(i)]--;
  }
  int a = 0;
  each(i, A){
    a = max(a, i.sc);
  }
  co(a);
}


Measured memory_bytes: 256
N=int(input())
P=[]

for i in range(N):
    P.append(int(input()))

P.sort()
ans = sum(P)

if ans%10==0:
    for i in range(N):
        if P[i]%10!=0:
            ans-=P[i]
            break

if ans%10==0:
    print(0)
else:
    print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  
  int oddC = 0;
  for(int i=1; i<=N; i++){
    if((i%2) != 0) oddC++;
  }
  
  double rate = (double)oddC/(double)N;
  printf("%lf",rate);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define mod 1000000007

void solve()
{
    int d;int t;int s;cin>>d>>t>>s;
    int kya=t*s;
    if(kya>=d)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}
int32_t main()
{
    rapido;
    int t;
    //cin>>t;
    t=1;
       while(t--)
       solve();
}

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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 pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	int K, A, B; cin >> K >> A >> B;
	for(int i = A; i <= B; i++){
		if(i % K == 0){
			cout << "OK" << ln; return 0;
		}
	}
	cout << "NG" << ln;
}


Measured memory_bytes: 3612
// AOJ 2709 Dark Room
// 2018.3.31 bal4u

#include <stdio.h>
#include <string.h>

#define QMAX 40000
typedef struct { int t; int s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define INF 0x10101010
int d[18], r[102];
int v[102][102];
int dist[1<<16];

int main()
{
	int N, M, K, i, j, k, s, e, t;

	N = in(), M = in(), K = in();
	memset(r, -1, sizeof(r));
	for (i = 0; i < M; i++) d[i] = in()-1, r[d[i]] = 1<<i;
	for (i = 0; i < N; i++) for (j = 0; j < K; j++) v[i][j] = in()-1;

	memset(dist, INF, sizeof(dist));
	qsize = 0;
	enq(s=(1<<M)-1, 0), dist[s] = 0;
	while (qsize) {
		s = que[0].s, t = que[0].t, deq();
	
		if (dist[s] == INF) continue;
		for (i = 0; i < K; i++) {
			e = 0;
			for (j = 0; j < M; j++) if ((s>>j)&1) {
				k = v[d[j]][i];
				if (r[k] >= 0) e |= r[k];
			}
			if (dist[e] > t+1) dist[e] = t+1, enq(e, t+1);
		}
	}
	printf("%d\n", dist[0]);
	return 0;
}


Measured memory_bytes: 2404
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_map>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 2000000000
typedef long long ll;


ll D[3000][3000],DP[3000][3000][4];

ll smax(ll a,ll b){
    if (a>b) return a;
    else return b;
}

ll smax2(ll *a){
    return smax(smax(a[0],a[1]),smax(a[2],a[3]));
}

int main(){
    int R,C,K;
    cin >> R >> C;
    cin >> K;
    
    REP(i,3000) {
        REP(j,3000){
             D[i][j]=0;
        }
    }
    
    int r,c;
    ll v;
    
    for(int i=0;i<K;i++){
        cin >> r >> c;
        cin >> v;
        D[r-1][c-1] = v;
        //cout << "a" << endl;
    }
    
    
    REP(i,3000) {
        REP(j,3000){
         REP(k,4){
              DP[i][j][k]=0;
         }
        }
    }
    
    //cout << "aa" << endl;

    REP(i,R){
        REP(j,C){
            if (i!=0 && j!=0){
                DP[i][j][0] = smax(smax2(DP[i-1][j]), DP[i][j-1][0]);
                DP[i][j][1] = smax(DP[i][j-1][0] + D[i][j], smax(DP[i][j-1][1],smax2(DP[i-1][j])+D[i][j]));
                DP[i][j][2] = smax(DP[i][j-1][1] + D[i][j], DP[i][j-1][2]);
                DP[i][j][3] = smax(DP[i][j-1][2] + D[i][j], DP[i][j-1][3]);
            }else if (i!=0 && j==0){
                DP[i][j][0] = smax2(DP[i-1][j]);
                DP[i][j][1] = smax2(DP[i-1][j])+D[i][j];
            }else if(i==0 && j!=0){
                DP[i][j][0] = DP[i][j-1][0];
                DP[i][j][1] = smax(DP[i][j-1][0] + D[i][j], DP[i][j-1][1]);
                DP[i][j][2] = smax(DP[i][j-1][1] + D[i][j], DP[i][j-1][2]);
                DP[i][j][3] = smax(DP[i][j-1][2] + D[i][j], DP[i][j-1][3]);
            } else {
                DP[i][j][0] = 0;
                DP[i][j][1] = D[i][j];
            }
        }
    }
    cout << smax2(DP[R-1][C-1]) << endl;
    
}


Measured memory_bytes: 354788
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    size_t N;
    std::cin >> N;

    size_t odd, even;
    odd = even = 0;

    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        if (t & 1) {
            odd++;
        }
        else {
            even++;
        }
    }

    for (;;) {
        auto neweven = 0;
        auto newodd = 0;

        neweven += odd / 2;
        newodd += odd % 2;

        neweven += even / 2;
        neweven += even %2;

        if (neweven + newodd == even + odd) {
            std::cout << "NO" << std::endl;
            return 0;
        }
        if (neweven + newodd == 1) {
            std::cout << "YES" << std::endl;
            return 0;
        }

        odd = newodd;
        even = neweven;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }
typedef pair<int,int> P;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

//Sieve sieve(1e6);
//auto f = sieve.factor(x);


int main(){
  int n;
  cin >> n;
  Sieve sieve(n);
  int ans=0;
  rep(i,n){
    if(i%2==1)continue;
    auto f = sieve.factor(i+1);
    int num = 1;
    for(auto p:f){
      num *= (p.second+1);
    }
    if(num==8){
      //cout << i+1 << endl;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <stack>
#include <iostream>
#include <string>
#include <ctype.h>
#include <cstring>

#define sz(x) ((int)x.size())

using namespace std;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pli;
typedef pair<lli,lli> pll;

int n,k,a[100000];

int main() {
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",a+i);

	int i=0,j=0,ans=1e9;
	for(;j<n;j++) {
		if(j-i+1==k) {
			int lv=max(0,0-a[i]),rv=max(0,a[j]-0);
			ans=min(ans,lv+rv+min(lv,rv));
			i++;
		}
	}
	printf("%d\n",ans);

	return 0;
}


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



int main(){
  int n,m;
  while(true){
    cin >> n >> m;
    if(n+m == 0)break;
    vector<int> vec;
    for(int i=1;i<=n;i++)
      vec.push_back(i);
     
vector<int>::iterator it = vec.begin(); 
    while(vec.size() > 1){
      
      for(int i=1;i < m;i++){
	if(it == vec.end())it = vec.begin();
	it++;
	if(it == vec.end())it = vec.begin();
      }
     
      it = vec.erase(it);
   
    }
    cout << vec[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
package main

import "fmt"

func sumDigits(n int) int {
	var sum int
	for n > 0 {
		sum += n % 10
		n /= 10
	}
	return sum
}

func main() {
	var n int
	fmt.Scan(&n)
	if n%sumDigits(n) == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

vector<P> v1[20];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	int s=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>m;
		for(j=0;j<m;j++){
			cin>>a>>b;
			a--;
			v1[i].push_back(make_pair(a,b));
		}
	}
	bool flag=true;
	for(i=0;i<(1<<n);i++){
		flag=true;
		for(j=0;j<n;j++){
			if((i&(1<<j))==0)continue;
			for(auto node:v1[j]){
				if(i&(1<<node.first))b=1;
				else b=0;
				if(node.second!=b){
					flag=false;
					break;
				}
			}
			if(!flag)break;
		}
		if(flag){
			a=0;
			for(j=0;j<n;j++){
				if(i&(1<<j))a++;
			}
			s=max(s,a);
		}
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,m;
    scanf("%d %d\n",&n,&m);
    int a[n][m],b[m],ans[n];
    int i,j;
    for(i=0;i<=n-1;i++){
        for(j=0;j<=m-1;j++){
            scanf("%d",&a[i][j]);  
        }
    }
    for(j=0;j<=m-1;j++){
        scanf("%d",&b[j]);
    }
    for(i=0;i<=n-1;i++){
        ans[i]=0;
    }
    for(i=0;i<=n-1;i++){
        for(j=0;j<=m-1;j++){
            ans[i]=ans[i]+a[i][j]*b[j];  
        }
    }
    for(i=0;i<=n-1;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}

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

int mod = 1'000'000'007;
map<pair<long long, long long>, long long> mp;

long long func(long long x, long long y){
    if (mp[{x, y}] != 0) return mp[{x, y}];
    if (x < 0 || y < 0) return 0;
    if (x == 0 && y == 0) return 1;
    long long tmp = func(x / 2, y / 2);
    if (x >= 1 && y >= 1) tmp += func((x - 1) / 2, (y - 1) / 2);
    if (x >= 2) tmp += func((x - 2) / 2, y);
    tmp %= mod;
    mp[{x, y}] = tmp;
    return tmp;
}

int main(){
    long long x;
    cin >> x;
    cout << func(x, x) << endl;
}

Measured memory_bytes: 768
# ABC079D - Wall
import sys
input = sys.stdin.readline

def warshall_floyd():
    for k in range(10):
        for i in range(10):
            for j in range(10):
                C[i][j] = min(C[i][j], C[i][k] + C[k][j])
    return C


def main():
    global C
    H, W = tuple(map(int, input().split()))
    C = list(list(map(int, input().split())) for _ in range(10))
    A = tuple(tuple(map(int, input().split())) for _ in range(H))
    warshall_floyd()
    ans = sum(sum(C[i][1] for i in a if i != -1) for a in A)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
while True:
    r = input()
    if r == "0":
        break

    A,B = 0,0
    for i in range(1, len(r)):
        if r[i] == "A":
            A += 1
        else:
            B += 1

    if A == 10 and B < 10:
        A += 1
    elif B == 10 and A < 10:
        B += 1
    elif A > B:
        A += 1
    else:
        B += 1

    print(A, B)


Measured memory_bytes: 5560
#include <stdio.h>
int main(void){
 int h,w;
 int i,j;
 while(1){
     scanf("%d %d",&h,&w);
     if(h == 0 && w == 0)break;
     for(i = 0; i < h;i++){
         for(j = 0;j < w;j++){
             printf("#");
         }
         printf("\n");
     }
     printf("\n");
 }
 return 0;
}



Measured memory_bytes: 2584
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a,T b){a=max(a,b);}
template<typename T> inline void minimize(T &a,T b){a=min(a,b);}
template<typename T> inline bool middle(T a,T b,T c){return b<=a && a<=c;}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
inline void outputVI(VI x){REP(i,SI(x)){cout << three(i," ","") << x[i];}OUT("");}
const int SIZE1=1e6+1000;
const int SIZE2=5010;
const int SIZE3=400;
const int SIZE=SIZE1;
const LL p=7+1e9;
const LL INF=1LL<<60;
const long double EPS=1e-7;
string s;
ut N,M,K,X,L,Y;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE],nums[SIZE],maps[SIZE2][SIZE2],answer=zero;
 
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////////////////////////////////////////////////////////////////////////////////////
void init(){
 	
}
LL solve(){
	cin >> s;
	s[3]='8';
	OUT(s);
	return 0;
}
signed main(){
	solve();
	return 0;
}

Measured memory_bytes: 25084
#include <stdio.h>
#include <vector>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
using vi = vector<int>;

string str;
string stra;
int id = 0;

void pt(vector<int> v){
  for(int r=0;r<v.size();r++){
    cout << v[r];
  }
  cout << endl;
}

vi number(){
  vi res;
  for (;'0'<=stra[id]&&stra[id]<='9'; id++) {
    res.push_back(stra[id] - '0');
  }
  reverse(res.begin(),res.end());
  return res;
}
int solve(){
  stra = str;
  for (int i = 9; i >= 0; i--) {
    id = 0;
    for (int j = 0; j <(int)str.size(); j++) {
      if (str[j] == 'X') {
        stra[j] = i + '0';
      }
    }
    vi a = number();
    if (stra[id] == '+' ) {
      id++;
    }
    vi b = number();

    a.resize(max(b.size() + 1,a.size()+1),0);

    for (int j = 0; j < (int)b.size(); j++) {
      a[j] += b[j];
      if (a[j]>=10) {
        a[j] -= 10;
        a[j+1]++;
      }
    }
    for (int j = b.size(); j < (int)(a.size()-1); j++) {
      if (a[j] >= 10) {
        a[j] -= 10;
        a[j+1]++;
      }
    }


    if(a[a.size()-1]==0){
      a.pop_back();
    }


    if (stra[id] == '=') {
      id++;
    }

    vi c = number();
    // while(a.size()<c.size()){
    //   a.push_back(0);
    // }
    // while(a.size()>c.size()){
    //   c.push_back(0);
    // }
    
    if (a.size() != c.size()) {
      continue;
    }
    int flag = 0;
    for (int j = 0; j < (int)a.size(); j++) {
      if (a[j] == c[j]) {
        flag++;
      }
    }
    if (flag ==(int)a.size()) {
      return i;
    }

  }
  return -1;
}
int main(){
  cin >> str;
  while(str.size()){
  int ans = solve();
  if (ans >= 0) {
    cout << ans << endl;
  } else {
    cout << "NA" << endl;
  }
  str="";
  cin >> str;
}
  return 0;
}



Measured memory_bytes: 3148
import sys
sys.setrecursionlimit(4100000)

N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
c = list(map(int,input().split()))
L = [0] * N

c.sort(reverse = True)

def dfs(x, par, index):
    L[x] = c[index]
    for u in edges[x]:
        if u != par:
            index += 1
            index = dfs(u, x, index)
    return index

dfs(0, -1, 0)

print(sum(L[1:]))
print(*L)

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n;cin>>n;
  ll x;cin>>x;
  ll a[n+10];

  ll ans=0;
  rep(i,0,n){
    cin>>a[i];
    if(a[i]>x){
      ans+=a[i]-x;
      a[i]=x;
    }
  }

  rep(i,0,n-1){
    ll d=a[i]+a[i+1]-x;
    if(d>0){
      ans+=d;

      if(a[i+1]>=d)a[i+1]-=d;
      else {
        a[i]-=(d-a[i+1]);
        a[i+1]=0;
      }

    }

  }

  out(ans);



  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main()
{
  string s;
  cin >> s;
  string ans;
  rep(i, s.size()){
    ans += "x";
  }
  cout << ans << endl;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


int N, p;
ll dp[55][2];

void solve() {
    cin >> N >> p;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    dp[0][0] = 1;
    rep(i, N){
        if(a[i]%2){
            dp[i+1][1] = dp[i][0] + dp[i][1];
            dp[i+1][0] = dp[i][0] + dp[i][1];
        }else{
            dp[i+1][1] = dp[i][1]*2;
            dp[i+1][0] = dp[i][0]*2;
        }
    }

    cout << dp[N][p] << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define bg begin()
#define end end()
#define sz size()
#define vi vector<int>
#define vl vector<long long int>
#define mod 1000000007
int main(){
	fast;
	int n,m,l;
	cin>>n>>m>>l;
	cout<<n+m+l-max({n,m,l});
	return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int int64_t
using namespace std;

const int inf = LLONG_MAX/2;

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	for (char c:s){
		if (c != '?') cout << c;
		else cout << 'D';
	}
	return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll sum = 0;
    rep (i, 1, n + 1) {
        if (i % 3 != 0 && i % 5 != 0) sum += i;
    }
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 3640
import numpy as np

N = int(input())
P = list(map(float, input().split()))
DP = np.zeros(N+2)
DP[0] = 1
for i, p in enumerate(P, 1):
    DP = DP * (1 - p) + np.roll(DP, 1) * p

print(np.sum(DP[N//2 + 1:]))

Measured memory_bytes: 27636
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val x1 = sc.nextInt()
  val y1 = sc.nextInt()
  val x2 = sc.nextInt()
  val y2 = sc.nextInt()

  val a = Math.abs(x1 - x2)
  val b = Math.abs(y1 - y2)

  var x3 = 0
  if (y2 > y1) {
    x3 = x2 - b
  } else {
    x3 = x2 + b
  }
  var y3 = 0
  if (x2 > x1) {
    y3 = y2 + a
  } else {
    y3 = y2 - a
  }

  var x4 = 0
  if (y3 > y2) {
    x4 = x3 - a
  } else {
    x4 = x3 + a
  }
  var y4 = 0
  if (x3 > x2) {
    y4 = y3 + b
  } else {
    y4 = y3 - b
  }

  val ans = IntArray(4) { 0 }
  ans[0] = x3
  ans[1] = y3
  ans[2] = x4
  ans[3] = y4

  println(ans.joinToString(" "))
}


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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;

typedef pair<int, int> ii;

struct book{
    int x, y, val;
}t[N];
int n, m, nums;
vector<ii> pos[5];

bool cmp(ii x, ii y)    {
    return x.fi > y.fi;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m >> nums; n ++; m ++;
    FOR(i, 1, nums)    {
        int x1, x2, y1, y2;
        cin >> x1 >> y1 >> x2 >> y2; x1 ++; y1 ++; x2 ++; y2 ++;
        bool flag = false, flag2 = false;

        if(x1 == 1 || x1 == n || y1 == 1 || y1 == m) flag = true;
        if(x2 == 1 || x2 == n || y2 == 1 || y2 == m) flag2 = true;

        if(flag && flag2)   {
            if(x1 == 1) pos[1].pb(ii(y1, i));
            else if(x1 == n) pos[3].pb(ii(y1, i));
            else if(y1 == 1) pos[4].pb(ii(x1, i));
            else if(y1 == m) pos[2].pb(ii(x1, i));

            if(x2 == 1) pos[1].pb(ii(y2, i));
            else if(x2 == n) pos[3].pb(ii(y2, i));
            else if(y2 == 1) pos[4].pb(ii(x2, i));
            else if(y2 == m) pos[2].pb(ii(x2, i));
        }
    }
    sort(pos[1].begin(), pos[1].end());
    sort(pos[2].begin(), pos[2].end());
    sort(pos[3].begin(), pos[3].end(), cmp);
    sort(pos[4].begin(), pos[4].end(), cmp);
    stack<int> st;
    FOR(i, 1, 4)    {
        for(ii v: pos[i])   {
            if(!st.empty() && st.top() == v.se) st.pop();
            else st.push(v.se);
        }
    }
    set<int> check;
    while(!st.empty())  {
        if(check.find(st.top()) !=  check.end()) {
            cout << "NO"; return 0;
        }
        check.insert(st.top()); st.pop();
    }
    cout << "YES";
}


Measured memory_bytes: 4308
N,K = map(int,input().split())
MOD = 10**9+7

MAXN = N+10
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def ncr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

for i in range(K):
    ans = ncr(N+1-K, i+1) * ncr(K-1,i)
    print(ans%MOD)

Measured memory_bytes: 3572
#include<stdio.h>
int main(){
  char s[1001];
  int i,n1,n2;
  while(fgets(s,1000,stdin)!=NULL){
   int n[1000]={0};
   int sum=0,c=0;
    for(i=0;s[i]!='\0';i++){
      c++;
      if(s[i]=='I')	n[i]=1;
      if(s[i]=='V')	n[i]=5;
      if(s[i]=='X')	n[i]=10;
      if(s[i]=='L')	n[i]=50;
      if(s[i]=='C')	n[i]=100;
      if(s[i]=='D')	n[i]=500;
      if(s[i]=='M')	n[i]=1000;
    }
    n1=n[0];
    for(i=1;i<c;i++){
      n2=n[i];
      if(n1>=n2){
	sum+=n1;
	n1=n2;
      }
      else{
	sum+=n2-n1;
	i++;
	n1=n[i];
      }
    }
    printf("%d\n",sum);
  }
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    LL n, k;cin >> n >> k;
    LL ans = 0LL;
    if(k == 0){
        printf("%lld\n", n*n);
        return 0;
    }
    inc(i, k+1, n+1){
        LL j = i-k;
        LL m = (n+i-1)/i;
        //cout << j << " " << m << " " << m*j << " " << min(j, m*i-n-1) << endl;
        ans += m*j;
        //ans += (m*i-n);
        if(n%i == 0) continue;
        ans -= min(j, m*i-n-1);
        //ans -= ((n+i-1)/i*i-n)-1;
        
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int 		long long
#define ull 		unsigned long long
#define vi 			vector<int>
#define vvi			vector<vi>
#define pb			push_back
#define mii  		map<int, int>
#define pii 		pair<int, int>
#define pq 			priority_queue<int>
#define pqs 		priority_queue<int, vi, greater<int>>
#define mod 		1000000007
#define inf 		1e18
#define ps(x, y) 	fixed<<setprecision(y)<<x
#define w(t)		int t; cin>>t; while(t--)
#define rep(i,a,b)	for(int i = a; i < b; i++)
#define repd(i,a,b)	for(int i = a; i>= b; i--)
int32_t main()
{
	int n, x, m, a;
    cin>>n>>x>>m;
    vector<int> v;
    a = x%m;
    int ans = 0;
    rep(i, 0, n)
    {
        if(find(v.begin(), v.end(), a) != v.end())
            break;
        ans += a;
        v.pb(a);
        a = (a*a)%m;
        if(i == n-1)
        {
            cout<<ans;
            return 0;
        }
    }
    int p = find(v.begin(), v.end(), a) - v.begin();
    int count = 0, s = v.size();
    ans = 0;
    rep(i, 0, p)
    {
        ans += v[i];
        n--;
    }
    a = 0;
    rep(i, p, s)
        a = a+v[i];
    ans += a*(n/(s - p));
    count = n%(s - p);
    int i = p;
    while(count--)
        ans += v[i++];
    cout<<ans;
	return 0;
}

Measured memory_bytes: 3860
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S[] = new String[N];

		for (int i = 0; i < N; i ++) {
			S[i] = sc.next();
		}
		Arrays.sort(S);

		int count[] = new int[N];
		Arrays.fill(count, 1);

		int max = 0;
		for (int i = 1; i < N; i++) {
			if (S[i].equals(S[i-1])) {
				count[i] = count[i-1]+1;
			}
			if (max < count[i]) max = count[i];
		}

		for (int i = 0; i < N; i++) {
			if (count[i] == max) {
				System.out.println(S[i]);
			}
		}
	}
}

Measured memory_bytes: 81700
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, M);
    AIN(ll, A, M);
    FOR(a, A)
    {
        N -= a;
    }
    OUT(max(-1LL, N));
}

Measured memory_bytes: 3696
#include <stdio.h> 
#include <stdlib.h> 
int main(){
 int h; 
int w; 
scanf("%d %d", &h,&w); 
while (h!=0&&w!=0){
 for(int i=0;i<h;i++){
 for(int j=0;j<w;j++){
 if(!i||!j||i==h-1||j==w-1){
 printf("#"); 
 }else{ 
 printf(".");
 }
 }
 puts("");
 } puts("");
 scanf("%d %d", &h,&w);
 } return 0;
 } 


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <list>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int> wcsum(N+10),bcsum(N+10);
    for(int i=0;i<N;i++){
        if(S[i]=='.'){
            wcsum[i+1]=wcsum[i]+1;
            bcsum[i+1]=bcsum[i];
        }
        else{
            wcsum[i+1]=wcsum[i];
            bcsum[i+1]=bcsum[i]+1;
        }
    }
    int mi=N;
    for(int i=0;i<N;i++){
        mi=min(mi,bcsum[i]+wcsum[N]-wcsum[i+1]);
        //cout << bcsum[i]+wcsum[N]-wcsum[i+1] << endl;
    }
    cout << mi << endl;
}

Measured memory_bytes: 2180
n,m = map(int,input().split())
h = list(map(int,input().split()))
used = [False]*n
ans = 0
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1]>h[b-1]:
        used[b-1] = True
    elif h[a-1]<h[b-1]:
        used[a-1] = True
    else:
        used[b-1] = True
        used[a-1] = True
for i in used:
    if not i:
        ans += 1

print(ans) 
        




Measured memory_bytes: 20140
n=int(input())
monsters=[int(i) for i in input().split()]
powers=[[int(i),0] for i in input().split()]
monsters.append(0)
powers.extend([[0,0],[0,0]])

breaks=[]
for i in range(n+1):
  if monsters[i]>powers[i][1]:
    
    if monsters[i]>=sum(powers[i]):
      breaks.append(sum(powers[i]))
    else:
      breaks.append(monsters[i])
      powers[i+1][1]=sum(powers[i])-monsters[i]
                    
  else:
    powers[i+1][1]=powers[i][0]
    breaks.append(monsters[i])
    
print(sum(breaks))
    
    

Measured memory_bytes: 27968
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AEoui
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            String ans = "Three";
            for (int i = 0; i < n; ++i) {
                if (in.next().equals("Y")) {
                    ans = "Four";
                }
            }

            out.println(ans);
        }

    }
}



Measured memory_bytes: 20564
import itertools
import math

n = int(input())
path = []
for i in range(n):
  x, y = map(int, input().split())
  path.append([x, y])

distance = []
visitedPath = list(itertools.permutations(path))
for vp in visitedPath:
  routeDistance = 0
  for i in range(len(vp)-1):
    routeDistance += math.sqrt((vp[i][0]-vp[i+1][0])**2 + (vp[i][1]-vp[i+1][1])**2)
  distance.append(routeDistance)
print(sum(distance)/len(distance))

Measured memory_bytes: 15516
#include<stdio.h>
#include<string.h>
int main()
{
    char s1[10000],s2[10000],s3[10000];
    int l1,l2,l3;
    scanf("%s",s1);
    scanf("%s",s2);
    scanf("%s",s3);
    l1=strlen(s1);
    l2=strlen(s2);
    l3=strlen(s3);
    if(s1[l1-1]==s2[0]&&s2[l2-1]==s3[0])
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;
}


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

#define REP(i,n) for(int i=1; i<=int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
using namespace std;

int main() {
	int n, a, b, res = 0;
	cin >> n >> a >> b;
	REP(i, n) {
		int c = 0, d = i;
		while (d) {
			c += d % 10;
			d /= 10;
		}
		if (a <= c && c <= b) {
			res += i;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
def pin(type=int):
    return map(type,input().split())

N,X =pin()
S = [int(input()) for i in range(N)]
S.sort()

ans=0
#それぞれ一種類のどーなつを作る
X -= sum(S)
#print(X,S)
ans += N
#greedyとして、小さいドーナツを優先的に作るとする
ans+=(X//S[0])
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[400][400];
ll a[400];
ll sum[401];
ll dfs(ll l,ll r){
  if(dp[l][r]>=0)return dp[l][r];
  if(l==r)return dp[l][r]=0;
  ll ret=1000000000000000;
  for(ll i=0;i<r-l;i++){
    ret=min(ret,dfs(l,l+i)+dfs(l+i+1,r)+sum[r+1]-sum[l]);
  }
  return dp[l][r]=ret;
}
int main(){
  ll n;cin>>n;
  for(ll i=0;i<n;i++)fill(dp[i],dp[i]+n,-1);
  sum[0]=0;
  for(ll i=0;i<n;i++){
    cin>>a[i];
    sum[i+1]=sum[i]+a[i];
  }
  cout<<dfs((ll)0,n-1)<<endl;
  //for(ll i=0;i<n;i++)for(ll j=i;j<n;j++)cout<<dp[i][j]<<endl;
}
        

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define nmax 1000005

using namespace std;

const int mod = 1e9+7;

int dp[nmax], sdp[nmax], smdp[nmax];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n; cin >> n;
	
	dp[n-1]=n-1;
	sdp[n-1]=n-1;
	smdp[n-1]=(1ll*(n-1)*(n-1))%mod;
	
	for(int i=n-2;i>=0;i--){
		dp[i]=(1ll*(n-1)*n)%mod;
		
		if(i<n-3){
			dp[i]=(dp[i]+smdp[i+3])%mod;
			dp[i]=(dp[i]-1ll*(i+2)*sdp[i+3])%mod;
			if(dp[i]<0)
				dp[i]+=mod;
		}
		
		sdp[i]=(dp[i]+sdp[i+1])%mod;
		smdp[i]=(1ll*dp[i]*i+smdp[i+1])%mod;
	}
	
	cout << (sdp[0]+1)%mod << endl;
	return 0;
}

Measured memory_bytes: 12032