akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <cmath>
#include <string>
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;

long long fastpow(int a, int b, int MOD)
{
    long long x=1,y=a; 
    while(b > 0)
    {
        if(b%2 == 1)
        {
            x=(x*y) % MOD;
        }
        y = (y*y) % MOD;
        b /= 2;
    }
    return x;
}

long long InverseEuler(int n, int MOD)
{
    return fastpow(n,MOD-2,MOD);
}
 
long long f[300000];
bool init;
long long C(int n, int r, int MOD)
{
    if (!init){
        init=1;
        f[0]=1;
        for (int i=1; i<300000;i++)
            f[i]= (f[i-1]*i) % MOD;
        
    }
    return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}

bool ada[999];
int main(){
   std::ios::sync_with_stdio(false); 
   string S;
   cin>>S;

   if (S.length() < 26) {
    for (char c:S) {
        ada[c] = 1;
    }
    for (int i=0;i<26;i++){
        if (!ada['a' + i]){
            cout<<S<<(char) ('a'+i)<<endl;
            return 0;
        }
    }
   } else if (S == "zyxwvutsrqponmlkjihgfedcba") cout<<-1<<endl; else {
    string Z = S;
    next_permutation(S.begin(), S.end());
    for (int i=0;i<S.length();i++){
        cout<<S[i];
        if (S[i] != Z[i]){
            cout<<endl;
            return 0;
        }
    }
   }

}


Measured memory_bytes: 256
/*
 * ARC082_C.cpp
 *
 *  Created on: Jun 5, 2018
 *      Author: 13743
 */
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

int pile[100001];

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

	int N;
	cin >> N;
	REP(i, N) {
		int a;
		cin >> a;
		pile[a]++;
	}

	int ans = 0;
	int now = 0;
	FOR(i, 0, 100000) {
		now = 0;
		if(i > 0) now += pile[i-1];
		now += pile[i];
		if(i < 100000) now += pile[i+1];
		ans = max(ans, now);
	}

	cout << ans << endl;
}






Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    vector<ll> ans;
    ll s=1e15-1;

    auto g=[](ll num){
        long double ret=num;
        long double bo=0;
        while(num){
            bo+=num%10;
            num/=10;
        }
        return ret/bo;
    };

    function<void(ll)> dfs=[&](ll num){
        ans.push_back(num);
        int d=0;
        ll tmp=num;
        while(tmp) d++,tmp/=10;
        d--;
        ll m=1;
        rep(i,d-5) m*=10;
        
        while(m<num){
            if(g(num-m)<=g(num)){
                dfs(num-m);
                break;
            }
            m*=10;
        }
    };
    dfs(s);
    sort(ALL(ans));
    int k;cin>>k;
    rep(i,k) cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;

const int INF = 1e18;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> A(n);
    rep(i, n)
    {
        cin >> A[i];
        A[i] -= i + 1;
    }

    sort(ALL(A));

    int b = A[(n - 1) / 2];

    int ans = 0;
    rep(i, n) ans += abs(A[i] - b);
    cout << ans << endl;
}

signed main()
{
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){return *(ll *)a - *(ll *)b;}

int main(void){
    ll n,i,ans=0;
    scanf("%lld",&n);
    char s[12],ini[n];
    for(i=0;i<n;i++){
        scanf("%s",s);
        ini[i] = s[0];
    }
    // for(i=0;i<n;i++){
    //     printf("%c ",ini[i]);
    // }
    ll letter[]={0,0,0,0,0};
    for(i=0;i<n;i++){
        if(ini[i]=='M') letter[0]++;
        if(ini[i]=='A') letter[1]++;
        if(ini[i]=='R') letter[2]++;
        if(ini[i]=='C') letter[3]++;
        if(ini[i]=='H') letter[4]++;
    }
    // for(i=0;i<5;i++){
    //     printf("%lld ",letter[i]);
    // }
    for(i=0;i<5;i++){
        for(ll j=i+1;j<5;j++){
            for(ll k=j+1;k<5;k++){
                ans+=letter[i]*letter[j]*letter[k];
            }
        }
    }

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


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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for(ll i = 0 ; i<n ; i++) 
#define repd(n) for(ll i = n-1 ; i>=0 ; i--)
#define MOD 1000000007

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s; cin>>s;
   ll n = s.size(); ll i=0;
   if(n%2) {
   	cout << "No"; return 0;
   }
   if(s[0]!='h') { cout <<"No"; return 0; }
  for(i=0;i<n-1;++i) {
  	if(s[i]=='h' && s[i+1]!='i') { cout <<"No"; return 0; }
  	if(s[i]=='i' && s[i+1]!='h') { cout <<"No"; return 0; }
  }
  cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		
	Scanner sc = new Scanner(System.in);
		
    int x[] = new int[3];
     x[0] = sc.nextInt();
     x[1] = sc.nextInt();
     x[2] = sc.nextInt();
		
     Arrays.sort(x);
     System.out.println(x[0]+" "+x[1]+" "+x[2]);
    }
}


Measured memory_bytes: 26252
import itertools

N = int(input())
X = []
Y = []
R = []

for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    R.append(i)

L = 0
cnt = 0

for r in list(itertools.permutations(R)):
    l = 0
    for i in range(N-1):
        l += ((X[r[i]] - X[r[i+1]])**2 + (Y[r[i]] - Y[r[i+1]])**2)**0.5
    L += l
    cnt += 1

print(L/cnt)


Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 10000000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};


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

	ll n,ans=1;cin>>n;
	vector<ll> t(n),a(n+1,0),res(n,0);

	cin>>t[0];
	res[0]=t[0];

	for(int i=1;i < n;i++)
	{
		cin>>t[i];
		if(t[i]>t[i-1]){
			res[i]=t[i];
		}
	}

	rep(i,n)cin>>a[i];

	
	for(int i=n-1;0<=i;i--)
	{
		if(a[i]>a[i+1]){
			if((!res[i] && a[i]<=t[i])|| (res[i] && res[i]==a[i])){
				res[i]=a[i];//
			}else {
				ans*=0;
			}
		}
	}
	//rep(i,n)cout<<res[i]<<endl;

	rep(i,n){
		if(!res[i]){
			ans*=min(a[i],t[i]);
			ans%=mod;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

vii d(10, vi(10, inf));
vii visited(10, vi(10, 0));
vii c(10, vi(10));

int find_min_v(int cur_v){
    int ans = inf;
    int ans_i = -1;
    rep(i, 0, d[0].size()){
        if(visited[cur_v][i]) continue;
        if(ans > d[cur_v][i]){
            ans = d[cur_v][i];
            ans_i = i;
        }
    } 
    return ans_i;
}

void dijkstra(int cur_v){
    d[cur_v][cur_v] = 0;

    while(find_min_v(cur_v) > -1){
        int fr_v = find_min_v(cur_v);
        visited[cur_v][fr_v] = 1;
        rep(to_v, 0, 10){
            if(d[cur_v][to_v] > (d[cur_v][fr_v] + c[fr_v][to_v])){
                d[cur_v][to_v] = d[cur_v][fr_v] + c[fr_v][to_v];
            }
        }
    }
}

int main(){
    int H, W; cin >> H >> W;
    rep(i, 0, 10){
        rep(j, 0, 10){
            int _c; cin >> _c;
            c[i][j] = _c;
        }
    }
    rep(i, 0, 10){
        dijkstra(i);
    }
    ll cnt = 0;
    rep(i, 0, H){
        rep(j, 0, W){
            int a; cin >> a;
            if(a==-1) continue;
            cnt += d[a][1];
        }
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int dp[N][N], n;
bool vis[N][N];
int dfs(int x, int y) {
	if (vis[x][y]) return dp[x][y];
	vis[x][y] = 1;
	int &nex = dp[x][y] = -1;
	if (x > 1 && x - 1 != y) nex = max(nex, -dfs(y, x - 1));
	if (x < n && x + 1 != y) nex = max(nex, -dfs(y, x + 1));
	return nex;
}
int main() {
	int a, b;
	scanf("%d%d%d", &n, &a, &b);
	puts((b - a) % 2 == 0 ? "Alice" : "Borys");
	return 0;
	int res = dfs(a, b);
	if (res == 0) puts("Draw");
	if (res == 1) puts("Alice");
	if (res == -1) puts("Borys");
}


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

using namespace std;
using ll =long long;
using db = double;

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

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;

ll ans;
//ここから書き始める
int main()
{
	int n ;
	cin >> n;
	for(int i = 1; i < 10; i++){
		if(n / i < 10 && n % i == 0){
			cout <<"Yes"<< endl;
			return 0;
		}
	}
	cout << "No" << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] a = new int[n];

        int i;
        for(i=0;i<n;i++){
            a[i] = sc.nextInt();
        }

        for(i=n-1;i>0;i--){
            System.out.printf("%d ",a[i]);
        }

        System.out.printf("%d\n",a[0]);

        sc.close();
    }
}


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


int main() {
  int H, W;
  cin >> H >> W;
  while (H != 0 || W != 0) {
    rep(i,H) {
      rep(j,W) {
        if (i == 0 || i == H-1 || j == 0 || j == W-1) cout << '#';
        else cout << '.';
      }
      cout << endl;
    }

    cout << endl;
    cin >> H >> W;
  }

  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;

int mod=1000000007;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int Gcd(int x,int y)              //最大公約数
{
  int large = max(x,y);
  int small = min(x,y);

  while(small!=0){
      int amari =large%small;

      large = small;

      small = amari;  
  }
  return large;
}


//メイン関数--------------------------------------------



int main(){

ll a, b, c, d;
cin>>a>>b>>c>>d;
ll e=a*c,f=a*d,g=b*c,h=b*d;
ll ans=max(f,max(g,max(h,e)));
cout<<ans<<endl;
}


Measured memory_bytes: 3672
#include<stdio.h>
int main(void){
  int ii = 0;
  int ij = 0;
  int iAns = 0;

  for(ii=1; ii<10; ii++){
    for(ij=1; ij<10; ij++){
      iAns = ii*ij;
      printf("%dx%d=%d\n" ,ii ,ij ,iAns);
    }
  }

  return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x=nxt();
    if(x<1200)
        cout<<"ABC\n";
    else
        cout<<"ARC\n";
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
N,W = map(int,input().split())

w1,v1 = map(int,input().split())
stuff = [[] for _ in range(4)]
stuff[0].append(v1)

for _ in range(N-1):
    w,v = map(int,input().split())
    stuff[w-w1].append(v)

for i in stuff:
    i.sort(reverse=True)

ans = 0

for a in range(len(stuff[0])+1):
    for b in range(len(stuff[1])+1):
        for c in range(len(stuff[2])+1):
            for d in range(len(stuff[3])+1):

                if a*w1+b*(w1+1)+c*(w1+2)+d*(w1+3) <= W:
                    ans = max(ans,sum(stuff[0][:a])+sum(stuff[1][:b])+sum(stuff[2][:c])+sum(stuff[3][:d]))

print(ans)

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


int main() {
  int five=0, seven=0;
  rep(i, 3){
    int n;
    cin >> n;
    if(n == 5) five++;
    else if(n == 7) seven++;
  }
  string ans = "NO";
  if(five == 2 && seven == 1) ans = "YES";
  
  cout << ans << endl;  
  return 0;
  
}

Measured memory_bytes: 256
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

	using i8 = std::int_least8_t;
	using i32 = std::int_least32_t;
	using i64 = std::int_least64_t;
	using u8 = std::uint_least8_t;
	using u32 = std::uint_least32_t;
	using u64 = std::uint_least64_t;
	using isize = std::ptrdiff_t;
	using usize = std::size_t;

	class rep {
		const usize f, l;

	public:
		class itr {
			friend rep;
			usize i;
			constexpr itr(const usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { ++i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr rep(const usize first, const usize last) noexcept
			: f(first), l(last) {}
		constexpr itr begin() const noexcept { return itr(f); }
		constexpr itr end() const noexcept { return itr(l); }
	};
	class revrep {
		const usize f, l;

	public:
		class itr {
			friend revrep;
			usize i;
			constexpr itr(usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { --i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
		constexpr itr begin() const noexcept { return itr(l); }
		constexpr itr end() const noexcept { return itr(f); }
	};
	template <class T> using vec_alias = std::vector<T>;
	template <class T> auto md_vec(const usize n, const T &value) {
		return std::vector<T>(n, value);
	}
	template <class... Args> auto md_vec(const usize n, Args... args) {
		return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
	}
	template <class T> constexpr T difference(const T &a, const T &b) {
		return a < b ? b - a : a - b;
	}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>
#include<string>

namespace n91 {

	void main_() {
		usize n, q;
		std::cin >> n >> q;
		std::string s;
		std::cin >> s;
		std::vector<char> t(q), d(q);
		for (const auto i : rep(0, q)) {
			std::cin >> t[i] >> d[i];
		}
		usize l = n, r = 0;
		for (const auto i : revrep(0, q)) {
			if (d[i] == 'L') {
				if (r != n&&s[r] == t[i]) {
					++r;
				}
				if (l != n&&s[l] == t[i]) {
					++l;
				}
			}
			else {
				if (l != 0 && s[l - 1] == t[i]) {
					--l;
				}
				if (r != 0 && s[r - 1] == t[i]) {
					--r;
				}
			}
		}
		if (l <= r) {
			std::cout << 0 << std::endl;
		}
		else {
			std::cout << l - r << std::endl;
		}
	}

} // namespace n91

int main() {
	n91::main_();
	return 0;
}


Measured memory_bytes: 900
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

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

ans = 0
for i in range(N):
    if A[A[i] - 1] - 1 == i:
        ans += 1
print(ans//2)


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

int main() {
	int arra[9][9], N;
	for(int i=0;i<9;i++) {
		for(int j=0;j<9;j++) {
			arra[i][j]=(i+1)*(j+1);
		}
	}
	cin>>N;
	for(int i=0;i<9;i++) {
		for(int j=0;j<9;j++) {
			if(arra[i][j]==N) {
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
	return 0;
}

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

using namespace std;

int main(){
	
	int n;
	
	cin >> n;
	
	vector<long long int> a(n);

	long long int sum1=0, sum2=0, cost1=0, cost2=0;

	for(int i=0; i<n; i++){
		cin >> a[i];
		sum1 += a[i];
		sum2 += a[i];
		if(i%2 == 0 && sum1 <= 0){
			cost1 += 1-sum1;
			sum1 = 1;
		}
		else if(i%2 == 1 && sum1 >= 0){
			cost1 += sum1+1;
			sum1 = -1;
		}
		if(i%2 == 0 && sum2 >= 0){
			cost2 += 1+sum2;
			sum2 = -1;
		}
		else if(i%2 == 1 && sum2 <= 0){
			cost2 += 1-sum2;
			sum2 = 1;
		}
	}
	cout << min(cost1, cost2) << endl;
	
	return 0;
}

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

int n,a[N],d[N],t;

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++) d[a[i]]++;
	for (int i=1;i<=n;i++) t=max(t,a[i]);
	for (int i=1;i<(t+1)/2;i++)
		if (d[i]) {printf("Impossible\n");return 0;}
	if (d[(t+1)/2]!=t%2+1) {printf("Impossible\n");return 0;}
	for (int i=(t+1)/2+1;i<=t;i++)
		if (d[i]<2) {printf("Impossible\n");return 0;};
	printf("Possible\n");return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    int ans = 0;
    for(int i=0;i<k;i++){
        ans += l[i];
    }
    cout << ans <<  endl;
}

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

//  2進数ならば baseNumber を  2 とする
// 10進数ならば baseNumber を 10 とする
ll GetDigitsCount(ll targetNumber, ll baseNumber=10) {
	ll digitsCount = 0;
	while (targetNumber != 0) {
		digitsCount++;
		targetNumber /= baseNumber;
	}
	return digitsCount;
}

int main() {

	ll n; cin >> n;
	ll ans = 9223372036854775807LL;
	for (ll i = 1; i * i <= n ; i++) {
		if (n % i != 0) continue;
		ll i_digit = GetDigitsCount(i);
		ll j_digit = GetDigitsCount(n / i);
		ans = min(ans, max(i_digit, j_digit));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3548
a=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
g=[[0]*3 for _ in range(3)]

for _ in range(n):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j]==b:
                g[i][j]=1

f=0
for i in range(3):
    if g[i][0] and g[i][1] and g[i][2]:
        f=1
    if g[0][i] and g[1][i] and g[2][i]:
        f=1
if g[0][0] and g[1][1] and g[2][2]:
    f=1
if g[0][2] and g[1][1] and g[2][0]:
    f=1
print("Yes" if f else "No")


Measured memory_bytes: 38256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end


INF=Float::INFINITY
$ans=0
def merge(a,l,m,r)
    n1=m-l
    n2=r-m
    l_arr=array(n1+1)
    r_arr=array(n2+1)
    n1.times do|i|
        l_arr[i]=a[l+i]
    end
    n2.times do|i|
        r_arr[i]=a[m+i]
    end
    l_arr[n1]=INF
    r_arr[n2]=INF
    i=0
    j=0
    l.upto(r-1) do|k|
        if l_arr[i]<=r_arr[j]
            a[k]=l_arr[i]
            i+=1
        else
            a[k]=r_arr[j]
            j+=1
        end
        $ans+=1
    end
end
def merge_sort(a,l,r)
    if l+1<r
        mid=(l+r)/2
        merge_sort(a,l,mid)
        merge_sort(a,mid,r)
        merge(a,l,mid,r)
    end
end
N=gets.to_i
a=get_i
merge_sort(a,0,N)
puts a.join(" ")
puts $ans


Measured memory_bytes: 69592
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

void solve() {
    int L = 0, R = 1000000;
    int n, m;
    cin >> n >> m;
    loop(i, m) {
        int l, r;
        cin >> l >> r;
        L = max(l, L);
        R = min(R, r);
    }
    if (R < L)
        cout << 0;
    else
        cout << R - L + 1;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <cstring>
//#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
typedef long long ll;
typedef unsigned long long ull;
#define gcd __gcd
const int INF=0x3f3f3f3f;
const ll LINF=1000000000000000000;
//priority_queue<int, vector<int>, greater<int> >p;
#define N 200005
ll n,m,l1,l2,k,sum=0,g,num,maxn,mid;
ll d[4][2]={1,0,-1,0,0,1,0,-1};
char s[100][100];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>s[i]+1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            if(s[i][j]=='.')continue;
            g=0;
            for(int k=0;k<=3;k++)
            {
                l1=i+d[k][0];
                l2=j+d[k][1];
                if(s[l1][l2]=='#'){g=1;break;}
            }
            if(!g)
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    cout<<"Yes"<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

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

        int w = sc.nextInt();
        int h = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();

        if(x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h)
            System.out.println("Yes");
        else    System.out.println("No");
    }
}


Measured memory_bytes: 26392
from collections import Counter

N = int(input())
divisor = []
mod = 10 ** 9 + 7


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


for i in range(N):
    divisor.extend(prime_factorize(i + 1))

c = list(Counter(divisor).values())
ans = 1

for i in c:
    ans = ans * (i + 1) % mod

print(ans)

Measured memory_bytes: 3316
n = int(input())
f = {}
for x in range(1, n + 1):
    for y in range(1, int(max((n - x**2), 0)**0.5) + 2):
        for z in range(1, int(max((n - x**2 - y**2), 0)**0.5) + 2):
            a = x**2 + y**2 + z**2 + x * y + y * z + z * x
            try:
                f[a] += 1
            except BaseException:
                f[a] = 1
for i in range(1, n + 1):
    try:
        print(f[i])
    except BaseException:
        print(0)


Measured memory_bytes: 71800
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 998244353;
ll dp[3010][3010];

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

int main(void){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    dp[a][b] = 1;
    FOR(i,a,c-1){
        // FOR(j,1,d){
        //     FOR(k,1,d){
        //         if (k <= j) (dp[i + 1][j] += dp[i][j]) %= mod;
        //         else (dp[i + 1][k] += dp[i][j] * powll(i, (k - j))) %= mod;
        //     }
        // }
        ll s = 0;
        FOR(j,1,d){
            (dp[i + 1][j] += s + j * dp[i][j]) %= mod;
            s = ((s + dp[i][j]) * i) % mod;
        }
    }

    // REP(i,c+1){
    //     REP(j,d+1) cout << dp[i][j] << " ";
    //     cout << endl;
    // }

    ll ans = 0;
    REP(j,d+1){
        (ans += dp[c][j] * powll(c, d - j)) %= mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 73928
#include <stdio.h>
#define N 100000

int A1[N];
char A2[N];
int input1[N];
char input2[N];

void swap1(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void swap2(char* a, char* b){
  char tmp = *a;
  *a = *b;
  *b = tmp;
}

int partition(int p, int r){
  int x = A1[r];
  int i = p - 1, j;
  for(j=p;j<r;j++){
    if(A1[j] <= x){
      i++;
      swap1(&A1[i], &A1[j]);
      swap2(&A2[i], &A2[j]);
    }
  }
  swap1(&A1[i+1], &A1[r]);
  swap2(&A2[i+1], &A2[r]);
  return i+1;
}

void quic_sort(int p, int r){
  if(p < r){
    int q = partition(p, r);
    quic_sort(p, q-1);
    quic_sort(q+1, r);
  }
}

int check(int n){
  int i, j;
  for(i=1;i<n;i++){
    if(A1[i-1] == A1[i]){
      int a, b;
      for(j=0;j<n;j++){
        if(A1[i-1] == input1[j] && A2[i-1] == input2[j]) a = j;
        if(A1[i] == input1[j] && A2[i] == input2[j]) b = j;
      }
      if(a > b) return 0;
    }
  }
  return 1;
}

main(){
  int n, i;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    getchar();
    scanf("%c%d", &A2[i], &A1[i]);
  }
  for(i=0;i<n;i++){
    input1[i] = A1[i];
    input2[i] = A2[i];
  }
  quic_sort(0, n-1);
  printf("%s\n", (check(n) ? "Stable" : "Not stable"));
  for(i=0;i<n;i++) printf("%c %d\n", A2[i], A1[i]);
  return 0;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


#define N 100001
vi par(N); //親
vi ran(N); //木の深さ
vl num(N); //木の要素数

		   //n要素で初期化
void init(int n) {
	int i;
	for (i = 0; i < n; i++) {
		par[i] = i;
		ran[i] = 0;
		num[i] = 1;
	}
}

//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	int nums = num[x] + num[y];
	if (x == y) {
		return;
	}
	if (ran[x]<ran[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (ran[x] == ran[y]) {
			ran[x]++;
		}
	}
	num[find(x)] = num[find(y)] = nums;
}

//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}



int main() {
	int n, m, i, j;
	cin >> n >> m;
	init(n);
	for (i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		unite(a, b);
	}
	ll n1 = num[find(0)], n2 = num[find(1)];
	if (n1 < n2) {
		swap(n1, n2);
	}
	ll ans = (n - n2)*(n - n2 - 1) / 2 + n2*(n2 - 1) / 2 - m;
	cout << ans << endl;
}

Measured memory_bytes: 1792
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,k = [int(i) for i in readline().split()]
d = [int(i) for i in readline().split()]

ng = [1 if i in d else 0 for i in range(10)]


for i in range(n,10**6):
    s = str(i)
    for j in s:
        if ng[int(j)]: break
    else:
        print(i)
        break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define MN 500000
#define mod 998244353
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,ans,p[MN+5],inv[MN+5];
inline int C(int n,int m){return m>n?0:1LL*p[n]*inv[m]%mod*inv[n-m]%mod;}
inline int pw(int x,int k)
{
    int res=1;
    for(;k;k>>=1,x=1LL*x*x%mod) if(k&1) res=1LL*res*x%mod;
    return res;
}
int main()
{
    n=read();m=read();p[0]=p[1]=inv[0]=inv[1]=1;if(n>m) swap(n,m);
    for(int i=2;i<=MN;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
    for(int i=2;i<=MN;++i) inv[i]=1LL*inv[i-1]*inv[i]%mod;
    for(int i=0;i<=n;++i)
    {
        int res=1LL*C(n,i)*pw(m+1,n-i)%mod*C(m,i)%mod*p[i]%mod*pw(n+1,m-i)%mod;
        if(~i&1) ans=(ans+res)%mod; else ans=(ans+mod-res)%mod;
    }
    cout<<ans;
    return 0;
}

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

using ll = long long;

int main() {
    ll N, K, MOD = 1e9 + 7;
    cin >> N >> K;
    vector<ll> A(N), l(N, 0), r(N, 0);;
    rep(i, N) cin >> A[i];
    rep(i, N) rep(j, N) {
        if (A[i] > A[j]) {
            if (j < i) l[i]++;
            else r[i]++;
        }
    }
    //rep(i, N) cout << l[i] << " " << r[i] << endl;
    ll ans = 0, x;
    rep(i, N) {
        x = ((K - 1) * K / 2) % MOD;
        x = (x * l[i]) % MOD;
        ans = (ans + x) % MOD;
        x = ((K + 1) * K / 2) % MOD;
        x = (x * r[i]) % MOD;
        ans = (ans + x) % MOD;
    }
    cout << ans << endl;
}

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

#define R 0
#define G 1
#define B 2

void print_col(int r, int g, int b)
{
  string col[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
  int c[][3] = {{0, 0, 0}, {0, 0, 255}, {0, 255, 0}, {0, 255, 255},
               {255, 0, 0}, {255, 0, 255}, {255, 255, 0}, {255, 255, 255}};
  double d = 1000000;
  double dd;
  int a = -1;

  for(int i = 0; i < 8; i++)
  {
    dd = pow(r - c[i][R], 2) + pow(g - c[i][G], 2) + pow(b - c[i][B], 2);
    if(dd < d)
    {
      d = dd;
      a = i;
    }
  }
  cout << col[a] << endl;
}

int to_num(char n)
{
  return n >= 'a' ? n - 'a' + 10 : n - '0';
}

int main()
{
  string s;
  int r, g, b;
  while(true)
  {
    cin >> s;
    if(s[0] == '0')
      break;
    r = to_num(s[1]) * 16 + to_num(s[2]);
    g = to_num(s[3]) * 16 + to_num(s[4]);
    b = to_num(s[5]) * 16 + to_num(s[6]);
    print_col(r, g, b);
  }
}

Measured memory_bytes: 1184
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

/*
100 099 098 097 096 095 094 093 092 091
065 064 063 062 061 060 059 058 057 090
066 037 036 035 034 033 032 031 056 089
067 038 017 016 015 014 013 030 055 088
068 039 018 005 004 003 012 029 054 087
069 040 019 006 001 002 011 028 053 086
070 041 020 007 008 009 010 027 052 085
071 042 021 022 023 024 025 026 051 084
072 043 044 045 046 047 048 049 050 083
073 074 075 076 077 078 079 080 081 082
*/

const int MAX_N = 1000;
const int MAX_N2 = MAX_N * MAX_N;

int caves[MAX_N][MAX_N]; // ここに置かないとSegmentation falutになる
pair<short, int> dp[MAX_N][MAX_N]; // 素数洞穴の数、最後に通った素数洞穴の番号
bool is_prime[MAX_N2 + 1];

// 入力
int n, m;

void sieve() {
	for (int i = 0; i <= MAX_N2; i++) {
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= MAX_N2; i++) {
		if (is_prime[i]) {
			for (int j = 2 * i; j <= MAX_N2; j += i) {
				is_prime[j] = false;
			}
		}
	}
	
	return;
}

// 初期化 素数表と洞穴を作成
void init() {
	sieve();
	int dx[4] = {1, 0, -1, 0};
	int dy[4] = {0, 1, 0, -1};
	
	int num = MAX_N2;
	int array = 0;
	int x = 0;
	int y = 0;
	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_N; j++) {
			caves[i][j] = 0;
		}
	}
	
	for (int i = num; i > 0; i--) {
		caves[y][x] = i;
		int tx = x + dx[array];
		int ty = y + dy[array];
		if (tx < 0 || tx >= MAX_N || ty < 0 || ty >= MAX_N || caves[ty][tx] != 0) {
			array = (array + 1) % 4;
		}
		x += dx[array];
		y += dy[array];
	}
	/*
	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_N; j++) {
			if (j > 0) {
				cout << " ";
			}
			printf("%7d", caves[i][j]);
		}
		cout << endl;
	}
	*/
	return;
}

void search(int sx, int sy) {
	for (int i = MAX_N - 1; i >= 0; i--) {
		for (int j = MAX_N - 1; j >= 0; j--) {
			if (caves[i][j] > m) {
				dp[i][j].first = 0;
				dp[i][j].second = 0;
				continue;
			}
			if (i == MAX_N - 1) {
				if (is_prime[caves[i][j]]) {
					dp[i][j].first = 1;
					dp[i][j].second = caves[i][j];
				} else {
					dp[i][j].first = 0;
					dp[i][j].second = 0;
				}
			} else {
				pair<short, int> tmp[3];
				for (int k = -1; k <= 1; k++) {
					if (j + k < 0 || j + k >= MAX_N) {
						tmp[k+1].first = 0;
						tmp[k+1].second = 0;
					} else {
						tmp[k+1].first = dp[i+1][j+k].first;
						tmp[k+1].second = dp[i+1][j+k].second;
					}
				}
				sort(tmp, tmp + 3, greater<pair<short, int> >());
				dp[i][j].first = tmp[0].first;
				dp[i][j].second = tmp[0].second;
				if (is_prime[caves[i][j]]) {
					dp[i][j].first++;
					if (dp[i][j].second == 0) {
						dp[i][j].second = caves[i][j];
					}
				}
			}
		}
	}
	return;
}

void solve(int sx, int sy) {
	search(sx, sy);
	cout << dp[sy][sx].first << " " << dp[sy][sx].second << endl;
}

int main() {
	init();
	while (true) {
		cin >> m >> n;
		if (m == 0) {
			break;
		}
		int sx, sy;
		for (int i = 0; i < MAX_N; i++) {
			for (int j = 0; j < MAX_N; j++) {
				dp[i][j].first = 0;
				dp[i][j].second = 0;
				if (caves[i][j] == n) {
					sx = j;
					sy = i;
				}
			}
		}
		solve(sx, sy);
	}
	
	return 0;
}

Measured memory_bytes: 13864
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
using namespace std;
int main(){
	int X,A,B;
	cin >> X >> A >> B;
	if(A>=B) cout << "delicious" << endl;
	else if(X+A-B >= 0) cout << "safe" << endl;
	else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int) n; i++)
#define repb(i, n) for (int i = (int) n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int) m; i < (int) n; i++)
#define repsb(i, m, n) for (int i = (int) m; i >= (int) n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
# define pb(a) push_back(a)
#define ll long long int
int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return 1; } return 0; }
template < class T > bool chmin(T & a,const T & b) { if (b < a) { a = b; return 1; } return 0; }
//vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));
using namespace std;
int main(int argc, char const * argv[]){
    int s,w;
    cin >>s>> w;
    if(s<=w) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;

    return 0;
}

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

int main(){
  int n, k; cin >> n >> k;
  vector<int> a(200010);
  for(int i = 0; i < n; i++){
    int c; cin >> c;
    a.at(c)++;
  }
  sort(a.rbegin(), a.rend());
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(i >= k) ans += a.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    l,r=map(int, input().split())
    ans=2019
    for i in range(l,min(l+2018,r)):
        for j in range(i+1,min(l+2019,r+1)):
            ans=min(ans,(i*j)%2019)
    print(ans)
resolve()


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

Measured memory_bytes: 3060
/**
* @author Ashini Singha
* IIT,Jahangirnagar University
*/
#include<bits/stdc++.h>
using namespace std;
#define     ll          long long int
#define     fo(i,b,n)   for(int i=(b); i<(n) ; i++)
#define     xx          first
#define     yy          second
#define     pb          push_back
#define     sz(n)       int(n.size())
#define     pii         pair
#define     MP          make_pair

#define     PI          acos(-1.0)

#define read(x)         scanf("%d",&x)
#define read2(x,y)      scanf("%d%d",&x,&y)
#define readl(x)        scanf("%lld",&x)
#define readl2(x,y)     scanf("%lld%lld",&x,&y)
#define readd(x)        scanf("%lf",&x)
#define readd2(x,y)     scanf("%lf%lf",&x,&y)

#define pr(n)           printf("%d",n)
#define prn(n)          printf("%d\n",n)
#define prl(n)          printf("%lld",n)
#define prln(n)         printf("%lld\n",n)
#define prd(x)          printf("%lf",x)
#define prdn(x)         printf("%lf\n",x)
#define TC(n) printf("Case %d: ",n)
/*_____________E_N_D______________*/


int main()
{
      int n, c, k;
      read(n);
      read2(c, k);
      vector<int>v;
      fo(i, 0, n) {
            int x;
            read(x);
            v.pb(x);
      }
      sort(v.begin(), v.end());

      ll time = v[0] + k;
      ll cnt = 0;
      ll bus = 0;



      fo(i, 0, n) {
            if(v[i] > time || cnt>=c ) {
                  //cout<<v[i]<<endl;
                  bus += (cnt / c);
                  if(cnt % c) bus++;
                  time = v[i] + k;
                  cnt = 1;
            } else {
                  cnt++;
            }
      }

      bus += (cnt / c);
      if(cnt % c)bus++;

      prln(bus);

      return 0;
}



























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

int main(){
int N, M;
  cin >> N >> M;
int x;
  if(M > N) x = (1900 * M) * pow(2,M);
  else x = ((N - M) * 100 + (1900 * M)) * pow(2,M);
  
  cout << x << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
s = []
for i in range(10):
    s.append(int(input()))
l = []
for i in range(10):
    l.append(int(input()))
    
a=sorted(s)[-1]
b=sorted(s)[-2]
c=sorted(s)[-3]
e=sorted(l)[-1]
d=sorted(l)[-2]
f=sorted(l)[-3]

print(a+b+c,end=' ')
print(e+d+f)


Measured memory_bytes: 5596
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int solve(){
	int ans = 0;

	bool V[MAX];
	for(int i=0;i<n;i++){
		B[i] = A[i];
		V[i] =false;
	}
	sort(B, B+n);
	for(int i=0;i<n;i++) T[B[i]] = i;
	for(int i=0;i<n;i++){
		if(V[i]) continue;
		int cur = i;
		int S = 0;
		int m = VMAX;
		int an = 0;
		while(1){
			V[cur] = true;
			an++;
			int v = A[cur];
			m = min(m,v);
			S += v;
			cur = T[v];
			if(V[cur]) break;
		}
		ans += min(S+(an-2)*m,m+S+(an+1)*s);
	}

	return ans;
}

int main(){
	cin >> n;
	s = VMAX;
	for(int i=0;i<n;i++){
		cin >> A[i];
		s = min(s,A[i]);
	}
	int ans = solve();
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3164
#include <stdio.h>

#define N 1000000
int a[N+1];
int main() {
	int n,i,j,r;
	for(i=2;i<=N;i++)if(!a[i])for(j=i+i;j<=N;j+=i)a[j]=1;
	while(~scanf("%d",&n)){
		r=0;
		for(i=2;i<=n;i++)if(!a[i])r++;
		printf("%d\n",r);
	}
	return 0;
}

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

long long gcd(long long a, long long b)
{
  while(b)
  {
    long long c = a;
    a = b;
    b = c % b;
  }
  return a;
}
int main()
{
  long long a, b;
  cin >> a >> b;
  cout << a / gcd(a, b) * b << endl;
  return 0;
}

Measured memory_bytes: 256
loop do
    h, w, n = gets.split.map(&:to_i)
    break if h == 0
    n -= 1
    a = (1..h).map { gets.split.map(&:to_i) }
    t = (1..h).map { Array.new(w, 0) }
    (0..h-1).each do |i|
        (0..w-1).each do |j|
            if i == 0 && j == 0
                t[i][j] = n
            end
            if a[i][j] == 0
                t[i+1][j] += (t[i][j] / 2.0).ceil  if i < h - 1
                t[i][j+1] += (t[i][j] / 2.0).floor if j < w - 1
            else
                t[i+1][j] += (t[i][j] / 2.0).floor if i < h - 1
                t[i][j+1] += (t[i][j] / 2.0).ceil  if j < w - 1
            end
        end
    end
    i = j = 0
    loop do
        if (a[i][j] + t[i][j]).even?
            i += 1
            break if i == h
        else
            j += 1
            break if j == w
        end
    end
    puts [i + 1, j + 1] * ' '
end



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

int main()
{
    while (1)
    {
        string s;
        cin >> s;
        if (s == "#")
            break;
        int y, m, d;
        cin >> y >> m >> d;
        if (y >= 32 || (y == 31 && m >= 5))
        {
            s = "?";
            y -= 30;
        }
        cout << s << " " << y << " " << m << " " << d << "\n";
    }
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<int> v(n+2);
    v[0]=0;
    rep(i, n) cin>>v[i+1];
    v[n+1]=0;
    vector<int> diff(n+1);
    rep(i, n+1){
        diff[i]=abs(v[i+1]-v[i]);
    }
    ll sum=accumulate(diff.begin(), diff.end(), 0LL);
    for(int i=1;i<=n;i++){
        ll ans=sum-diff[i-1]-diff[i]+(ll)abs(v[i+1]-v[i-1]);
        cout<<ans<<endl;
    }
    return 0;
    
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <fstream>

using namespace std;

int N;

int main(){
    cin >> N;
    char S[N];
    char T[N];
    cin >> S;
    cin >> T;

    for(int i=0;i<N;i++){
        cout << S[i] << T[i];
    }


}


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

static const int N = 100;
static const int INF = (1 << 30);
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;

int n;
int m[N][N];

void dijkstra(){
    int min_val;
    int d[N],color[N];

    for(int i=0;i<n;i++){
        d[i] = INF;
        color[i] = WHITE;
    }

    //始点設定
    d[0] = 0;
    color[0] = GRAY;

    while(1){
        min_val = INF;
        int u = -1;
        for(int i=0;i<n;i++){
            if(min_val > d[i] && color[i] != BLACK){
                u = i;
                min_val = d[i];
            }
        }

        if(u == -1) break;

        color[u] = BLACK;
        for(int v=0;v<n;v++){
            if(color[v] != BLACK && m[u][v] != INF){
                if(d[v] > d[u]+m[u][v]){
                    d[v] = d[u]+m[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

    for(int i=0;i<n;i++){
        cout << i << ' ';
        if(d[i] == INF)
            cout << -1;
        else
            cout << d[i];
        cout << endl;
    }

}

int main(){
    int u,k,v,c;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            m[i][j] = INF;
    }

    for(int i=0;i<n;i++){
        cin >> u >> k;
        for(int j=0;j<k;j++){
            cin >> v >> c;
            m[u][v] = c;
        }
    }

    dijkstra();

}



Measured memory_bytes: 3128