akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;


public class Main {
    static int mod = (int) 1e9 + 7;
    static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

    static int n;
    static long k;
    static long a[];
    public static void main(String[] args) {
        FastScanner fs = new FastScanner(System.in);
        n = fs.nextInt();
        k = fs.nextLong();
        a = fs.nextLongArray(n);
        Arrays.sort(a);
        long INF = (long)(1e18)+1;
        long l = -INF;
        long r = INF;
        while(l+1<r) {
            long c = (l+r)/2;
            if(check(c))l=c;
            else r = c;
        }
        System.out.println(l);
    }
    //x未満の組合せがk個未満ならtrue
    static boolean check(long x) {
        long tot = 0;
        for(int i=0;i<n;i++) {
            long now = a[i];
            int l = 0, r = n;
            if(now >= 0) {
                while(l<r) {
                    int c = (l+r)/2;
                    if(now * a[c] < x) l = c+1;
                    else r = c;
                }
                tot += l;
            }
            else {
                while(l<r) {
                    int c = (l+r)/2;
                    if(now * a[c] >= x) l = c+1;
                    else r = c;
                }
                tot += (n - l);
            }
            if((long)a[i] * a[i]<x)tot--;
        }
        if(tot/2 < k) return true;
        else return false;
    }
}

//高速なScanner
class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}



Measured memory_bytes: 49880
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>

using namespace std;

typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef map<int, int> M;
typedef pair<int, int> P;
typedef stack<int> S;
typedef queue<int> Q;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, d, x;
    cin >> n >> d >> x;
    VI a = VI(n, 0);
    int ans = x;
    for(int i = 0; i < n; ++i)
    {
        cin >> a[i];
        for (int j = 1; j <= d; j+=a[i]) ++ans;
    }
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
  vector<int> x(5);
  int ans = 0; 
  for( int i=0;i<5;++i )
    {
      cin >> x[i];
      ans += x[i]%10==0?x[i]:(x[i]-x[i]%10+10);
    }

  //  cout << ans << endl;
  int tmp = 10;
  
  for( int i=0;i<5;++i )
    {
      if( x[i]%10!= 0 && x[i]%10<tmp )
	tmp = x[i]%10;
    }
  //  cout << tmp << endl;  
  if( tmp != 10)
    ans -= (10-tmp);

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


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

int main() {
    while (true) {
        int n;
        cin >> n;
        
        if (n==0) {
            break;
        }
        
        int h[n+1];
        
        for (int i=0; i<=n; i++) {
            cin >> h[i];
        }
        
        for (int i=0; i<=n; i++) {
            vector<int> l;
            
            for (int j=0; j<=n; j++) {
                if (i==j) {
                    continue;
                }
                
                l.push_back(h[j]);
            }
            
            int d = l[1]-l[0];
            bool flag = true;
            
            for (int j=0; j<n-1; j++) {
                if (l[j+1]-l[j]!=d) {
                    flag = false;
                    break;
                }
            }
            
            if (flag) {
                cout << h[i] << endl;
                break;
            }
        }
    }
}


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

int n,x,y,a,b,c,d[2005][2005],cnt[2005];



int main()
{
	scanf("%d%d%d",&n,&x,&y);

	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			{
				a=abs(j-i);
				b=abs(i-x)+1+abs(j-y);
				c=abs(i-y)+1+abs(j-x);
				d[i][j]=min(a,min(b,c));
			}
			
	for(int i=1;i<=n;i++)
    	for(int j=i;j<=n;j++)
    	{
    		cnt[d[i][j]]++;	
		}
  

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

        
	return 0;
}

Measured memory_bytes: 15872
(* unihernandez22
 * https://atcoder.jp/contests/abc142/tasks/abc142_b
 * implementation, simulation
 * *)

Scanf.scanf "%d %d\n" @@ fun n k ->
    Printf.printf "%d\n" @@ Array.fold_left ( + ) 0 @@
    Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun h -> if h >= k then 1 else 0



Measured memory_bytes: 6620
#include <iostream>
using namespace std;
struct Point 
{
	int x;
	int y;
};

bool inLine(Point a, Point b, Point c)
{
	if(b.x<=max(a.x,c.x) && b.x>=min(a.x,c.x) && b.y<=max(a.y,c.y) && b.y>=min(a.y,c.y)) return true;
	return false;
}

int orientation(Point a, Point b, Point c)
{
	int val = (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
	//counterclockwise
	if(val<0) return -1;
	//clockwise
	else if(val>0) return 1;
	//coliar
	return 0;	
}

bool intersect(Point a, Point b, Point c, Point d)
{
	int o1 = orientation(a,b,c);
	int o2 = orientation(a,b,d);	
	int o3 = orientation(c,d,a);
	int o4 = orientation(c,d,b);

	if(o1!=o2 && o3!=o4) return true;
	if(o1==0 && inLine(a,c,b)) return true;
        if(o2==0 && inLine(a,d,b)) return true;
	if(o3==0 && inLine(c,a,d)) return true;
	if(o4==0 && inLine(c,b,d)) return true;
	return false;	
}

int main()
{
	int q;
	int p1x,p1y,p2x,p2y;
	int q1x,q1y,q2x,q2y;
	cin>>q;
	for(int i=0;i<q;i++)
	{
		cin>>p1x>>p1y>>p2x>>p2y;
		cin>>q1x>>q1y>>q2x>>q2y;

		struct Point p1 = {p1x,p1y};
		struct Point p2 = {p2x,p2y};
		struct Point q1 = {q1x,q1y};
		struct Point q2 = {q2x,q2y};
		cout<<intersect(p1,p2,q1,q2)<<endl;
	}
	return 0;
}



Measured memory_bytes: 3124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AthleteProgramming2
{

    class Point
    {
        public double x;
        public double y;
        public Point(double x,double y)
        {
            this.x = x;
            this.y = y;
        }
       public  static double Inclination(Point p1,Point p2)
        {
            double x = p2.x - p1.x;
            double y = p2.y - p1.y;
            return y / x;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string str;
            for(int i = 0; i < n; i++)
            {
                str = Console.ReadLine();
                double[] data = str.Split(' ').Select(double.Parse).ToArray();
                Point a = new Point(data[0], data[1]);
                Point b = new Point(data[2], data[3]);
                Point c = new Point(data[4], data[5]);
                Point d = new Point(data[6], data[7]);
                double inclination1 = Point.Inclination(a, b);
                double inclination2 = Point.Inclination(c, d);
                if (inclination1.ToString("F6") == inclination2.ToString("F6"))
                {
                    Console.WriteLine("YES");
                }else
                {
                    Console.WriteLine("NO");
                }
            }
        }
    }

}

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

int main() {
    FIO;
    string s;
    cin>>s;
    if(s.at(s.length()-1)=='s')
        cout<<s+"es";
    else
        cout<<s+'s';
    
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;


int main(){
  string s;
  cin >> s;
  int n=s.size();
  vector<int> ans(n,0);
  int cnt=0;
  char c='R';
  rep(i,n){
    if(s.at(i)==c && i!=n-1){
      cnt++;
      continue;
    }
    else{
      if(i==n-1){
        if(c=='R'){
          ans.at(n-1)+=1;
        }
        else{
          cnt++;
        }
      }
      if(c=='R'){
        c='L';
        ans.at(i) += cnt/2;
        ans.at(i-1) += (cnt+1)/2;
        cnt=1;
      }
      else{
        c='R';
        if(i!=n-1){
          ans.at(i-cnt)+=(cnt+1)/2;
          ans.at(i-cnt-1) += cnt/2;
        }
        else{
          ans.at(i-cnt+1)+=(cnt+1)/2;
          ans.at(i-cnt) += cnt/2;
        }
        cnt=1;
      }
    }
  }
  rep(i,n) cout << ans.at(i) << ' ';
  cout << endl;
}


Measured memory_bytes: 1024
import itertools
n,m,q=map(int,input().split())
a=[[int(i) for i in input().split()] for l in range(q)]
b=[int(i) for i in range(1,m+1)]
M=0
for x in itertools.combinations_with_replacement(b,n):
    r=0
    for y in a:
       if x[y[1]-1]-x[y[0]-1]==y[2]:r+=y[3]
    M=max(M,r)
print(M)

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

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;
static long long INF = (1LL<<62);
using LLPair = pair<LL, LL>;

int main(int argc, char* argv[]){
	int H, W, N;
	vector<int> A;
	vector<int> B;

	cin >> H >> W;
	cin >> N;
	for(int i=0; i<N; i++){
		int a; cin >> a;
		A.push_back(a);
	}

	for(int i=0; i<A.size(); i++){
		for(int j=0; j<A[i]; j++){
			B.push_back(i+1);
		}
	}

	int dir = 1;
	for(int i=0; i<H; i++){
		vector<string> S;
		for(int j=0; j<W; j++){
			int c = B[B.size()-1]; B.pop_back();
			string s = to_string(c);
			S.push_back(s);
			if(j != W-1){
				S.push_back(" ");
			}
		}
		if(dir == -1){
			reverse(S.begin(), S.end());
		}
		for(int i=0; i<S.size(); i++){
			printf("%s", S[i].c_str());
		}
		printf("\n");
		dir *= (-1);
	}
	return 0;
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int gcd(int a,int b){
      if(b==0)return a;
      return gcd(b,a%b);
}
int main(){
      int a,b;
      cin>>a>>b;
      cout<<gcd(a,b)<<endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repbtw(i, a, b) for (int i = a; i <= (int)(b); i++)
#define all(v) v.begin(), v.end()
#define pr(x) cout << x << endl


int main()
{
    string s, t;
    cin >> s >> t;
    rep(i, s.size()){   
        if(s.at(i) != t.at(i)){
            pr("No");
            return 0;
        }
    }
    pr("Yes");
    return 0;
}



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

using namespace std;

int main(){
	int n;
  	cin >> n;
  	vector<string> blue(n);
  	for(int i = 0; i < n ; i++ ){
    	cin >> blue[i];
    }
  	
  	int m;
  	cin >> m;
  	vector<string> red(m);
  	for(int i = 0; i < m; i++){
    	cin >> red[i];
    }

  	int ans = 0;
  	auto calc = [&](string s){
    	int buf = 0;
      	for(string t :blue){
        	if(t==s) buf++;
        }
      
      	for(string t : red){
        	if(t == s) buf--;
        }
      	return buf;
      
    };

  	for(string t : blue){
    	ans = max(ans, calc(t));
    }
  	cout << ans << endl;
  	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n;
	cin >> n;
	vector<string> vs(n);
	vector<int> vi(n);
	rep(i, n) {
		cin >> vs[i] >> vi[i];
	}
	string x;
	cin >> x;
	int ans = 0;
	int flag = 0;
	rep(i, n) {
		ans += flag * vi[i];
		flag |= vs[i] == x;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
 
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
 
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
 
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define Se second
#define Fi first
 
int main() {
	int N;
	scanf("%d", &N);
 
	if (N == 3) return !printf("2 5 63\n");
	if (N == 4) return !printf("2 5 20 63\n");
	if (N == 5) return !printf("2 3 4 6 9\n");
	if (N == 6) return !printf("2 3 4 6 9 12\n");
	if (N == 7) return !printf("2 3 4 6 8 9 10\n");
	
	int x = N / 8;
	for (int i = 0; i < x; i++) printf("%d %d %d %d %d %d %d %d ", i * 12 + 2, i * 12 + 3, i * 12 + 4, i * 12 + 6, i * 12 + 8, i * 12 + 9, i * 12 + 10, i * 12 + 12);
 
	int t = x * 12;
	if (N % 8 == 0);
	else if (N % 8 <= 2) {
		printf("%d ", t + 6);
		if (N % 8 == 2) printf("%d ", t + 12);
	}
	else if (N % 8 <= 4) {
		printf("%d %d %d ", t + 3, t + 6, t + 9);
		if (N % 8 == 4) printf("%d ", t + 12);
	}
	else if (N % 8 <= 6) {
		printf("%d %d %d %d %d ", t + 2, t + 3, t + 4, t + 6, t + 9);
		if (N % 8 == 6) printf("%d ", t + 12);
	}
	else printf("%d %d %d %d %d %d %d ", t + 2, t + 3, t + 4, t + 6, t + 8, t + 9, t + 10);
	return !printf("\n");
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

			int  X = sc.nextInt();

			if (X == 7 || X == 5 || X == 3) {

				System.out.println("YES");
			}else {

				System.out.println("NO");
			}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

int N;
string c;
int ans;

int main() {
    cin >> N >> c;
    int r = N - 1;
    int l = 0;
    while (true) {
        while (r != 0 && c[r] != 'R') {
            r--;
        }
        while (l != N - 1 && c[l] != 'W') {
            l++;
        }
        if (r <= l) break;
        c[r] = 'W';
        c[l] = 'R';
        //cout << r << " " << l << endl;
        //cout << c << endl;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

bool vector_find(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) {
        return true;
    }
    else {
        return false;
    }
}


int main(void){
    ll result;
    vector<ll> ABC;
    rep(i, 3){
        ll x;
        cin >> x;
        ABC.push_back(x);
    }
    sort(ALL(ABC));

    result += 10*ABC[2] + ABC[1] + ABC[0];
    
    cout << result << endl;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n;
    cin>>n;

    vc<pair<string,int>> strset,preset;
    vc<string> al={"a","b","c","d","e","f","g","h","i","j"};
    strset.push_back(make_pair(al[0],1));

    rep(i,n-1){
        preset=strset;
        strset.clear();
        rep(i,preset.size()){
            // cerr<<prest[i].first<<"\n";
            rep(j,preset[i].second){
                strset.push_back(make_pair(preset[i].first+al[j],preset[i].second));
            }
            strset.push_back(make_pair(preset[i].first+al[preset[i].second],preset[i].second+1));
        }
    }

    rep(i,strset.size()){
        cout<<strset[i].first<<"\n";
    }
    
    return 0;
}

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

int main() {
  string S,T; cin >> S >> T;
  ll s = S.size(); ll t = T.size();
  ll ans = t;
  
  rep(i, s-t+1){
    ll cnt = 0;
    rep(j, t){
      if(T.at(j) != S.at(i+j))
        cnt++;
    }
   // cout << cnt << endl;
    if(cnt < ans)
      ans = cnt;
  }
  cout << ans << endl;
}

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

int main(){
    int W, H, x, y, r;
    
    cin >> W >> H >> x >> y >> r;
    
    if (r>x){
        cout << "No" << endl;
    } else if (W<x+r){
        cout << "No" << endl;
    } else if (r>y){
        cout << "No" << endl;
    } else if (H<y+r){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3116
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque



def main():
    num, k = map(int, input().split())
    data = list(map(int, input().split()))
    ans = 0

    for i in range(num):
        if data[i] >= k:
            ans += 1

    print(ans)






if __name__ == '__main__':
    main()


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

int isprime(int);

int main(){
    int n, a, i, count = 0;
    
    scanf("%d", &n);
    
    for(i = 0; i < n; i++){
    	scanf("%d", &a);
    	//printf("%d ", a);
    	count += isprime(a);
    	//printf("%d\n", isprime(a));
    }
    
    printf("%d\n",count);
    
    return 0;
}

int isprime(int a){
	int i;
	if(a == 2){
		return 1;
	}
	
	if(a % 2 == 0){
		return 0;	
	}
	
	i = 3;
	while(i <= sqrt(a)){
		if(a % i == 0){
			return 0;
		}
		i += 2;
	}
	
	return 1;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define N 10005

int n,ans;
string s[N];
int a,b,c;

int main()
{
	
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>s[i];
	for(int i=0;i<n;i++)
	for(int j=0;j<s[i].size()-1;j++)
		if(s[i].substr(j,2)=="AB") ans++;
	for(int i=0;i<n;i++)
	{
		if(s[i][0]=='B') b++;
		if(s[i][s[i].size()-1]=='A') a++; 
		if(s[i][0]=='B' && s[i][s[i].size()-1]=='A') c++;
	}
	ans+=min(a,b);
	if(c==a && c==b && c) ans--;
	cout<<ans<<'\n';
	
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>

int main() {
	int m, n, a[100];
	std::cin >> m >> n;
	for (int i = 0;i < n * 2;i++) {
		std::cin >> a[i];
	}
	for (int i = 1;i <= m;i++) {
		int nSum = 0;
		for (int j = 0;j < n * 2;j++) {
			if (i == a[j]) {
				nSum += 1;
			}
		}
		std::cout << nSum << std::endl;
	}
	return 0;
}
	


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int x,sum,z,y;
	scanf("%d",&x);
	y=x%1000;
	if(y==0)
	{
	printf("0");
	}
	else
	{
		y=x/1000;
		sum=1000*(y+1);
		z=sum-x;
		printf("%d",z);
	}
	return 0;
}

Measured memory_bytes: 1728
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define INF 10000000000000

int N, K;
int H[305];

long long memo[305][305];
long long getMinPaint(int index, int remK)
{
    if (index >= N) return 0;
    if (memo[index][remK] != -1) return memo[index][remK];

    long long curAns = INF;
    for (int i = 0; i <= remK; i++)
    {
        curAns = min(curAns, getMinPaint(index + i + 1, remK - i) + max(0, H[index + i + 1] - H[index]));
    }
    return memo[index][remK] = curAns;
}

int main()
{
    scanf("%d%d", &N, &K);
    H[0] = 0;
    for (int i = 1; i <= N; i++)
    {
        scanf("%d", H + i);
    }

    memset(memo, -1, sizeof(memo));
    printf("%lld", getMinPaint(0, K));
}


Measured memory_bytes: 896
from itertools import groupby

RANGE_TO_COLORS = {
    range(1, 400): "gray",
    range(400, 800): "brown",
    range(800, 1200): "green",
    range(1200, 1600): "lightblue",
    range(1600, 2000): "blue",
    range(2000, 2400): "yellow",
    range(2400, 2800): "orange",
    range(2800, 3200): "red",
    range(3200, 4801): "all"
}


def rate_to_color(r: int) -> str:
    for _range, color in RANGE_TO_COLORS.items():
        if r in _range:
            return color
    else:
        return "Unknown"


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

groups = []
unique_keys = []
data = sorted(A, key=rate_to_color)
for k, g in groupby(data, rate_to_color):
    groups.append(len(list(g)))
    unique_keys.append(k)

if "all" in unique_keys:
    idx = unique_keys.index("all")
    n = groups[idx]
    c = len(unique_keys) - 1
else:
    n = 0
    c = len(unique_keys)

print(c if c >= 1 else 1, n + c)


Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_L = 100;

const int INF = 1 << 30;

/* typedef */

struct Edge {
  int i, d, e;
  Edge() {}
  Edge(int _i, int _d, int _e): i(_i), d(_d), e(_e) {}
};

typedef vector<Edge> ve;

struct Stat {
  int d, i, l;
  Stat() {}
  Stat(int _d, int _i, int _l): d(_d), i(_i), l(_l) {}

  bool operator>(const Stat& s0) const { return d > s0.d; }
  void print() { printf("Stat: d=%d, i=%d, l=%d\n", d, i, l); }
};

/* global variables */

int n, m, l;
ve nbrs[MAX_N];
int dists[MAX_N][MAX_L + 1];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> m >> l;
    if (n == 0) break;

    for (int i = 0; i < n; i++) nbrs[i].clear();

    for (int i = 0; i < m; i++) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      a--, b--;
      nbrs[a].push_back(Edge(b, d, e));
      nbrs[b].push_back(Edge(a, d, e));
    }

    for (int i = 0; i < n; i++)
      for (int j = 0; j <= l; j++) dists[i][j] = INF;
    dists[0][l] = 0;

    priority_queue<Stat,vector<Stat>,greater<Stat> > q;
    q.push(Stat(0, 0, l));

    while (! q.empty()) {
      Stat u = q.top(); q.pop();
      //u.print();
      
      if (u.d != dists[u.i][u.l] || u.i == n - 1) continue;

      ve& nbru = nbrs[u.i];
      for (ve::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
	int vi = vit->i;
	int vd = u.d + vit->e;
	
	if (dists[vi][u.l] > vd) {
	  dists[vi][u.l] = vd;
	  q.push(Stat(vd, vi, u.l));
	}

	int vl = u.l - vit->d;
	if (vl >= 0 && dists[vi][vl] > u.d) {
	  dists[vi][vl] = u.d;
	  q.push(Stat(u.d, vi, vl));
	}
      }
    }

    int min_d = INF;

    for (int i = 0; i <= l; i++) {
      //printf("dists[n-1][%d]=%d\n", i, dists[n - 1][i]);
      if (min_d > dists[n - 1][i]) min_d = dists[n - 1][i];
    }

    cout << min_d << endl;
  }

  return 0;
}

Measured memory_bytes: 1736
n = int(input())
hs = input()
hs = hs.split(' ')
hs = [int(i) for i in hs]
r = 0
maxr = 0
curi = 1e11
for i in hs:
    if curi >= i:
        r += 1
        curi = i
    else:
        maxr = max(maxr, r)
        curi = i
        r = 1

maxr = max(maxr, r)
print(maxr - 1)


Measured memory_bytes: 14252
# -*- coding: utf-8 -*-
# 標準入力を取得
N = int(input())
a = list(map(int, input().split()))

# 求解処理
ans = 0
for i in range(0, N, 2):
    ans += (a[i] % 2 == 1)

# 結果出力
print(ans)


Measured memory_bytes: 9096
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
cost0 = 0
costn = 0

for i in range(m):
    if a[i] < x:
        cost0 += 1
    if a[i] > x:
        costn += 1

print(min(cost0, costn))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
    
#define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    
 
#define bp __builtin_popcountll
#define inf 1e18
    
const int N=50+5;
const int MOD=1e9+7;
bool chk(int r,int g,int b)
{
	if(b>g && g>r)
	return true;
	return false;
}
int go(int r,int g,int b,int k)
{
	if(chk(r,g,b))
	return 1;
	if(k==0)
	return 0;
	int ans=0;
	ans=ans|go(2*r,g,b,k-1);
	ans=ans|go(r,2*g,b,k-1);
	ans=ans|go(r,g,2*b,k-1);
	return ans;
}
void solve()
{
	int r,g,b,k;
	cin>>r>>g>>b>>k;
	int ans=go(r,g,b,k);
	if(ans==1)
	cout<<"Yes";
	else
	cout<<"No";
}
 
signed main()
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": "<<endl;
    	solve();
    }
}

Measured memory_bytes: 3648
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int main(void){
	int N; cin >> N;
	map<int, int> cnt;
	for (int i = 0; i < N; ++i){
		int Di; cin >> Di;
		cnt[Di]++;
	}
	int M; cin >> M;
	for (int i = 0; i < M; ++i){
		int Ti; cin >> Ti;
		if (cnt[Ti]-- == 0){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 12908
#include <iostream>
#include <vector>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= (m); --(i))
typedef long long ll;
using namespace std;
int main() {
    int n; ll l; cin >> n >> l;
    vector<ll> a(n); repeat (i,n) cin >> a[i];
    vector<int> ans;
    repeat (i,n-1) {
        if (a[i] + a[i+1] >= l) {
            repeat (j,i) ans.push_back(j);
            repeat_from_reverse (j,i,n-1) ans.push_back(j);
            break;
        }
    }
    if (ans.empty()) {
        assert (n >= 2);
        cout << "Impossible" << endl;
    } else {
        cout << "Possible" << endl;
        for (int i : ans) cout << i+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 2168
n=int(input())
w=list(map(int,input().split()))

min_=sum(w)
for i in range(len(w)):
  s1=0
  s2=0
  for j in range(i):
    s1+=w[j]
  for j in range(i,len(w)):
    s2+=w[j]
  if min_>abs(s1-s2):
    min_=abs(s1-s2)
    
print(min_)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=100100;
int n,a[maxn],t[maxn],ans; 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		t[a[i]]++;
	ans=0;
	for(int i=1;i<=100000;i++)		
		ans=max(ans,t[i-1]+t[i]+t[i+1]);
	printf("%d",ans);	
	return 0;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
s = []
c = []
for i in range(n):
    s.append(list(map(int, input().split())))

for j in range(m):
    c.append(list(map(int, input().split())))
    
for k in range(n):
    cnt = []
    for l in range(m):
        kyori = abs(s[k][0]-c[l][0])+abs(s[k][1]-c[l][1])
        cnt.append(kyori)
    print(cnt.index(min(cnt))+1)

Measured memory_bytes: 68668
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,d;
	cin>>n>>d;
	d=d*2+1;
	float sum=float(n)/float(d);
	int k=sum;
//	cout<<sum<<endl;
	if(sum>k){
		k++;
	}
	cout<<k;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int A;
	int B;
	int K;
	int m[101];
	int p;
	for (int i = 0; i <= 100; i++)
		m[i] = 0;

	cin >> A >> B>>K;
	for (int i = 1; i <= 100; i++)
	{
		if (A%i == 0 && B%i == 0)
		{
			
			for (int j = 1; j <= 100; j++)
				if (m[j] == 0)
				{
					m[j] = i;
					break;
				}
		}
	}
	for (int i = 1; i <= 100; i++)
		if (m[i] == 0)
		{p = i-1;
	break; 
		}
	cout << m[p+1-K];
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    bool X = 0;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(j * i == N){
               X = 1;
                break;
            }
        }
    }
    if(X == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

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

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

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

ll p(ll n) {
	if (n == 0) { return 1; }
	else { return 10 * p(n - 1); }
}

long double s(ll n) {
	ll k = 0;

	for (ll m = n; m > 0; m /= 10) {
		k += m % 10;
	}

	return (long double)n / (long double)k;
}

int main() {

	ll N, A, B;
	cin >> N >> A >> B;

	cout << min(N*A, B);
	

	system("PAUSE");

	

}


Measured memory_bytes: 504
import Data.List.Split
import qualified Data.Map as Map

--data Tree = Tree {node :: Int, left :: Tree, right :: Tree} | Emp
type Tree = Map.Map Int (Int,Int)

main = do
	ns <- getLoopValues
	let tree = createTree ns
	putStrLn "Preorder"
	putStr " " >> printList (preorder tree)
	putStrLn "Inorder"
	putStr " " >> printList (inorder tree)
	putStrLn "Postorder"
	putStr " " >> printList (postorder tree)

printList [] = putStrLn ""
printList (x:[]) = putStrLn $ show x
printList (x:xs) = putStr (show (x) ++ " ") >> printList xs

preorder :: Tree -> [Int]
preorder tree = preorder_ (getRoot tree)
  where
    preorder_ (-1) = []
    preorder_ s = s:(preorder_ l) ++ (preorder_ r)
      where 
        (l,r) = tree Map.! s

inorder :: Tree -> [Int]
inorder tree = inorder_ (getRoot tree)
  where
    inorder_ (-1) = []
    inorder_ s = (inorder_ l) ++ s:(inorder_ r)
      where 
        (l,r) = tree Map.! s

postorder :: Tree -> [Int]
postorder tree = postorder_ (getRoot tree)
  where
    postorder_ (-1) = []
    postorder_ s = (postorder_ l) ++ (postorder_ r) ++ s:[]
      where 
        (l,r) = tree Map.! s

--木のルートを取得する
getRoot :: Tree -> Int
getRoot t = getRoot_ 0 t
  where
    getRoot_ n t = case getParent n t of
	                    Nothing -> n			--親が見つからなかった場合、今のノードがルート
	                    Just p -> getRoot_ p t --親が見つかった場合、さらにその親を取得する

--指定されたノードの親を取得する
getParent :: Int -> Tree -> Maybe Int
getParent c t = safeHead $ Map.keys $ Map.filter isChild t
  where 
    isChild (l,r)
      | l == c    = True
      | r == c    = True
      | otherwise = False

safeHead []    = Nothing
safeHead (a:_) = Just a

--木（連想配列）を作る
createTree :: [(Int,Int,Int)] -> Tree
createTree ns = Map.fromList $ map (\(a,b,c) -> (a,(b,c))) ns

getLoopValues :: IO([(Int,Int,Int)])
getLoopValues = do
    loopNum <- getInt
    lines <- getLoopValues' loopNum
    return $ map (\(a:b:c:_) -> (a,b,c)) $ map (map read) $ map (splitOn " ") $ lines

getLoopValues' :: Int -> IO([String])
getLoopValues' 0 = return []
getLoopValues' n = do
    v <- getLine
    vs <- getLoopValues' (n - 1)
    return $ v : vs

getInt :: IO (Int)
getInt = do
    str <- getLine
    return $ read str





Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int n,q,l,r;
  string s;
  cin >> n>>q>>s;
  vector<int> v;
  rep(i,n-1)
     if(s[i]=='A'&&s[i+1]=='C')
       v.push_back(i);
  rep(i,q){
    cin>>l>>r;
    cout<<binary_search(v.begin(),v.end(),r-2)+(lower_bound(v.begin(),v.end(),r-2)-v.begin())-(lower_bound(v.begin(),v.end(),l-1)-v.begin())<<endl;
  }
  return 0;
}


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

int main()
{
	int x, a, b;

	cin >> x >> a >> b;

	if ( abs(x - a) > abs(x - b) ) {
		cout << "B" << endl;
	} else {
		cout << "A" << endl;
	}

	return ( 0 );
}


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

typedef long long ll;

int
main(void)
{
  ll a, b, k; cin >> a >> b >> k;
  if(0 <= a - k){
    cout << a - k << " " << b << endl;
  } else{
    k -= a;
    if(0 <= b - k){
      cout << 0 << " " << b - k << endl;
    } else {
      cout << 0 << " " << 0 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
using static Func;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var S = Str;
		WriteLine(new HashSet<char>(S).Count == 2 && S.Count(c => c == S[0]) == 2 ? "Yes" : "No");
	}
}
static class Func
{
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; }
	static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; }
	public static long GCD(long a, long b)
	{
		var n = (ulong)Math.Abs(a); var m = (ulong)Math.Abs(b);
		if (n == 0) return (long)m; if (m == 0) return (long)n;
		int zm = 0, zn = 0;
		while ((n & 1) == 0) { n >>= 1; zn++; }
		while ((m & 1) == 0) { m >>= 1; zm++; }
		while (m != n)
		{
			if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; }
			else { n -= m; while ((n & 1) == 0) n >>= 1; }
		}
		return (long)n << Math.Min(zm, zn);
	}
	public static long Inverse(long a, long mod)
	{
		if (a < 0) { a %= mod; if (a < 0) a += mod; }
		var t = SolveLinear(a, mod);
		return t.Item1 > 0 ? t.Item1 : t.Item1 + mod;
	}
	public static long Pow(long a, long b, long mod)
	{
		var p = 1L;
		var x = a;
		while (b > 0)
		{
			if ((b & 1) == 1) p = (p * x) % mod;
			b >>= 1;
			x = (x * x) % mod;
		}
		return p;
	}
	public static Tuple<long, long> SolveLinear(long n, long m)
	{
		if (n < 0) { var p = SolveLinear(-n, m); return p == null ? p : new Tuple<long, long>(-p.Item1, p.Item2); }
		if (m < 0) { var p = SolveLinear(n, -m); return p == null ? p : new Tuple<long, long>(p.Item1, -p.Item2); }
		if (n < m) { var p = SolveLinear(m, n); return p == null ? p : new Tuple<long, long>(p.Item2, p.Item1); }
		long a = 1, b = 0, c = 0, d = 1;
		while (m > 0)
		{
			var r = n % m;
			var q = n / m;
			n = m;
			m = r;
			var tmp = a;
			a = -a * q + b;
			b = tmp;
			tmp = c;
			c = -c * q + d;
			d = tmp;
		}
		return n != 1 ? null : new Tuple<long, long>(d, b);
	}
}


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

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<string>> data(H, vector<string>(W) );
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> data.at(i).at(j);
        }
    }

    string S = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(data.at(i).at(j) == "snuke"){
                cout << S.at(j) << i + 1 << endl;
            }
        }
    }

}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int num[] = {1, 1};

  for (num[0] = 1; num[0] <= 9; num[0]++) {
    for (num[1] = 1; num[1] <= 9; num[1]++) {
      printf("%dx%d=%d\n", num[0], num[1], num[0] * num[1]);
    }
  }

  return 0;
}

Measured memory_bytes: 520
def resolve():
    def solve(n, arr):

        def cycles():
            V = [False]*N
            B = sorted(A)
            T = {B[i]:i for i in range(N)}
            C = []
            for i in range(N):
                if V[i]:
                    continue
                cur = i
                cycle = []
                while not V[cur]:
                    V[cur] = True
                    cycle.append(cur)
                    cur = T[A[cur]]
                C.append(cycle)
            return C

        ans = 0
        minV = min(A)
        for cycle in cycles():
            S = sum([A[i] for i in cycle])
            m = min([A[i] for i in cycle])
            an = len(cycle)
            ans += min(S+(an-2)*m, S+(an+1)*minV+m)
        return ans

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

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 5860
#include <iostream>
#include <algorithm>
using namespace std;
int c[51][51],w,h;
void func(int i,int j){
  c[i][j]=0;
  if(i+1<h&&c[i+1][j]==1)
    func(i+1,j);
  if(i-1>=0&&c[i-1][j]==1)
    func(i-1,j);
  if(j+1<w&&c[i][j+1]==1)
    func(i,j+1);
  if(j-1>=0&&c[i][j-1]==1)
    func(i,j-1);
  if(i+1<h&&j+1<w&&c[i+1][j+1]==1)
    func(i+1,j+1);
  if(i+1<h&&j-1>=0&&c[i+1][j-1]==1)
    func(i+1,j-1);
  if(i-1>=0&&j+1<w&&c[i-1][j+1]==1)
    func(i-1,j+1);
  if(i-1>=0&&j-1>=0&&c[i-1][j-1]==1)
    func(i-1,j-1);
}
int main(){
  while(1){
    int i,j,ans=0;
    cin>>w>>h;
    if(w==0&&h==0)
      break;
    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
	cin>>c[i][j];
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(c[i][j]==1){
	  func(i,j);
	  ans++;
	}
      }
    }
    cout<<ans<<endl;
  }
}



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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, B, K;
    cin >> A >> B >> K;

    ll cn = 0;
    for(ll i = A; i <= B; i++){
        if(cn < K || B - A - K < cn){
            cout << i << endl;
        }
        cn++;
    }

}

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


int main()
{
  int N, K;
  cin >> N >> K;
  string s;
  cin >> s;
  auto target = s[K - 1];
  if (target == 'A') {
    s[K - 1] = 'a';
  } else if (target == 'B') {
    s[K - 1] = 'b';
  } else {
    s[K - 1] = 'c';
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  unsigned int n, a, b;

  while (scanf("%d%d", &a, &b) != EOF) {
    if (a + b < 10)
      printf("1\n");
    else if (a + b < 100)
      printf("2\n");
    else if (a + b < 1000)
      printf("3\n");
    else if (a + b < 10000)
      printf("4\n");
    else if (a + b < 100000)
      printf("5\n");
    else if (a + b < 1000000)
      printf("6\n");
    else
      printf("7\n");
  }

  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int n;
  cin >> n;
  map<string,int> m;
  REP(i,n) {
    string s;
    cin >> s;
    m[s]++;
  }
  int x;
  cin >> x;
  REP(i,x) {
    string s;
    cin >> s;
    m[s]--;
  }
  int ans=0;
  for(auto [i, j]:m) {
    if(j>ans) ans=j;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3564
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif


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

    string S; cin >> S;
    ll K; cin >> K;
    int N = S.size();

    // 11..123 -> 11..12...3....3
    int cnt = 0;
    REP(i,N) {
        if (S[i] == '1') cnt++;
        else break;
    }
    if (K <= cnt) {
        cout << 1 << endl;
        return 0;
    }

    // 123 -> 12...23....33
    int ans = S[cnt] - '0';
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
#define pii pair<pii , pii>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int d, t , s;

int main()
{
    _FastIO;

    cin >> d >> t >> s;
    if(t * s >= d){
        cout << "Yes" << endl;
    }else{
    cout << "No" << endl;}

    return 0;
}


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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N;
  ll K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    tmp--;
    A.at(i) = tmp;
  }

  map<int,int> m;
  map<int,int> r;
  int num = 0;
  m[0] = 0;
  r[0] = 0;
  int now = 0;
  while(num <= N){
    num++;
    now = A[now];
    if(m.count(now) == 0){
      m[now] = num;
      r[num] = now;
    } else {
      break;
    }
  }

  // 周期: 
  ll reg = num - m[now];
  //スタート地点;
  int start = now;
  //スタートまでにかかる時間
  int until_start = m[start];

  // cerr << "reg: " << reg << " start: " << start << " until_start: " << until_start << endl;

  int ans;
  if(K <= (ll)until_start){
    ans = r[K];
  } else {
    K = K - (ll)until_start;
    K %= reg;
    ans = r[until_start + K];
  }
  cout << ans+1 << endl;



}

Measured memory_bytes: 22416
def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  for i in reversed(input()):
    n = (n+int(i)*d)%2019
    d = d*10%2019
    mods[n] += 1
  print(sum([i*(i-1)//2 for i in mods]))
main()

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

using namespace std;

int main(){
    ios_base::sync_with_stdio (false);
    int a,b,c;
    long long x,y,s,r;
    cin>>a>>b>>c>>x>>y;
    if(x>y){
        if(2*c*x <= 2*c*y+(x-y)*a){
            s=2*c*x;
        } else s=2*c*y+(x-y)*a;
        if(a*x+b*y <= s)
            r=a*x+b*y;
        else r=s;
    } else {
        if(2*c*y <= 2*c*x+(y-x)*b){
            s=2*c*y;
        } else s=2*c*x+(y-x)*b;
        if(a*x+b*y <= s)
            r=a*x+b*y;
        else r=s;
    }
    cout<<r;
    return 0;
}


Measured memory_bytes: 256