akhauriyash/Code-Regression huggingface dataset:
/*
  AUTHOR:SOURABH
  CREATED:26:10:19
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll n,i,j,sum=0,c1,c2,k;
    string s;
    cin>>s;
    n=s.length();
    fn(i,n)
    {
        if(s[i]=='<')
        {
            c1=0;
            fs(j,i,n)
            {
                if(s[j]==s[i])
                    c1++;
                else
                    break;
            }
            c2=0;
            fs(k,j,n)
            {
                if(s[k]==s[j])
                    c2++;
                else
                    break;
            }
            //cout<<c1<<" "<<c2<<endl;
            sum+=(c1*(c1-1))/2+(c2*(c2-1))/2+max(c1,c2);
            i=k-1;
        }
        else
        {
            c1=0;
            fs(j,i,n)
            {
                if(s[j]==s[i])
                    c1++;
                else
                    break;
            }
            sum+=(c1*(c1+1))/2;
            i=j-1;
        }
    }
    cout<<sum;
    return 0;
}


























Measured memory_bytes: 1172
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

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

    int n;
    string s;
    cin >> n >> s;

    int rnum = 0;
    rep(i, n) {
        if(s[i] == 'R') {
            rnum++;
        }
    }

    int wr = 0;
    rep(i, rnum) {
        if(s[i] == 'W') {
            wr++;
        }
    }

    cout << wr << endl;
}

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

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

        char[] answer = {'a', 'b', 'c'};
        char[] split = s.toCharArray();
        Arrays.sort(split);

        if (Arrays.equals(split, answer)) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  n = 5;
  int ai[n];
  for(int i = 0;i < n;i++){
    cin >> ai[i];
  }
  for(int i = 0;i < n;i++){
    if(ai[i] == 0){
      cout << i + 1;
    }
  }
  return 0;
}

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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int a, b;

	while (cin >> a >> b, b) {
		int d = b - a;

		vi a;
		a.pb(d / 1000);
		d %= 1000;

		a.pb(d / 500);
		d %= 500;
		
		a.pb(d / 100);

		reverse(all(a));

		print(a);
	}
}

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

using namespace std;

const int N=1e5+5,MOD=1e9+7;

typedef long long ll;

int n,c,u,m,z,v,w,k,tc,ans,root[N];

vector<int> g[N];

bool vis[N];

int Find(int u){
    if (root[u]==u)
        return u;
    return root[u]=Find(root[u]);
}

int main() {
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        root[i]=i;
    while(m--){
        scanf("%d%d%d",&u,&v,&z);
        g[--u].push_back(--v);
        g[v].push_back(u);
        int _u=Find(u),_v=Find(v);
        if (_u!=_v)
            root[_u]=_v;
    }
    for(int i=0;i<n;i++)
        if (!vis[Find(i)]){
            vis[Find(i)]=true;
            ans++;
        }
    printf("%d",ans);
}



Measured memory_bytes: 7032
#include <iostream>

int main() {
  const int buildings = 4;
  const int floors = 3;
  const int rooms = 10;
  int persons[buildings][floors][rooms] = {};
  int b;
  int f;
  int r;
  int v;
  int n;
  std::cin >> n;

  for(int i = 0; i < n; ++i) {
    std::cin >> b >> f >> r >> v;
    if(v < 0) {
      persons[b-1][f-1][r-1] += v;
    }
    else {
      persons[b-1][f-1][r-1] += v;
    }
  }

  for(int i = 0; i < buildings; ++i) {
    for(int j = 0; j < floors; ++j) {
      for(int k = 0; k < rooms; ++k) {
        std::cout << " " << persons[i][j][k];
      }
      std::cout << std::endl;
    }
    if(i != buildings-1) {
      for(int j = 0; j < 20; ++j) {
        std::cout << "#";
      }
      std::cout << std::endl;
    }
  }

  return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e18;

signed main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto& y : a)
        cin >> y;
    vector<int> u(n - 1);
    vector<int> v(n - 1);
    for(int i = 0; i < n - 1; ++i){
        cin >> u[i] >> v[i];
        --u[i];
        --v[i];
    }
    vector<vector<int>> edges(n);
    for(int i = 0; i < n - 1; ++i){
        edges[u[i]].push_back(v[i]);
        edges[v[i]].push_back(u[i]);
    }
    vector<int> size(n, 1);

    bitset<5000> flag;
    function<void(int)> siz = [&](int x){
        for(auto& y : edges[x])
            if(!flag[y]){
                flag[y] = 1;
                siz(y);
                size[x] += size[y];
            }
    };
    flag[0] = 1;
    siz(0);
    flag.reset();

    function<vector<vector<ll>>(int)> f = [&](int x){
        vector<vector<ll>> dp(1, vector<ll>(2, INF));
        dp[0][0] = a[x];
        if(a[x] > 0)
            dp[0][1] = a[x];

        int sizesum = 0;
        for(auto& y : edges[x]){
            if(flag[y])
                continue;
            flag[y] = 1;
            auto from = f(y);

            vector<vector<ll>> next(sizesum + size[y] + 1, vector<ll>(2, INF));

            for(int i = 0; i <= sizesum; ++i){
                for(int j = 0; j < size[y]; ++j){
                    next[i + j][0] = min(next[i + j][0], dp[i][0] + from[j][0]);
                    next[i + j][0] = min(next[i + j][0], dp[i][0] + from[j][1]);
                    next[i + j][0] = min(next[i + j][0], dp[i][1] + from[j][0]);
                    next[i + j][0] = min(next[i + j][0], dp[i][1] + from[j][1]);
                    if(a[x] > 0 && from[j][1] != INF)
                        next[i + j][1] = min(next[i + j][1], dp[i][1] + from[j][1]);
                    // 分断が可能なら
                    if(from[j][0] < 0 || from[j][1] != INF){
                        next[i + j + 1][0] = min(next[i + j + 1][0], dp[i][0]);
                        if(a[x] > 0)
                            next[i + j + 1][1] = min(next[i + j + 1][1], dp[i][1]);
                    }
                }
            }
            dp = move(next);
            sizesum += size[y];
        }
        return dp;
    };
    flag[0] = 1;
    auto dp = f(0);
    int ans = 1e9;
    for(int j = 0; j < (int)dp.size(); ++j){
        if(dp[j][0] < 0)
            ans = min(ans, j);
        if(dp[j][1] != INF)
            ans = min(ans, j);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2128
n = int(input())
a = list(map(int,input().split()))
a.sort()
min = a[-1]
j = 0
for i in range(n-1):
	if abs(a[i] - a[-1]//2) <= min:
		min = abs(a[i] - a[-1]//2)
		j = i
L = [a[-1],a[j]]
print(*L)

Measured memory_bytes: 19972
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        var a = int.Parse(Console.ReadLine());
        var b = int.Parse(Console.ReadLine());
        var c = int.Parse(Console.ReadLine());
        var d = int.Parse(Console.ReadLine());
        var e = int.Parse(Console.ReadLine());

        var k = int.Parse(Console.ReadLine());

        var antenaList = new[] { a, b, c, d, e };

        var min = antenaList.Min();
        var max = antenaList.Max();

        if (max - min > k)
        {
            Console.WriteLine(":(");
        }
        else
        {
            Console.WriteLine("Yay!");
        }
    }
}

Measured memory_bytes: 13268
import java.util.*;

public class Main{
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);
        String str = sc.next();

        int mod = (int)1e9+7;
        char arr[] = str.toCharArray();
        int dp[][] = new int[str.length()+1][13];

        dp[0][0]=1;
//        for (int i=0; i<10; i++) dp[0][i]=1;

        for (int i=0; i<str.length(); i++){
            int x = -1;
            if (arr[i]!='?'){
                x = arr[i] - '0';
            }
            for (int j=0; j<10; j++){
                if (x==-1 || x==j){
                    for (int k=0; k<13; k++){
                        int m = (k*10+j)%13;
                        dp[i+1][m] += dp[i][k];
                        dp[i+1][m] %= mod;
                    }
                }
            }
        }

        System.out.println(dp[str.length()][5]);


    }

}

Measured memory_bytes: 33120
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		int a, b;
		a = input.nextInt();
		b = input.nextInt();
		
		if (a < b){
			System.out.println("a < b");
		}
		else if (a > b){
			System.out.println("a > b");
		}
		else {
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26080
def gcd(m: int, n: int):

    if n == 0:
        return m

    return gcd(n, m % n)


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

A.sort(reverse=True)

num = A[0]

for i in range(1, N):

    if A[i] > num:
        big = A[i]
        small = num
    else:
        big = num
        small = A[i]

    num = gcd(big, small)

print(num)


Measured memory_bytes: 14252
N=int(input())
if 1<=N<=9:
  print(N)
elif 1<=N<=99:
  print(9)
elif 100<=N<=999:
  print(9+N-100+1)
elif 1000<=N<=9999:
  print(909)
elif 10000<=N<=99999:
  print(909+N-10000+1)
elif N==100000:
  print(90909)

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

/*int main(){
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(8) << sqrt(pow((x1-x2),2)+pow((y1-y2),2)) << endl;
    return 0;
}

int main(){
    double a,b,c,S,L,h;
    double PI = acos(-1);
    cin >>a>>b>>c;
    S=a*b*sin(c*PI/180.0)/2;
    L=a+b+sqrt(a*a+b*b-2*a*b*cos(c*PI/180.0));
    h=2*S/a;
    cout << fixed << setprecision(8) << S << endl << L << endl << h <<endl;
}*/

int main(){
    int n;
    while(cin >> n&&n!=0){
        double m=0,aa=0;
        vector<int> s(n);
        for(int i=0;i<n;i++){
            cin >> s.at(i);
            m+=s.at(i);
        }
        m=m/n;
        for(int i=0;i<n;i++){
            aa+=pow((s.at(i)-m),2);
        }   
        aa=aa/n;
        cout <<fixed<<setprecision(8)<< sqrt(aa) << endl;
    }
    return 0;
}


Measured memory_bytes: 3272
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
    
struct Node{
    ll cost;
    int parent;  // index of parent node
    int index;   // index in node list
    vector< ll > connect;
};
    
int reach[200001];
vector< ll > p(200001);
    
void dfs(vector<Node> &node, int index){
    
    reach[index] = 1;
    
    for(int i = 0; i < node[index].connect.size(); i++){
        int next_index = node[index].connect[i];
        if(reach[next_index] == 0){
            p[next_index] += p[index];
            dfs(node, next_index);
        }
    }
       
}
    
int main(){
    
    int N, Q;
    cin >> N >> Q;
    
    vector<Node> node(N);
    for(int i = 0; i < N; i++){
        node[i].cost = 0;
        node[i].parent = -1;
        node[i].index = i;
    }
    for(int i = 0; i < N-1; i++){
        ll a, b;
        cin >> a >> b ;
        a --;
        b --;
        node[a].connect.push_back(b);
        //node[b].connect.push_back(a);
    }
    
    for(int i = 0; i < N; i++) p[i] = 0;
    for(int i = 0; i < Q; i++){
        ll a, b;
        cin >> a >> b;
        a --;
        p[a] += b;
    }

    dfs(node, 0);
    for(int i = 0; i < N; i++){
        cout << p[i] << endl;
    }

}

Measured memory_bytes: 28160
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = 0;
		int max = 100001;
		for (int i = 0; i < M; i++) {
			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		}
		sc.close();
		System.out.println(Math.max(max - min + 1, 0));
	}
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

#ifdef LOCAL
#define i64 "%lld"
#else
#define i64 "%I64d"
#endif

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int MOD = 1e9 + 7;
const int N = 444;

int n,c,a[N],b[N];
int pot[N][N], cpot[N][N];

int ans[2][N], now[N];

int add(int a, int b) {
    int res = a+b;
    while (res >= MOD) res -= MOD;
    while (res < 0) res += MOD;
    return res;
}

int mult(int a, int b) {
    return (ll) a * b % MOD;
}

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

    for (int b = 0; b < N; b++) {
        pot[b][0] = 1;
        // pot[b][e] = b^e
        for (int e = 1; e < N; e++) pot[b][e] = mult(pot[b][e-1], b);

        // cpot(b,e) = 0^e + 1^e + 2^e + ... + (b-1)^e
        if (b+1 < N) for (int e = 0; e < N; e++) cpot[b+1][e] = add(cpot[b][e], pot[b][e]);
    }

    cin >> n >> c;
    forn(i,n) cin >> a[i];
    forn(i,n) cin >> b[i];

    int act = 0, nxt = 1;
    ans[act][0] = 1;
    forn(i,n) {
        forn(j,c+1) now[j] = add(cpot[b[i]+1][j], -cpot[a[i]][j]);

        fill(ans[nxt], ans[nxt] + (c+2), 0);
        forn(x,c+1) forn(y,c+1) {
            if (x+y > c) break;
            ans[nxt][x+y] = add(ans[nxt][x+y], mult(ans[act][x], now[y]));
        }
        swap(act,nxt);
    }
    cout << ans[act][c] << endl;

    return 0;
}


Measured memory_bytes: 1792
import math

def main():
    n = int(input())
    dams = list(map(int, input().split()))
    mountains = [0] * n
    left = 0
    # right = 10**9
    right = (max(dams)+1) * 2
    while True:
        center = (left + right) // 2
        if center % 2 == 1:
            center -= 1
        mountains[0] = center
        for i in range(1, n):
            mountains[i] = 2 * dams[i-1] - mountains[i-1]
        temp_dam = (mountains[0] + mountains[-1]) // 2
        if dams[-1] == temp_dam:
            break
        elif dams[-1] < temp_dam:
            right = center
        else:
            left = center
    ans = ' '.join(map(str, mountains))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84068
#include<bits/stdc++.h>
using namespace std;
#define int long long
int N,M;
vector<int>A,B,C;

signed main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>N;A.resize(N);
    for(int i=0;i<N;i++)cin>>A[i];
    cin>>M;
    B.resize(M);C.resize(M);
    for(int i=0;i<M;i++)cin>>B[i];
    for(int i=0;i<M;i++)cin>>C[i];

    sort(A.begin(),A.end());
    vector<int>sum(N);
    for(int i=0;i<N;i++){
        sum[i]=A[i]+(i?sum[i-1]:0);
    }


    for(int i=0;i<M;i++){
        int u=upper_bound(A.begin(),A.end(),B[i])-A.begin();
        int val;
        if(u==0)val=0;
        else val=sum[u-1];
        if(C[i]<=val)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 10180
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47244
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main() {
	int a, b, c,x;
	cin >> a >> b >> c>>x;
	int ans = 0;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (500 * i + 100 * j + 50 * k == x) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int N, Fac[1001] = { 0 };
	long long int count = 1;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		int j = i;
		while (j != 1) {
			for (int k = 2; k <= j; k++) {
				if (j % k == 0) {
					j /= k;
					Fac[k]++;
					break;
				}
			}
		}
	}
	for (int i = 2; i <= N; i++) {
		count *= (Fac[i] + 1);
		count = count % 1000000007;
	}
	cout << count;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var s = ReadText();

            switch (s)
            {
                case "Sunny": return "Cloudy";
                case "Cloudy": return "Rainy";
                case "Rainy": return "Sunny";
                default: return "";
            }
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = unordered_set<int32_t>;
using setstr = unordered_set<string>;
using qint = queue<int32_t>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    string s;
    cin >> s;

    string pattern = "^A[a-z]+C[a-z]+$";
    regex re(pattern);
    if (regex_match(s, re))
        puts("AC");
    else
        puts("WA");
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
using namespace std;

ll x, k, d, ans;
int main() {
	cin >> x >> k >> d;

	x = abs(x);
	ll p = x/d; // 最も近づけるときの移動回数

	if(p >= k) ans = x - (k*d);
	else if(p < k){
		ll a = x - (d*p);
		ll b = x - (d*(p+1));
		b = abs(b);
		// dの移動をp回行った時が最小である
		if(b < a) p++;

		if((k-p)%2 == 0){
			// p回移動した後の残り回数が偶数ならばそれ以降移動しないことと変わらない
			ans = min(a, b);
		}
		else{
			ll c = x - (d*p);
			ans = min(abs(c+d), abs(c-d));
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3208
#include <cstdio>
#include <algorithm>

using namespace std;
const int Max_N(100050);
typedef long long int LL;
typedef pair<int, int> pil;
#define fi first
#define se second
#define mp make_pair

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

int N, A[Max_N], B[Max_N];

LL work_none_11()
{
	LL SumA(0LL), SumB(0LL);
	for (int i = 1;i <= N;++i)
		SumA += A[i], SumB += B[i];
	return min(SumA, SumB);
}

bool done[Max_N];
pil V[Max_N << 1]; 
LL work()
{
	LL Sum(0LL);
	bool ok(false);
	for (int i = 1, M = 0;i <= N;++i)
		V[++M] = mp(A[i], i), V[++M] = mp(B[i], i);
	sort(V + 1, V + 1 + (N << 1));
	for (int i = 1;i <= N;++i)
	{
		if (done[V[i].se])
			ok = true;
		Sum += V[i].fi, done[V[i].se] = true;
	}
	if (ok)
		return Sum;
	LL Ans(0X3F3F3F3F3F3F3F3FLL);
	for (int i = N + 1;i <= 2 * N;++i)
		if (V[i].se == V[N].se)
			Ans = min(Ans, Sum + V[i].fi - V[N - 1].fi);
		else
			Ans = min(Ans, Sum + V[i].fi - V[N].fi);
	return Ans;
}

int main()
{ 
	gi(N);
	for (int i = 1, M = 0;i <= N;++i)
		gi(A[i]), gi(B[i]);
	printf("%lld", min(work_none_11(), work()));
	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    long long ans, i, j, t, neck, N;
    vector< double > T(5);

    cin >> N >> T[0] >> T[1] >> T[2] >> T[3] >> T[4];

    decltype(T)::iterator min = std::min_element(T.begin(), T.end());
    int min_dis = std::distance(std::begin(T), min);
    neck = T[min_dis];

    if (N % neck != 0) ans = N / neck + 1;
    else ans = N / neck;

    cout << ans + 4 << "\n";
}

Measured memory_bytes: 256
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val day = in.readLine()

    System.out.println(
      day match {
        case "MON" => 6
        case "TUE" => 5
        case "WED" => 4
        case "THU" => 3
        case "FRI" => 2
        case "SAT" => 1
        case "SUN" => 7
      }
    )
  }
}


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

int main() {
  int n,m;
  cin>>n>>m;
  
  long long int p[m],y[m];
  vector<tuple<long long int , long long int ,int>> vec;
  
  for(int i=0;i<m;i++){
    cin>>p[i]>>y[i];
    vec.push_back( make_tuple(y[i],p[i],i) );
  }
  
  sort(vec.begin(), vec.end());
  int num[m]={},cnt[n+1]={};
  
  for(int i=0;i<m;i++){
    cnt[get<1>(vec[i])]++;
    num[get<2>(vec[i])]=cnt[get<1>(vec[i])];
  }
  
  for(int i=0;i<m;i++)
    printf("%06lld%06d\n",p[i],num[i]);

}

Measured memory_bytes: 6640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int N,C;

int main(){
    cin>>N>>C;
    vector<vector<P>> v(C,vector<P>(0));
    rep(i,N){
        int s,t,c;
        cin>>s>>t>>c;
        v[c-1].push_back(P(s,t));
    }

    vector<int> cnt(100002,0);
    vector<int> x(100002,0);
    rep(i,C){
        fill(x.begin(),x.end(),0);
        //cout<<i<<endl;
        //rep(j,v[i].size()) cout<<v[i][j].first<<' '<<v[i][j].second<<endl;
        rep(j,v[i].size()){
            x[v[i][j].first]++;
            x[v[i][j].second]--;
        }
        //repn(j,100) cout<<j%10<<' ';cout<<endl;
        //repn(j,100) cout<<x[j]<<' ';cout<<endl;
        for(int j=100000;j>=0;j--){
            if(x[j]==-1){
                x[j]++;
                x[j+1]--;
            }
        }
        //repn(j,100) cout<<j%10<<' ';cout<<endl;
        //repn(j,100) cout<<x[j]<<' ';cout<<endl;
        rep(j,100002){
            cnt[j]+=x[j];
        }
    }

    repn(i,100001){
        cnt[i]+=cnt[i-1];
    }

    int ans=0;
    repn(i,100000) ans=max(ans,cnt[i]);

    cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s, pre, post;
  cin >> s;
  bool rev = false;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      rev = !rev;
      swap(pre, post);
    } else {
      int f;
      char c;
      cin >> f >> c;
      if (f == 1) {
        pre.push_back(c);
      } else {
        post.push_back(c);
      }
    }
  }
  if (rev) reverse(s.begin(), s.end());
  reverse(pre.begin(), pre.end());
  cout << pre << s << post << endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  int p[N];
  rep(i,N) cin >> p[i];
  int ans=0;
  rep(i,N){
    p[i]--;
    if(p[i]==i){
      ans++;
      i++;
    }   
  }
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 640
N = int(input())
s = list(input())
s_new = []

i = 0
s_new.append(s[i])
while True:
    if i + 1 >= N:
        break
    i += 1
    if s[i] != s_new[-1]:
        s_new.append(s[i])

print(len(s_new))


Measured memory_bytes: 4652
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,n;
	cin>>a>>b>>c;
	n=a*100+b*10+c;
	if(n%4==0){
		cout<<"YES";
	}
	else{
		cout<<"NO";
	}
	return 0;
}

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




void solve() {
    int n, k; cin >> n >> k;
    vec a(n);
	rep(i, n){
		cin >> a[i];
		a[i]--;
	}
	map<int, int> m;
	vector<ll> s(n+1, 0);
	rep(i, n){
		s[i+1] = s[i] + a[i];
		s[i+1] %= k;
	}
	int cnt = 0;
	ll res = 0;
	rep(i, n+1){
		if(i >= k){
			m[s[cnt]]--;
			cnt++;
		}
		res += m[s[i]];
		m[s[i]]++;
	}
	cout << res << 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: 18936
#include <bits/stdc++.h>
using namespace std;

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n;
    cin>>n;
    int a[n];
    for(int i = 0;i < n;i++) cin>>a[i];
    int ans = 0;
    for(int i = 1;i < n-1;i++) {
        if(a[i] > min({a[i-1], a[i], a[i+1]}) && a[i] < max({a[i-1], a[i], a[i+1]})) {
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

int main() {
  int h, n; cin >> h >> n;
  vector<int> vec(n);
  for (int i=0; i<n; i++) cin >> vec[i];

  for (int i=0; i<n; i++){
  h -= vec[i];
  }
  
  if(h<=0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 640
arr=[]
from collections import Counter
c=Counter([])
inp=list(map(int,input().split()))
n=inp[0]
x=inp[1]
m=inp[2]
sumi=x
c=Counter([])
c[x]=1
a=(x**2)%m
arr=[x]
z=2
flag=0
sz=1
while 1:
    if c[a]!=0 :
        flag=1
        break
    arr.append(a)
    sz+=1
    c[a]+=1
    a=(a**2%m)
    if sz==n:
        break
if flag==0:
    print (sum(arr))
else:
    ind=arr.index(a)
    s=sum(arr[:ind])
    s1=sum(arr[ind:])
    s+=s1
    l=len(arr)-ind
    n-=len(arr)
    x=n//l
    s+=s1*x
    x=n%l
    s+=sum(arr[ind:ind+x])
    print (s)

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

ll a, b, c, d;
map<ll, ll> H;
ll solve(ll n){
    if (H.count(n)) return H[n];
    ll res = 1e18;
    if ( n <= res / d) res = n*d;
    res = min(res, abs(n - n/2*2) * d + a + solve(n/2));
    res = min(res, abs(n - (n+1)/2*2) * d + a + solve((n+1)/2));
    res = min(res, abs(n - n/3*3) * d + b + solve(n/3));
    res = min(res, abs(n - (n+2)/3*3) * d + b + solve((n+2)/3));
    res = min(res, abs(n - n/5*5) * d + c + solve(n/5));
    res = min(res, abs(n - (n+4)/5*5) * d + c + solve((n+4)/5));
    return H[n] = res;
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

   int T;
   cin >> T;
   FOR(t, T){
       ll n;
       cin >> n;
       cin >> a >> b >> c >> d;
       H.clear(); H[1] = d; H[0] = 0;
       cout << solve(n) << endl;
   }

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 4452
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    k = a[i]
    j = i - 1
    while j >= 0 and a[j] > k:
        a[j+1] = a[j]
        a[j]=k
        j-=1
    print(*a)



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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    deque<int> que;
    int d, x, p;
    for (int i = 0; i < q; ++i) {
        int query;
        cin >> query;
        switch (query) {
            case 0:
                cin >> d >> x;
                if (d == 0) que.push_front(x);
                else que.push_back(x);
                break;
            case 1:
                cin >> p;
                cout << que[p] << endl;
                break;
            case 2:
                cin >> d;
                if (d == 0) que.pop_front();
                else que.pop_back();
                break;
        }
    }
    return 0;
}




Measured memory_bytes: 4528
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

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

using namespace std;
typedef long long int lint;

void AOJ0139()
{
	string snake;
	cin >> snake;
	if (snake[0] != '>') {
		cout << "NA" << endl;
		return;
	}
	//A
	if (snake[1] == '\'') {
		if (snake[2] != '=') {
			cout << "NA" << endl;
			return;
		}
		int eq_count = 0;
		int pos = 2;
		while (snake[pos] == '=') {
			eq_count++;
			pos++;
		}
		if (snake[pos] != '#') {
			cout << "NA" << endl;
			return;
		}
		pos++;
		FOR(i, pos, pos + eq_count) {
			if (snake[i] != '=') {
				cout << "NA" << endl;
				return;
			}
		}
		pos += eq_count;
		if (snake.substr(pos) != "~") {
			cout << "NA" << endl;
			return;
		}
		cout << "A" << endl;
		return;
	}
	//B
	if (snake[1] == '^') {
		int Q_count = 0;
		int pos = 2;
		if (snake.substr(pos, 2) != "Q=") {
			cout << "NA" << endl;
			return;
		}
		while (snake.substr(pos, 2) == "Q=") {
			pos += 2;
		}
		if (snake.substr(pos) != "~~") {
			cout << "NA" << endl;
			return;
		}
		cout << "B" << endl;
		return;
	}
	cout << "NA" << endl;
	return;
}

int main()
{
	int n;
	cin >> n;
	REP(i, n) AOJ0139();

	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
//	cut here before submit 
//	freopen ("testcase.pizza", "r", stdin );
	int d;
	while (scanf ("%d", &d ), d ){
		int n, m;
		scanf ("%d", &n );
		scanf ("%d", &m );
		vector<int> shop (n+1, 0 );
		shop[0] = 0;
		shop[n] = d;
		for (int i = 1; i < n; i++ ){
			scanf ("%d", &shop[i] );
		} // end for
		sort (ALL (shop ) );
		vector<int> order (m, 0 );
		rep (j, m ){
			scanf ("%d", &order[j] );
		} // end rep
		ll res = 0LL;
		rep (j, m ){
			int k = lower_bound (ALL (shop ), order[j] ) - shop.begin();
			ll curr = (ll)min (shop[k] - order[j], order[j] - shop[k-1]);
			res += curr;
		} // end rep
		cout << res << endl;
	} // end loop

	return 0;
}

Measured memory_bytes: 1532
N = int(input())
S = [input() for i in range(N)]

dict = {}

for s in S :
    dict.setdefault(s, 0)
    dict[s] += 1

max_value =  max(dict.values())
ans = sorted([ k for k,v in dict.items() if v == max_value])

for a in ans :
    print(a)

Measured memory_bytes: 38460
unittest
{
	assert( [ "10" ].parse.expand.solve == 9 );
	assert( [ "81" ].parse.expand.solve == 81 );
	assert( [ "271828182" ].parse.expand.solve == 271821169 );
}



import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	foreach_reverse( i; 2 .. n + 1 )
	{
		auto s = sqrt( cast( real ) i );
		if( s % 1 == 0 ) return i;
	}
	
	return 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

int r, p, s;

int opnum(char x) {
    if (x == 's') {
        return (r);
    }
    if (x == 'r') {
        return (p);
    }
    if (x == 'p') {
        return (s);
    }
    return 0;
}
char op(char x) {
    if (x == 's') {
        return ('r');
    }
    if (x == 'r') {
        return ('p');
    }
    if (x == 'p') {
        return ('s');
    }
    return 0;
}

int main() {
    long a, b, n, k, ans = 0;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        if (h[i] >= k) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
# -*- coding:utf-8 -*-

def solve():
    import sys

    N, W = list(map(int, sys.stdin.readline().split()))

    dp = [0 for i in range(W+1)]  # dp[w] := 重さの総和がw以下のときの価値の最大値

    for _ in range(N):
        v, w = list(map(int, sys.stdin.readline().split()))

        for j in range(W+1):
            if j+w <= W:
                dp[j+w] = max(dp[j+w], dp[j]+v)

    print(dp[W])


if __name__ == "__main__":
    solve()



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

//問題文より、入力されるデータの最大個数
#define MAXCOUNT 10000

//素数であるか確認する関数
int check_prime(int number);

int main(void)
{
	//nは入力されるデータの個数を、countは素数の個数を格納
	int i, n, count;
	int number[MAXCOUNT];

	scanf("%d", &n);

	//n個のデータを入力
	for(i = 0; i < n; i++){
		scanf("%d", &number[i]);
	}

	count = 0;
	//入力されたデータ分、素数であるか判定する
	for(i = 0; i < n; i++){
		if(check_prime(number[i])){
			count++;
		}
	}

	//結果を出力
	printf("%d\n", count);

	return 0;
}

//返り値が1ならば素数であり、0ならば素数でない
int check_prime(int number)
{
	//flagが1ならば素数
	int i, sqrt_number;
	int flag;

	//2～√numberまでの数で割り切れるか確認する
	sqrt_number = sqrt(number);

	flag = 1;
	for(i = 2; i <= sqrt_number; i++){
		//割り切れた場合は素数でない
		if(!(number % i)){
			flag = 0;
			break;
		}
	}

	return flag;
}


Measured memory_bytes: 2044
#include <stdio.h>
int a[2000005], b[2000005], flag[2000005] = { 0 };
int main()
{
	int n, i, j, mod;
	long long k;
	scanf("%d %lld", &n, &k);
	for (i = 1; i <= n; i++)
		scanf("%d", &a[i]);//a[i]存下一位
	flag[1] = 0;
	b[1] = a[1];
	i = 1;
	j = 1;
	while (flag[b[j]]==0&&j<=k)
	{
		flag[b[j]] = j;
		b[j+1] = a[b[j]];
		j++;
	}
//	b[j]已经有了
	if (j > k)
	{
		printf("%d", b[k]);
		return 0;
	}
	mod = j - flag[b[j]];
	k = k - flag[b[j]];
	k = k % mod;
	k = k + flag[b[j]];
	printf("%d", b[k]);
}

Measured memory_bytes: 5356
n = gets.to_i
size = n*(n-1)/2
array = []

(1..n).each do |i|
  (i+1..n).each do |j|
    array.push([i,j])
  end
end
tmp = []
if n % 2 == 0
  array.each {|a|
    if a[0] + a[1] == n+1
      tmp.push(a)
    end
  }
else
  array.each {|a|
    if a[0] + a[1] == n
      tmp.push(a)
    end
  }
end

tmp.each {|a|
  array.delete(a)
}

puts array.size
array.each {|a|
  puts "#{a[0]} #{a[1]}"
}


Measured memory_bytes: 2172
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <functional>
using namespace std;

long long N, X, dp[100], dp2[100], sum = 0;

int main() {
	cin >> N >> X;
	dp[0] = 1; for (int i = 1; i <= N; i++) dp[i] = dp[i - 1] * 2 + 3;
	dp2[0] = 1; for (int i = 1; i <= N; i++) dp2[i] = dp2[i - 1] * 2 + 1;

	for (int i = N; i >= 1; i--) {
		if (X <= 1) {
			sum += 0; X = 0;
		}
		else if (X <= 1 + dp[i - 1]) {
			X -= 1;
		}
		else if (X <= 2LL + dp[i - 1]) {
			sum += dp2[i - 1] + 1; X = 0;
		}
		else if (X <= 2LL + 2LL * dp[i - 1]) {
			X -= (2LL + dp[i - 1]);
			sum += dp2[i - 1] + 1;
		}
		else {
			X = 0; sum += dp2[i];
		}
	}
	if (X >= 1) sum += 1;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i=0; i<(int)n; ++i)
typedef pair<int,int> pii;

const int inf = 1<<29;
int r,c,m;
string room[51];
int on[51][51],off[51][51],con[51][51];

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

bool in(int y,int x) {
    if(x < 0 || x >= c) return false;
    if(y < 0 || y >= r) return false;
    if(room[y][x] == '#') return false;
    return true;
}

vector<pii> bfs(int sy,int sx,int gy,int gx) {
    int dist[51][51];
    rep(i,r) rep(j,c) dist[i][j] = -1;
    dist[sy][sx] = 0;
    queue<pii> q; q.push(make_pair(sy,sx));

    while(!q.empty()) {
        pii p = q.front(); q.pop();
        for(int k=0; k<4; ++k) {
            int nx = p.second+dx[k],ny = p.first+dy[k];
            if(!in(ny,nx) || dist[ny][nx] != -1) continue;
            dist[ny][nx] = dist[p.first][p.second]+1;
            q.push(make_pair(ny,nx));
        }
    }

    vector<pii> ret;
    int r = dist[gy][gx],x = gx,y = gy;
    while(true) {
        if(x == sx && y == sy) break;
        ret.push_back(make_pair(y,x));
        for(int k=0; k<4; ++k) {
            int nx = x+dx[k],ny = y+dy[k];
            if(!in(ny,nx) || dist[ny][nx]+1 != dist[y][x]) continue;
            x = nx,y = ny;
            break;
        }
    }
    reverse(ret.begin(), ret.end());
    return ret;
}

int main() {
    cin>>r>>c>>m;
    rep(i,r) cin>>room[i];

    rep(i,r) rep(j,c) cin>>con[i][j];
    rep(i,r) rep(j,c) cin>>on[i][j];
    rep(i,r) rep(j,c) cin>>off[i][j];

    vector<pii> root;
    int a,b,x,y;
    cin>>a>>b;
    root.push_back(make_pair(a,b));
    rep(i,m-1) {
        cin>>x>>y;
        vector<pii> r = bfs(a,b,x,y);
        for(int j=0; j<r.size(); ++j)
            root.push_back(r[j]);
        a=x,b=y;
    }

    vector<int> app[r*c];
    rep(i,r) rep(j,c) app[i*c+j].clear();

    rep(i,root.size()) {
        int y = root[i].first,x = root[i].second;
        app[y*c+x].push_back(i);
    }

    int ans = 0;
    rep(i,r) rep(j,c) {
        vector<int> &v = app[i*c+j];
        if(!v.empty()) ans += on[i][j];
        for(int k=1; k<v.size(); ++k)
            ans += min((v[k]-v[k-1])*con[i][j],on[i][j]+off[i][j]);
        if(!v.empty()) ans += off[i][j];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
public class Tenka1Begginer2019B {
    public static void Main() {
        int N, K;
        string S, ans = "";
        N = int.Parse(System.Console.ReadLine());
        S = System.Console.ReadLine();
        K = int.Parse(System.Console.ReadLine());

        char target = S[K - 1];
        for(int i = 0; i < S.Length; i++) {
            if (S[i] != target) {
                ans += '*';
            } else {
                ans += target;
            }
        }
        System.Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	string s, t;
	
	cin>>s>>t;
	
	t.erase(s.size());
	
	if(s == t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int>x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];
    ll ans=LONG_LONG_MAX;
    rep(a,n)rep(b,n)rep(c,n)rep(d,n){
        int L=x[a],R=x[b],D=y[c],U=y[d];
        if(R<L||U<D)continue;
        int cnt=0;
        rep(v,n){
            if(L<=x[v]&&x[v]<=R&&D<=y[v]&&y[v]<=U)cnt++;
        }
        if(cnt>=k)ans=min(ans,(ll)(R-L)*(U-D));
    }
    cout<<ans<<endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, C; cin >> N >> C;
    vvi D(C+1, vi(C+1)); REP1(i, C) REP1(j, C) cin >> D[i][j];
    vvi c(N+1, vi(N+1)); REP1(i, N) REP1(j, N) cin >> c[i][j];
    vvi color(3, vi(C+1, 0));
    REP1(i, N)
    {
        REP1(j, N)
        {
            if((i+j) % 3 == 1) color[1][c[i][j]]++;
            else if((i+j) % 3 == 2) color[2][c[i][j]]++;
            else color[0][c[i][j]]++;
        }
    }

    int ans = INF;
    REP1(i, C) // % 3 == 0
    {
        REP1(j, C) // 1
        {
            if(i == j) continue;
            REP1(k, C) // 2
            {
                if(i == k || j == k) continue;
                int d = 0;
                REP1(l, C)
                {
                    d += D[l][i] * color[0][l];
                    d += D[l][j] * color[1][l];
                    d += D[l][k] * color[2][l];
                }
                ans = min(ans, d);
            }
        }
    }

    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 1280