akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)
	switch N % 10 {
	case 2, 4, 5, 7, 9:
		fmt.Println("hon")
	case 0, 1, 6, 8:
		fmt.Println("pon")
	case 3:
		fmt.Println("bon")
	}
}


Measured memory_bytes: 1816
def isPrime(n):
  if (n%2 == 0):
    return n == 2
  
  i = 3;
  while(i*i <= n):
    if (n%i == 0):
      return False
    i += 2
  
  return True



x = int(input())
while True:
  if (isPrime(x)):
    print(x)
    break
  x += 1

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s.size()<=3){
		cout<<s<<endl;
		return 0;
	}
	for(int i=0;i<3;i++){
		cout<<s[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const double eps = 1e-6;
const ll MOD = 1000000007;
const ll INF = 1e15;

int main() {
	ll N;
	cin >> N;
	string s;
	cin >> s;
	vector<ll> imos(N + 1);
	for (int i = 0;i < N;i++) {
		if (s[i] == 'W')
			imos[i + 1]++;
		imos[i + 1] += imos[i];
	}
	ll ans = INF;
	for (int i = 0;i < N;i++) {
		ans = min(ans, imos[i] + (N - i - 1) - (imos[N] - imos[i+1]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;
const int mod = 1e5;
const int MAX = 1e6;

int main() {
    int n, m;
    cin >> n >> m;
    vll a(n);
    vll c(n+1,0);
    unordered_map<ll,ll> ct;
    rep(i,n) cin >> a[i];
    ct[0]++;
    REP(i,n+1) {
        c[i] = (c[i-1] + a[i-1]) % m;
        ct[c[i]]++;
    }
    ll ans = 0;
    for (auto pt = ct.begin(); pt != ct.end(); pt++) {
        ll x = pt->second;
        ans += x*(x-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5260
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

string S;

vector<pair<int, int> > ret;

void print() {
	FOR (i, ret.sz)
		cout << ret[i].first << " " << ret[i].second << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> S;
	int N = S.sz;

	bool good = true;
	FOR (i, N - 1)
		if (S[i] != S[N - 2 - i])
			good = false;

	if (!good || S[N - 1] == '1' || (N > 1 && S[N - 2] != '1')) {
		cout << "-1" << endl;
		return 0;
	}
	
	
	ret.clear();
	ret.pb(make_pair(1, 2));
	if (N == 2) {
		print();
		return 0;
	}
	
	int last = 2;
	ffor (i, 1, N / 2 + 1) {
		ret.pb(make_pair(last, i + 2));
		if (S[i] == '1')
			last = i + 2;
	}
	
	ffor (i, N / 2 + 1, N - 1)
		ret.pb(make_pair(last, i + 2));
	
	print();
	return 0;
}

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

int main()
{
  int k,a,b;
  string ans="NG";
  cin >> k >> a >> b ;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      ans="OK";
      break;
      }
  }

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



Measured memory_bytes: 3628
import sys
input = sys.stdin.readline

x,y = list(map(int,input().split()))
dxy = abs(abs(x)-abs(y))
if y-x == -1 * dxy:
    ans = dxy+2
    if x == 0 or y ==0:
        ans -=1    
elif y-x == dxy:
    ans = dxy
else:
    ans = dxy+1
    
print(ans)


Measured memory_bytes: 9108
a,b,c,d=map(int,input().split())
if a<=c<=b<=d:
 print(b-c)
elif c<=a<=d<=b:
 print(d-a)
elif a<=c<=d<=b:
 print(d-c)
elif c<=a<=b<=d:
 print(b-a)
else:
 print(0)

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define PII pair<int,int>
#define INF LONG_MAX
#define ull unsigned long long
#define long long long
#define PIL pair<long,int>
#define M 1000000007
#define endl "\n"

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

}

int main()
{
	fastIO();
    int d,t,s;
    cin>>d>>t>>s;
    float t1 = d/(float)s;
    if(t1<=t)
    cout<<"Yes";
    else
    cout<<"No";
	return 0;
}

Measured memory_bytes: 3608
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	X, Y := sc.nextInt(), sc.nextInt()
	count := 0
	num := X
	count++
	for {
		num *= 2
		if num <= Y {
			count++
		} else {
			break
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b;
	cin>>a>>b;
	ll cnt=1;
	ll ans=0;
	while(cnt<b){
		ans++;
		cnt+=a-1;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3552
#include<iostream>
using namespace std;
const int maxn = 1e5;
long long n, k;
long long sum = 0;
int main()
{
	cin >> n >> k;
	if (k == 0)sum = n*n;
	else {
		for (int i = k + 1; i <= n; i++) {
			sum += (n / i)*(i - k);
			if (n%i >= k)sum +=( n%i - k + 1);
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
W = [input() for i in range(N)]
ans = "Yes"
if sorted(set(W)) != sorted(W):
    ans = "No"
else:
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            ans = "No"
            break
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>

using namespace std;


int main()
{
	long long int n, m, a[2000000],r,g,b,res=0;
	cin >> r>>g>>b>>n;
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			if ((n - r * i - g * j) % b == 0&& (n - r * i - g * j)>=0) {
				res++;
			}
		}
	}
	cout << res;
}


Measured memory_bytes: 384
#include <stdio.h>
#define N  2001001

int B[N],C[N];

void CountingSort(int A[],int B[],int k,int n){
  int i,j;

for(i=0; i<=k; i++){
  C[i] = 0;
 }

     /* C[i] に i の出現数を記録する */
for(j=1; j<=n; j++){
  C[A[j]]++;
           }

     /* C[i] に i 以下の数の出現数を記録する*/
for(i= 1; i<=k; i++){
  C[i] = C[i] + C[i-1];
 }

for(j=n; j>=1; j--){
  B[C[A[j]]] = A[j];
  C[A[j]]--;
 }

for(i=1; i<=n; i++){
  printf("%d",B[i]);
  if(i != n) printf(" ");
 }
printf("\n");

}

int main(){

  int A[N];
  int k=0,n,m, i, j;

  scanf("%d", &m);
for(i=1; i<=m; i++){
  scanf("%d",&A[i]);
  if(k<A[i]) k=A[i];
 }

 CountingSort(A,B,k,m);


  return 0;
}



Measured memory_bytes: 17416
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define scan(x) scanf("%lld",&x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok, flag;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


int main(void) {

  ll a, b, c;
  cin >> a >> b >> c;
  mi = min(mi, abs(b - a) + abs(c - b));
  mi = min(mi, abs(c - a) + abs(b - c));
  mi = min(mi, abs(a - b) + abs(c - a));
  mi = min(mi, abs(c - b) + abs(a - c));
  mi = min(mi, abs(a - c) + abs(b - a));
  mi = min(mi, abs(b - c) + abs(a - b));
  cout << mi << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define llu long long unsigned
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define ull unsigned long long int
#define pii pair<ll,ll>
#define vll vector<ll>
#define vp vector<pii>
#define mp make_pair
#define lb "\n"
#define ins insert
#define fon(i,n) for(int i = 0;i<n;i++)
#define foa(i,a) for(auto i = a.begin();i!=a.end();i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define INF 100000007
#define sz size
#define len length
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
ll i,j=0,k,n,m,t;
cin>>n;
vll a(n),b(n);
rep(i,0,n)
cin>>a[i];
if(n==2)
    cout<<abs(a[0]-a[1]);
else
{
b[0]=0;
b[1]=abs(a[1]-a[0]);
rep(i,2,n)
{
    b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));
}
cout<<b[n-1];
}
return 0;
}


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

using namespace std;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x1 - x2;
  int dy = y1 - y2;

  int x3 = x2 + dy;
  int y3 = y2 - dx;
  int x4 = x3 + dx;
  int y4 = y3 + dy;
  printf("%d %d %d %d\n", x3, y3, x4, y4);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>N;
    long double pi = 3.1415926;
    cout<<fixed<<setprecision(10)<<pi * N * 2<<endl;
}


Measured memory_bytes: 3804
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
l = [input() for _ in range(n)]
print(len(set(l)))


Measured memory_bytes: 35732
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int main() 
{
    ll p;
    cin>>p;
    ll x=100,c=0;
    while(x<p)
    {
        x+=x/100;
        c++;
    }
    cout<<c;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
long N,M;
void solve()
{
    long i,x,y,tag=0,*a=new long[N+1],*b=new long[N+1];
    for (i=0;i<=N;i++)
        a[i]=b[i]=0;
    while(M--)
    {
        cin>>x>>y;
        if (x==1) a[y]=1;
        if (y==N) b[x]=1;
    }
    for (i=2;i<=N;i++)
        if (a[i]&&b[i]) {tag=1;break;}
    if (tag) cout<<"POSSIBLE";
    else cout<<"IMPOSSIBLE";
    cout<<endl;
}
int main()
{
    while(cin>>N>>M)
        solve();
}

Measured memory_bytes: 3328
import java.io.*;
 
public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        String[] cut = input.split(" ");
        int noOne = Integer.parseInt(cut[0]);
        int noTwo = Integer.parseInt(cut[1]);
        int noThree = Integer.parseInt(cut[2]);
        
        if(noOne < noTwo && noTwo < noThree) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 24116
#include <bits/stdc++.h>
#include <unistd.h>
#include <stdio.h>
using namespace std;
typedef long long lli;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define forr(c, n) for (int i = c; i < n; i++)
#define forli(n) for (lli i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())

//FUNCTONS
lli llipower(lli x, lli y)
{
    lli res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
lli llipowerp(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (!a)
        return b;
    return gcd(b % a, a);
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
void printvec(vector<T> inp)
{
    for (int i = 0; i < inp.size(); i++)
    {
        cout << inp[i] << " ";
    }
    cout << endl;
}
template <typename T>
T ceildiv(T x, T y) { return 1 + ((x - 1) / y); }
lli modInverse(lli a, lli m)
{
    lli g = gcd(a, m);
    if (g != 1)
        return -1;
    else
        return llipowerp(a, m - 2, m);
}


int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> votes(n);
    int total=0;
    fori(n){
        cin>>votes[i];
        total+=votes[i];
    }
    sortvec(votes);
    reverse(votes.begin(),votes.end());
    int count=0;
    int minv;
    if(total%(4*m)==0)
        minv = (total / (4 * m));
    else{
        minv=total/(4*m);
        minv++;
    }
    fori(n){
        if(votes[i]>=minv) count++;
    }
    if(count>=m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;






}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
  int a[200],d[200];
  int b,c,i,j,k,tmp,tmp2,count=0;
  scanf("%d %d",&b,&c);
  for(i=0;i<c;i++){
    scanf("%d",&a[i]);
  }
   for(i=0; i<c; ++i){
    for (j=i+1;j<c;++j){
      if(a[i] > a[j]){
        tmp =  a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
  k=0;
  for(i=-5; i<102; ++i){
    for(j=0; j<c; ++j){
      if(i==a[j])count+=1;
    }
    if(count==0){
      d[k]=i;
      k+=1;
    }
    count=0;
  }
  for(i=0; i<k; ++i){
    for (j=i+1;j<k;++j){
  
      if(abs(b-d[i]) > abs(b-d[j])) {
       tmp2 =  d[i];
        d[i] = d[j];
        d[j] = tmp2;
      }
    }
  } 
  printf("%d",d[0]);
    
  return 0;
  }


Measured memory_bytes: 1732
a,l="+<";f,r=print,range(29,-1,-1);f(60451,l,4,0,3);s,t=[a,7,7,7],[a,8,8,8]
for i in r:f(a,3,4,7,*s*i,a,5,7,7,l,0,7,7,l,7,3,7,a,4,4,6);[f(a,3,4,8,*t*j,a,6,8,8,l,1,8,8,l,8,3,8,l,7,8,9,l,9,8,9,*[a,9,9,9]*(i+j),a,2,9,2,*t*j,a,6,8,6)for j in r];f(*s*i,a,5,7,5)

Measured memory_bytes: 9448
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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; }

ll MOD = 1000000007;
ll INF =1<<30;

int main(){
    string s;
    cin >> s;
    cout << s[0]<<s[1] <<s[2] <<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
const int MOD = 1e9 + 7;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> use;
    vector<int> d(k);
    rep(i, k) cin >> d[i];
    sort(d.begin(), d.end());
    int m = 0;
    rep(i, 10)
    {
        if (i != d[m])
            use.push_back(i);
        else
            ++m;
    }
    int ans;
    repr(i,n,100000) {
        int j = i;
        vector<int> value;
        while(j>0) {
            value.push_back(j%10);
            j/=10;
        }
        bool flag = 1;
        rep(j,value.size()) {
            bool flag1 = 0;
            rep(l,use.size()) {
                if (value[j]==use[l]) flag1=1;
            }
            if (!flag1) flag=0;
        }
        if (flag) {
            ans=i;
            break;
        }
    } 
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    vector<pair<int, int> > A(N);
    for(int i = 0; i < N; i++) {
    cin >> A.at(i).first;
    A.at(i).second = i + 1;
    }

    sort(A.begin(),A.end());

    for(int i = 0; i < N; i++) {
        cout << A.at(i).second;
        if (i < N - 1)
        {
            cout << ' ';
        }
        
    }
    cout << endl;




    return 0;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
/*  
- Our collaboration has been a thing of beauty.
- And for those who fear Allah , He will make their path easy. 
*/
bool isUpper(char c)
{
   return (c>=65 && c<97);
}
int main()
{
  string s;
  getline(cin,s);
  int len = s.length();
  if(isUpper(s[0]) && len>1 && !isUpper(s[1]))
           cout<<s[0];
  for(int i =1 ;i<len;++i)
  {
    if(i+1==len)
    {
        if(isUpper(s[i]))
        cout<<s[i];
        else
        {
            break;
        }
        
    }  
    if(isUpper(s[i]) && len>i+1 && !isUpper(s[i+1]) && s[i-1]==' ')
              cout<<s[i];
       
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
 
#define INF (1e10)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}

int N,M;
int ans = 0;

int main()
{
	cin >> N;
	long long a[N];
	long long sum = 0;
	REP(i, N)
	{
		cin >> a[i];
		sum += a[i];
	}

	long long snuke[N];
	long long arai[N+1];
	arai[N] = 0;

	REP(i,N){
		if(i==0){
			snuke[0] = a[0];
			arai[0] = sum - a[0];
		}else{
			snuke[i] = a[i] + snuke[i - 1];
			arai[i] = sum - snuke[i];
		}
	}
	long long m = INF;
	for (int i = 0; i < N - 1;i++){
		long long now = abs(snuke[i] - arai[i]);
		if(now<m){
			m = now;
		}
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 4992
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {
    var s = input[0];

    if ('YAKI' === s.substr(0, 4)) {
        console.log('Yes');
    }
    else {
        console.log('No');
    }

    return 0;
}


Measured memory_bytes: 15180
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> Point;
constexpr double EPS = 1e-6;
const double PI = acos(-1);

Point rotate(Point p, double theta) { return p * exp(1i * theta); }
vector<Point> rotate(vector<Point> ps, double theta) {
    for (auto &p : ps) {
        p = rotate(p, theta);
    }
    return ps;
}

bool ok(const vector<Point> &ps, int h, int w) {
    double xmin = 1e18, xmax = -1e18, ymin = 1e18, ymax = -1e18;
    for (auto &p : ps) {
        xmin = min(xmin, p.real());
        xmax = max(xmax, p.real());
        ymin = min(ymin, p.imag());
        ymax = max(ymax, p.imag());
    }
    double x = xmax - xmin;
    double y = ymax - ymin;
    if (x > y) swap(x, y);
    if (h > w) swap(h, w);
    return x <= h + EPS && y <= w + EPS;
}

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

    int n;
    double h, w, r;
    cin >> n >> h >> w >> r;
    h -= 2 * r, w -= 2 * r;
    if (h < 0 || w < 0) {
        cout << "No" << endl;
        return 0;
    }
    vector<Point> ps;
    for (int i = 0; i < n; i++) {
        double a, b;
        cin >> a >> b;
        ps.emplace_back(a, b);
    }

    bool multi = false;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (ps[i] == ps[j]) continue;
            multi = true;
            double theta = atan((ps[i].imag() - ps[j].imag()) / (ps[i].real() - ps[j].real() + EPS));
            auto qs = rotate(ps, theta);
            if (ok(qs, h, w)) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    if (!multi) {
        cout << "Yes" << endl;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int H : {w, h}) {
                if (ps[i] == ps[j]) continue;
                double theta1 = atan((ps[i].imag() - ps[j].imag()) / (ps[i].real() - ps[j].real() + EPS));
                double c = hypot(ps[i].imag() - ps[j].imag(), ps[i].real() - ps[j].real());
                if (c <= H + EPS) continue;
                double theta2 = PI / 2 - acos(H / c);
                auto qs = rotate(ps, theta2 - theta1);
                if (ok(qs, h, w)) {
                    cout << "Yes" << endl;
                    return 0;
                }
                double theta3 = acos(H / c);
                qs = rotate(ps, theta3 - theta1);
                if (ok(qs, h, w)) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
}



Measured memory_bytes: 3804
#include<iostream>
#include<string>
using namespace std;
string s[1000];
string h;
bool x=true;
int main()
{
	int n;
	cin>>n;
	cin>>s[0];
	for(int i=1;i<n;i++)
	{
	cin>>s[i];
	if(s[i-1][s[i-1].size()-1]!=s[i][0])
	{
		x=false;
	}
}
	if(x==false)
	{
		cout<<"No";
		return 0;
	}
	for(int i=0;i<n;i++)
	for(int j=i+1;j<n;j++)
	{
		if(s[i]==s[j])
		{
			cout<<"No";
			return 0;
		}
	}
cout<<"Yes";
 } 

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
    unsigned short *A,*B;
    
    int C[VMAX+1];
    int n,i,j;
    scanf("%d",&n);
    
    A=malloc(sizeof(short)*n+1);
    B=malloc(sizeof(short)*n+1);
    
    for(i=0;i<=VMAX;i++) C[i] = 0;
    
    for(i=0;i<n;i++){
        scanf("%hu",&A[i+1]);
        C[A[i+1]]++;
    }
    
    for(i=1;i<=VMAX;i++) C[i] = C[i] + C[i-1];
    
    for(j=1;j<=n;j++){
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }
    
    for(i=1;i<=n;i++){
        if(i>1) printf(" ");
        printf("%d",B[i]);
        }
        printf("\n");
        return 0;
}


Measured memory_bytes: 9596
import numpy as np

N = int(input())
xy=[]
ans=0

for i in range(N):
    a=int(input())
    xy.append( [list(map(int,input().split())) for _ in range(a)] )

for i in range(2**N):

    # tfに正直フラグを格納
    tf=[0]*N
    for j in range(N):
        if (i>>j)&1:
            tf[j]=1

    # N人分の整合性確認
    marubatu = 1
    for j in range(N):
        # j番目が不親切なら見る意味なし
        if tf[j]==0:
            continue

        # 正しくなかったらtfの組み合わせおかしい　ので次の組み合わせに移る
        for k in range(len(xy[j])):
            if tf[xy[j][k][0]-1]!=xy[j][k][1]:
                marubatu = 0
                break

    if marubatu == 1:
        ans=max(ans,sum(tf))

print(ans)


Measured memory_bytes: 27144
n=int(input())
abc=[list(map(int,input().split()))  for i in  range(n)]
dp=[[0]*3 for i in range(n)]

for i in range(3):
  dp[0][i]=abc[0][i]


for i in range(n-1):
  #print("i={}日目".format(i+2))
  for j in range(3):
    #print("{}から遷移".format(dp[i][j]))
    for k in range(3):
      if j==k:
        continue
      if dp[i][j]+abc[i+1][k]>=dp[i+1][k]:
        dp[i+1][k]=dp[i][j]+abc[i+1][k]
      #print(dp)
      
print(max(dp[-1]))

Measured memory_bytes: 50268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define hell  1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb   push_back


int main()
{
	ios;
	ll n,q,s=0;
	cin>>n;
	ll a[n+10];
	map<ll,ll> mp;	
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		s+=a[i];
		mp[a[i]]++;
	}
	cin>>q;
	while(q--)
	{
		ll a,b;
		cin>>a>>b;
		s-=a*mp[a];
		s+=b*mp[a];
		mp[b]=mp[b]+mp[a];
		mp[a]=0;
		cout<<s<<endl;
	}
}

Measured memory_bytes: 10344
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  vector<int> p(n);
  vector<ll> c(n);

  REP(i, n) {
    int t;
    cin >> t;
    t--;
    p[i] = t;
  }

  REP(i, n) cin >> c[i];

  ll ans = -LLINF;
  REP(i, n) {
    int n_p = i;
    ll sum = 0, d = -LLINF;
    vector<ll> dp;
    while(dp.size() <= 0 || n_p != i) {
      n_p = p[n_p];
      sum += c[n_p];
      d = max(d, sum);
      dp.push_back(d);
    }

    ll t = 0;
    if(sum > 0 && k / dp.size()) {
      ll t1 = 0, t2 = 0;
      if(k % dp.size()) t1 += dp[k % dp.size() - 1];
      t1 += sum * (k / dp.size());

      t2 += sum * ((k / dp.size()) - 1);
      t2 += dp[dp.size() - 1];
      t = max(t1, t2);
    } else {
      t = dp[min((int)dp.size() - 1, k - 1)];
    }
    ans = max(ans, t);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3764
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	

	
	
	
	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		int x = s.nextInt();
		int y = s.nextInt();
		
		int flag=0;
		for(int i=0;i<=x;i++) {
			if(i*2+(x-i)*4==y) {
				System.out.println("Yes");
				flag=1;
				break;
			}
		}
		if(flag==0) {
			System.out.println("No");
		}
	}
}

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

int main(){
	cin.tie(0);	
	cout.tie(0);	
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	int n = s.length();
	vector<string> moves = {"dream", "dreamer", "erase", "eraser"};
	bool val[n + 1] = {};
	val[0] = 1;
	for(int i = 0;i < n; ++i){
		if(val[i]){
			for(string &move:moves){
				if(i + move.length() <= n && move == s.substr(i, move.length())){
					val[i + move.length()] = 1 ;
				}
			}
		}
	}
	cout << (val[n] ? "YES":"NO") << '\n';
}


Measured memory_bytes: 592
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;


int main() {

	int N;
	cin >> N;

	string s, t;

	cin >> s >> t;

	rep(i, N) {
		cout << s[i] << t[i];
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	
	int St = A+B;
	if(St >= 24){
		St = St - 24;
	}
	
	System.out.println(St);
}
}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
ll l;
cin >> l;
ll l_ans = pow(l,3);
double ans = (double)l_ans/27;

cout << fixed << setprecision(10) << ans << endl;
return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> vector<T> make_vec(size_t n) { return vector<T>(n); }
template<typename T, typename... Args> auto make_vec(size_t n, Args... args) {
    return vector<decltype(make_vec<T>(args...))>(n, make_vec<T>(args...));
}
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U& u, const V... v) {
    for (auto& e : u) fill_v<T>(e, v...);
}

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

    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

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

    auto dist = make_vec<int>(h, w);
    fill_v<int>(dist, -1);
    queue<pair<int, int>> que;
    rep(i, h) rep(j, w) {
        if (s[i][j] == '#') {
            que.emplace(i, j);
            dist[i][j] = 0;
        }
    }
    while (!que.empty()) {
        auto [i, j] = que.front();
        que.pop();
        rep(k, 4) {
            int ni = i + di[k], nj = j + dj[k];
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (dist[ni][nj] >= 0) continue;
            dist[ni][nj] = dist[i][j] + 1;
            que.emplace(ni, nj);
        }
    }
    int ans = 0;
    rep(i, h) rep(j, w) chmax(ans, dist[i][j]);
    cout << ans << '\n';
}


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

int selectionSort(vector<int> &a,int n){
  int sw = 0;
  int i,j,minj;
  
  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(a[j] < a[minj]){
        minj = j;
      }
    }
    swap(a[i],a[minj]);
    if(i!=minj) sw++;
  }
  
  return sw;
}

int main(){
  int n,sw;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  sw = selectionSort(a,n);
  
  rep(i,n){
    if(i!=n-1){
      cout << a[i] << " ";
    }else{
      cout << a[i] << endl;
    }
  }
  
  cout << sw << endl;
  
  return 0;
}


Measured memory_bytes: 3120
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
x=set()
d={}
cnt=0
for i in range(n):
  if s[i] not in x:
    x.add(s[i])
    d[s[i]]=1
  else:
    cnt+=d[s[i]]
    d[s[i]]=d[s[i]]+1
print(cnt)

Measured memory_bytes: 23576
line = list(map(int,input().split()))
n = line[0]
a = line[1]
b = line[2]

nums = []
for num in range(n+1):
  sowa = 0
  count = len(str(num))
  for i in range(count):
    num = str(num)
    sowa += int(num[i])
  if a <= sowa and sowa <= b:
    nums.append(num)
answer = 0
for j in nums:
  answer += int(j)
print(answer)

Measured memory_bytes: 3564
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int h; cin >> h;
	int n; cin >> n;
	vector<int>A(n);
	rep(i, n)cin >> A[i];
	int cnt = 0;
	rep(i, n)cnt += A[i];
	cout << (cnt >= h ? "Yes" : "No") << "\n";


	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n;
  cin >> n;
  int p = 0, ans = 0;
  rep(i, n) {
    int h;
    cin >> h;
    if (p <= h) ans++;
    cmax(p, h);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807/2;
const int MOD = 1000000007;
const int N_MAX = pow(10,2);
const int W_MAX = pow(10,5);

int main() {
  ll N, W; cin >> N >> W;
  ll a[N+1][2]; for(int i=1; i<=N; i++) rep(j, 2) cin >> a[i][j];

  ll dp[N_MAX+1][W_MAX+1] = {};
  for (int i=1; i<=N; i++) for (int j=0; j<=W; j++) {
    if (j>=a[i][0]) dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i][0]]+a[i][1]);
    else dp[i][j] = dp[i-1][j];
  }
  cout << dp[N][W] << endl;
  return 0;
}

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

const long long MOD = 1000000007;

int main() {
    int n;
    long long sum = 0;
    cin >> n;
    vector<long long> a(n);
    vector<long long> b(n+1, 0);
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        b[i+1] = b[i] + a[i];
    }
    for(int i=0; i<(n-1); i++)
    {
        long long tmp = a[i] * ((b[n] - b[i+1]) % MOD);
        sum = (sum + tmp) % MOD;
    }

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



Measured memory_bytes: 6340
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;

void solve(int now, VI& visit, VI& H, VI& maxNeigh, VVI& adja) {
    visit[now] = 1;

    for (int i = 0; i < adja[now].size(); ++i) {
        int nextv = adja[now][i];

        if (visit[nextv] == 0) {
            solve(nextv, visit, H, maxNeigh, adja);
        }

        maxNeigh[nextv] = max(maxNeigh[nextv], H[now]);
        maxNeigh[now] = max(maxNeigh[now], H[nextv]);
    }
}

int main() {
    int N;
    int M;
    cin >> N >> M;

    VI H(N);
    VVI adja(N);
    VI visit(N);
    VI maxNeigh(N);

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

    for (int i = 0; i < M; ++i) {
        int f;
        int t;
        cin >> f >> t;
        --f;
        --t;
        adja[f].push_back(t);
        adja[t].push_back(f);
    }

    for (int i = 0; i < N; ++i) {
        if (visit[i] == 0) {
            solve(i, visit, H, maxNeigh, adja);
        }
    }

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (maxNeigh[i] < H[i]) {
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11972
#include <iostream>
#include <queue>
#define MAX 1000001
using namespace std;
int ans[MAX];
int main() {
    int n;
    cin >> n;

    for(int i=0; i<5; i++) ans[i] = i+1;
    for(int i=5; i<n; i++) ans[i] = -1;

    queue<int> q;
    q.push(0);

    while(!q.empty()) {
        int v = q.front();
        q.pop();

        if(v+1<=n && ans[v]==-1) {
            ans[v]=ans[v-1]+1;
            q.push(v+1);
        }

        int i=6;
        while(v+i<=n) {
            if(ans[v+i-1]==-1) {
                ans[v+i-1] = ans[v-1]+1;
                q.push(v+i);
            }
            i*=6;
        }

        i=9;
        while(v+i<=n) {
            if(ans[v+i-1]==-1) {
                ans[v+i-1] = ans[v-1]+1;
                q.push(v+i);
            }
            i*=9;
        }
    }

    cout << ans[n-1] << endl;

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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 <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int K,Q; cin >> K >> Q;
    VL D(K);
    REP(i,K) cin >> D[i];
    REP(_,Q){
        int N,X,M; cin >> N >> X >> M;
        VI DQ(K);
        LL sum = 0;
        LL cnt = 0;
        REP(i,K){
            if(D[i]%M == 0) DQ[i] = M;
            else DQ[i] = D[i] % M;
            sum += DQ[i];
            if(sum >= M){
                sum -= M;
                cnt++;
            }
        }
        dump(sum)
        dump(cnt)
        LL loop = (N-1) / K;
        LL amari = (N-1) % K;
        dump(loop)
        dump(amari)
        cnt *= loop;
        sum *= loop;
        cnt += sum / M;
        sum %= M;
        dump(sum)
        dump(cnt)

        REP(i,amari){
            sum += DQ[i];
            if(sum >= M){
                sum -= M;
                cnt++;
            }
        }
        X %= M;
        sum += X;
        cnt += sum / M;
        dump(sum)
        dump(cnt)
        cout << N-1-cnt << endl;


    }

}


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

using namespace std;

int main() {
    while (true) {
        int a, b;
        cin >> a >> b;
        if (a == 0 && b == 0) {
            break;
        }
        if (a < b) {
            cout << a << " " << b << endl;
        } else {
            cout << b << " " << a << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)
#define MAX 1000000

int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    set<int> s;
    
    map<int, int> check;
    rep(i, N) {
        for (int j = 2; j*j <= A[i]; j++) {
            if (A[i]%j == 0) {
                check[j]++;
                s.insert(j);
                while(A[i]%j == 0) A[i]/=j;
            }
        }
        if (A[i] > 1) {
            s.insert(A[i]);
            check[A[i]]++;
        }
    }
    bool flag = false;
    int mx = 0;
    vector<int> primes(ALL(s));
    rep(i, primes.size()) {
        chmax(mx, check[primes[i]]);
        if (mx >= N) {
            flag = true;
            break;
        }
    }
    if (flag) cout << "not coprime" << endl;
    else if (mx <= 1) cout << "pairwise coprime" << endl;
    else cout << "setwise coprime" << endl;
}


Measured memory_bytes: 14700
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
  int z;
  if(b==0){
    z=1;
    z%=c;
    return z;
  }
  if(b==1){
    z=a;
    z%=c;
    return z;
  }
  else{
    return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int vec[n];
  string s;
  cin>>s;
  for(int i=0;i<n;i++){
    if(i>=s.size()){
      vec[i]=1;
      continue;
    }
    if(s.at(i)=='1'){
      vec[i]=1;
    }
    if(s.at(i)=='2'){
      vec[i]=2;
    }
    if(s.at(i)=='3'){
      vec[i]=3;
    }
  }
  int ans=0;
  while(n>4000){
    if(n%2==0){
      for(int i=0;i<n/2;i++){
        vec[i]=abs(vec[2*i]-vec[2*i+1]);
      }
      n/=2;
      ans++;
      continue;
    }
    if(n%2==1){
      for(int i=0;i<n-1;i++){
        vec[i]=abs(vec[i]-vec[i+1]);
      }
      n-=1;
      ans++;
      continue;
    }
  }
  while(n>1){
    for(int i=0;i<n-1;i++){
      vec[i]=abs(vec[i]-vec[i+1]);
    }
    n-=1;
  }
  //cout<<ans<<endl;
  cout<<vec[0]<<endl;
}

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

int main() {
  
  string s, t;
  cin >> s >> t;
  int ans = 0;
  
  rep(i,3){
  	if(s.at(i) == t.at(i)) ans++;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  if(a<b) swap(a,b);
  return b? gcd(b,a%b) : a;
}
int lcm(int a,int b){
  int r = gcd(a,b);
  a /= r;
  b /= r;
  return a * b * r;
}
int main(){
  int a;
  cin >> a;
  cout << lcm(a,2) << endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc084/tasks/abc084_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// constexprな素数列挙(エラトステネスの篩)
// https://259-momone.hatenablog.com/entry/2018/05/06/015026
template <int_fast64_t max_N> struct Prime {
    bool sieve[max_N];
    constexpr Prime() : sieve() {
        for (int_fast64_t i = 0; i < max_N; ++i)
            sieve[i] = true;
        sieve[0] = sieve[1] = false;
        for (int_fast64_t i = 2; i < max_N; ++i) {
            for (int_fast64_t j = i * i; j < max_N; j += i)
                sieve[j] = false;
        }
    }
};

const int SZ = 1e5 + 1;
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    constexpr auto p = Prime<SZ>();
    vector<int> cnt(SZ + 1);
    cnt[0] = 0;
    for (int i = 1; i < SZ; i++) {
        cnt[i] = cnt[i - 1];
        if (p.sieve[i] && p.sieve[(i + 1) / 2]) {
            cnt[i]++;
        }
    }
    int Q;
    cin >> Q;
    while (Q--) {
        int l, r;
        cin >> l >> r;
        cout << cnt[r] - cnt[l - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 3988
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
int main() {
	int n;
	vector<long long>li;
	while (cin >> n) {
		if (n == 0)break;
		vector<long long>l;
		long long a;
		for (int i = 0; i < n; i++){
			cin >> a;
			l.push_back(a);
		}
		sort(l.begin(), l.end());
		long long sum = 0;
		int g = l.size();
		for (int i = 1; i < g - 1; i++){
			sum += l[i];
		}
		li.push_back(sum / (g - 2));
	}
	for (long long i : li) {
		cout << i << endl;
	}
	char c;
	cin >> c;
	return 0;
}

Measured memory_bytes: 3032
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

struct data_t {
    int I;
    int X;
    int M;
};

bool fx(data_t a, data_t b) {
    return a.X < b.X;
}

bool fi(data_t a, data_t b) {
    return a.I < b.I;
}

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

    vector<data_t> v;
    int x;
    REP(0, i, N) {
        scanf("%d", &x);
        v.push_back((struct data_t){i, x, 0});
    }

    // sort by X
    sort(v.begin(), v.end(), fx);

    // REP(0, i, N) {
    //     printf("I=%d, X=%d, M=%d\n", v[i].I, v[i].X, v[i].M);
    // }

    REP(0, i, N) {
        if (i < N / 2) {
            v[i].M = v[N / 2].X;
        } else {
            v[i].M = v[N / 2 - 1].X;
        }
    }

    // sort by I
    sort(v.begin(), v.end(), fi);

    // REP(0, i, N) {
    //     printf("I=%d, X=%d, M=%d\n", v[i].I, v[i].X, v[i].M);
    // }

    REP(0, i, N) {
        printf("%d\n", v[i].M);
    }

    return 0;
}


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

int main() {
long long X;
  cin >> X;
  int flag = 0;
  for(long long a = 0;a < 10000;a++){
    if(flag == 0){
    for(long long b = 0;b < a;b++){
      long long A = a * a * a * a * a;
      long long B = b * b * b * b * b;
      if(A - B == X){
       cout << a << " " << b << endl; 
        flag = 1;
        break;
      }else if(A + B == X){
        cout << a << " " << -b << endl; 
        flag = 1;
        break;
      }
    }
    }else{
     break; 
    }
  }
  if(flag == 0)cout << "a" << endl;
}

Measured memory_bytes: 3636