akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX;
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int i,j,max=0,n,sum;
	cin>>n;
	int a[2][n];
	rep(i,n)cin>>a[0][i];
	rep(i,n)cin>>a[1][i];
	for(i=0;i<n;i++){//曲がる場所 
		sum=0;
		for(j=0;j<=i;j++){
			sum+=a[0][j];
//			cout<<a[0][j]<<" ";
		}
		for(j=i;j<n;j++){
			sum+=a[1][j];
//			cout<<a[1][j]<<" ";
		}
//		cout<<endl;
		if(sum>max)max=sum;
	}
	cout<<max<<endl;
	
	
	
	
	
	
	
	
	
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int N;
int A[2][MAX_N];
int dp[2][MAX_N];

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

  cin >> N;
  REP(i, 2) REP(j, N) cin >> A[i][j];

  dp[0][0] = A[0][0];
  for (int j = 1; j < N; j++) {
    dp[0][j] = dp[0][j - 1] + A[0][j];
  }
  for (int j = 0; j < N; j++) {
    // 上からか左からか
    if (j - 1 < 0) {
      dp[1][j] = dp[0][j] + A[1][j];
    }
    else {
      dp[1][j] = max(dp[0][j], dp[1][j - 1]) + A[1][j];
    }
  }

  cout << dp[1][N - 1] << endl;

  return 0;
}


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

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

using namespace std;

int main(){
  int n;
  cin >> n;
  REP(i, n){
    set<string> strs;
    string target;
    cin >> target;
    REP(i, target.size()){
      if(i == 0) continue;
      string suba, subb;
      suba = target.substr(0, i);
      subb = target.substr(i, target.size() - i);
      strs.insert(suba + subb);
      strs.insert(subb + suba);
      reverse(ALL(suba));
      strs.insert(suba + subb);
      strs.insert(subb + suba);
      reverse(ALL(subb));
      strs.insert(suba + subb);
      strs.insert(subb + suba);
      reverse(ALL(suba));
      strs.insert(suba + subb);
      strs.insert(subb + suba);
    }
    cout << strs.size() << endl;
  }
  return 0;
}

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

public class Main{
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            while(true){
                int n = sc.nextInt();
                if(n==0){break;}
                int[] scores = new int[n];
                for(int i=0; i<n; i++){
                    int s = sc.nextInt();
                    scores[i] = s;
                }
                Arrays.sort(scores);
                int ave=0;
                for(int i=1; i<n-1; i++){
                    ave+=scores[i];
                }
                ave/=(n-2);
                System.out.println(ave);
            }
        }
    }
}


Measured memory_bytes: 29128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="Sunny")
        cout<<"Cloudy"<<endl;
    else if(s=="Cloudy")
        cout<<"Rainy"<<endl;
    else if(s=="Rainy")
        cout<<"Sunny"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;


import java.io.*;
/**
 * MLASERP
 */
public class Main {

    static int [] parent;
    static int [] size;
    static MyScanner in  = new MyScanner();
   static int mod  = 1000000007;
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      static StringTokenizer st;
      static int []dr  = {1,-1,0,0};
      static int [] dc = {0,0,-1,1};
      static int max =1;
public static void main(String[] args) {
    int N = in.nextInt();
    int M = in.nextInt();
    parent(N);
    for(int i=0;i<M;i++){
        int a = in.nextInt();
        int b = in.nextInt();
        union(a, b);
    }
    out.println(max);
   out.flush();
}
static int find_set(int v){
    if(v==parent[v])
        return v;
    return parent[v]=find_set(parent[v]);
}
static void union(int a, int b){
    a =find_set(a);
    b = find_set(b);
    if(a!=b){
        parent[b] =a;
        size[a]+=size[b];
        max = Math.max(size[a], max);
    }
}
static void parent(int V){
    parent = new int[V+1];
    size = new int[V+1];
    for(int i=0;i<=V;i++){
        parent[i] = i;
        size[i] = 1;
    }
}
public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
}

Measured memory_bytes: 57528
N = int(input())
D = list(map(int,input().split()))
MOD = 998244353

if D[0] != 0:
  print(0)
  exit()

D.sort()
ans = 1
count = {}
for i in range(N):
  if i > 0:
    if D[i]-1 in count:
      ans *= count[D[i]-1]
      ans %= MOD
    else:
      print(0)
      exit()
  if D[i] in count:
    count[D[i]] += 1
  else:
    count[D[i]] = 1
print(ans)


Measured memory_bytes: 61748
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();

        final int n = sc.nextInt();
        int[] inputNumbers = new int[n];
        int result = 1;

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

        Arrays.sort(inputNumbers);

        for (int i = 1; i < inputNumbers.length; i++) {
            if (inputNumbers[i] > inputNumbers[i - 1])
                result++;
        }
        System.out.println(result);
    }
}

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

main()
{
	int n; cin >> n;
	int a[n];
	
	rep(i, 0, n) cin >> a[i], a[i] -= i + 1;
	
	sort(a, a + n);
	int b = a[n >> 1];
	
	long long ans = 0;
	rep(i, 0, n) ans += abs(b - a[i]);
	cout << ans;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<stdio.h>
#include<vector>
#include<set>
#include<utility>
#include<ctype.h>
#include<ctime>
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
# define ll long long
using namespace std;
int gcd(int a,int b){
    int r;
    while(b){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int GCD(int a,int b)
{
    if(a==0) return b;
    else return GCD(b%a,a);
}
long long int power(long long int a,long long int b){
    long long int r=1;
    while(b){
        if(b & 1){
            r=r*a;
            b--;
        }
        a=a*a;
        b>>=1;
    }
    return r;
}
int palindrome(char *s,int len)
{
    int i,j,k,count=0,c=0;
    for(i=0,j=len-1;i<len,j>=0;i++,j--){
        if(s[i]==s[j]) count++;
    }
	if(count==len) return 1;
    	else return 0;
}
long long int binary(char *s,long long int len)
{
    long long int i,j,k,r=0,p=0,num;
    for(i=len-1;i>=0;i--){
        num=s[i]-'0';
        r+=(num*power(2,p));
        p++;
    }
    return r;
}
int binary_search(int *ara,int size,int n)
{
    int high,mid,low;
    low=0;
    high=size-1;
    while(low<=high){
        mid=(low+high)/2;
        if(ara[mid]==n){
            return 1;
        }
        else if(n>ara[mid]) low=mid+1;
        else if(n<ara[mid]) high=mid-1;
    }
    return -1;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	ll int i,j,k,n,T,q,mini=200000000000000000,a,b;
	string s1,s2;
	cin>>n>>a>>b;
	ll ara[n];
	for(i=0;i<n;i++) cin>>ara[i];
	vector<int>v;
	for(i=1,j=0;i<n;i++,j++){
        int x=ara[i]-ara[i-1];
        v.push_back(x);
	}
	ll int sum=0;
	for(i=0;i<v.size();i++){
        mini=min((v[i]*a),b);
        sum+=mini;
	}
	cout<<sum<<endl;
}



Measured memory_bytes: 1660
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {

	int A, B, C, K;
	int mainasu;
	int total;

	cin >> A >> B >> C >> K;

	if (A >= K)
	{
		cout << K;
	}
	else if (A + B >= K)
	{
		cout << A;
	}
	else
	{
		mainasu = K - (A + B);
		total = A - mainasu;

		cout << total;
	}

	return 0;

}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int, int>  P;

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

int h, w, c;

void Debug(const vector<vector<int>> &b)
{
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j)
            cout << b[i][j] << " ";
        cout << "\n";
    }
}


void Bfs(int cc, vector<vector<int>> &panel)
{
    vector<vector<bool>> visit(h, vector<bool>(w, false));

    int bf = panel[0][0];
    visit[0][0] = true;
    queue<P> que;
    que.push(make_pair(0, 0));


    while (!que.empty()) {
        P now = que.front();  que.pop();
        panel[now.second][now.first] = cc;

        for (int i = 0; i < 4; ++i) {
            int nx = now.first + dx[i];
            int ny = now.second + dy[i];

            if (nx < 0 || ny < 0 || nx >= w || ny >= h)
                continue;
            if (!visit[ny][nx] && panel[ny][nx] == bf) {
                que.push(make_pair(nx, ny));
                visit[ny][nx] = true;
            }
        }
    }
}

int Count(const vector<vector<int>> &panel)
{
    vector<vector<bool>> visit(h, vector<bool>(w, false));

    int cc = panel[0][0], res = 0;
    visit[0][0] = true;
    queue<P> que;
    que.push(make_pair(0, 0));

    while (!que.empty()) {
        P now = que.front();  que.pop();
        ++res;

        for (int i = 0; i < 4; ++i) {
            int nx = now.first + dx[i];
            int ny = now.second + dy[i];

            if (nx < 0 || ny < 0 || nx >= w || ny >= h)
                continue;
            if (!visit[ny][nx] && panel[ny][nx] == cc) {
                que.push(make_pair(nx, ny));
                visit[ny][nx] = true;
            }
        }
    }

    return res;
}

int Dfs(int cc, int cnt, vector<vector<int>> panel)
{
    if (cnt == 4 && panel[0][0] != c) {
        Bfs(c, panel);
        return Count(panel);
    }
    else if (cnt == 4)
        return 0;

    Bfs(cc, panel);
    int res = 0;
    for (int i = 1; i <= 6; ++i) {
        if (panel[0][0] == i)
            continue;
        res = max(res, Dfs(i, cnt + 1, panel));
    }

    return res;
}

int main()
{
    while (cin >> h >> w >> c, h || w || c) {
        vector<vector<int>> panel(h, vector<int>(w));

        for (int i = 0; i < h; ++i)
            for (int j = 0; j < w; ++j)
                cin >> panel[i][j];

        int res = 0;
        for (int i = 1; i <= 6; ++i) {
            if (panel[0][0] == i)
                continue;
            res = max(res, Dfs(i, 0, panel));
        }

        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 1224
use std::collections::HashMap;
#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(non_snake_case)]
fn main() {
    input![N: usize, A: [i32; N]];
    let mut map = HashMap::new();
    for a in &A {
        *map.entry(a).or_insert(0) += 1;
    }
    let ans = map
        .iter()
        .map(|(&k, &v)| if k <= &v { v - k } else { v })
        .fold(0, |sum, l| sum + l);
    println!("{}", ans);
}


Measured memory_bytes: 12540
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000

int main(){
	int N;
	cin>>N;
	
	long long K;
	cin>>K;
	
	vector<int> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	
	vector<int> last_ind(200001,-1);
	vector<int> next(N,-1);
	for(int i=0;i<N;i++){
		if(last_ind[A[i]]!=-1){
			next[last_ind[A[i]]] = i;
		}
		last_ind[A[i]] = i;
	}
	for(int i=0;i<N;i++){
		if(last_ind[A[i]]!=-1){
			next[last_ind[A[i]]] = i;
		}
		last_ind[A[i]] = i;
	}
	
	int shuuki = 1;
	int now = 0;
	while(true){
		int a = next[now];
		if(a<=now)shuuki++;
		if(a==N-1)break;
		now = a+1;
	}
	K--;
	K%=shuuki;
	
	now=0;
	if(K!=0){
		while(true){
			int a = next[now];
			if(a<=now){
				if(K==0)break;
				K--;
			}
			now = (a+1)%N;
		}
	}
	vector<int> ans(0);
	for(int i=now;i<N;i++){
		if(next[i]>i) i = next[i];
		else{
			ans.push_back(A[i]);
		}
	}
	for(int i=0;i<ans.size();i++){
		if(i!=0)cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;

		
	
	
	return 0;
	
}

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

int p[1000000] = {};

int main()
{
	int n;

	for (int i = 2; i <= 1000000; ++i)
	{
		if (p[i-2] == 0)
		{
			p[i-2] = 1;
			for (int j = i+i; j <= 1000000; j += i) p[j-2] = -1;
		}
	}

	while (cin >> n && n)
	{
		int r = 0;
		for (int i = 2; i <= n/2; ++i) if (p[i-2] == 1 && p[n-i-2] == 1) ++r;
		cout << r << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

ll x, k, d;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> x >> k >> d;
    x = abs(x);
    ll tmp = x / d;
    ll ans = 1e17;
    if (tmp > k) cout << abs(x - k * d), exit(0);
    if (tmp <= k) {
        if ((k - tmp) % 2 == 0) {
            ans = min(ans, x - tmp * d);
            if (k - tmp >= 2) ans = min(ans, abs(x - tmp * d - 2 * d));
        } else
            ans = min(ans, abs(x - tmp * d - d));
    }
    tmp = x / d + 1;
    if (tmp <= k) {
        if ((k - tmp) % 2 == 0)
            ans = min(ans, abs(x - tmp * d));
        else
            ans = min(ans, abs(x - tmp * d + d));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

ll acnt[51], pcnt[51];

ll solve(int n, ll x) {
	if (n == 0) return 1;
	
	ll res = 0;
	
	if (x == 1) return res;
	x--;
	
	if (x <= acnt[n - 1]) return res + solve(n - 1, x);
	x -= acnt[n - 1];
	res += pcnt[n - 1];
	
	if (x == 1) return res + 1;
	x--; res++;
	
	if (x <= acnt[n - 1]) return res + solve(n - 1, x);
	x -= acnt[n - 1];
	res += pcnt[n - 1];
	
	return res;
}

int main() {
	ll N, X;
	cin >> N >> X;
	
	acnt[0] = 1;
	pcnt[0] = 1;
	FOR(i, 1, N + 1) {
		acnt[i] = acnt[i - 1] * 2 + 3;
		pcnt[i] = pcnt[i - 1] * 2 + 1;
	}
	
	cout << solve(N, X) << endl;
	return 0;
}


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

int main() {
	
	long long s,c, n_max;
	
	
	
	cin >> s;
	cin >> c;
	
	// cが２つ未満ならsccはつくれない
	if ( c < 2 )
	{
		cout << 0 << endl;
		return 0;
	}
	
	// sを使ってsccをつくる
	n_max = s;
	
	//  cが少ない場合
	if ( c - s*2 < 0 )
	{
		cout << c / 2;
		return 0;
	}
	
	c -= s*2;
	
	// cを組み合わせてsccをつくる
	n_max += c / 4;
	
	
	cout << n_max;
	
	return 0;
}

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

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {

            var K = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            if (K < S.Length)
            {
                S = S.Substring(0, K) + "...";
            }

            Console.WriteLine(S);



#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}


Measured memory_bytes: 17632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int N,K;
    cin>>N>>K;
    vector<int> h(N);
    for(int i=0;i<N;i++)scanf("%d",&h[i]);
    sort(h.begin(),h.end());
    int mindif=1000000000;
    for(int i=0;i<N-K+1;i++){
        int dif=h[i+K-1]-h[i];
        mindif=min(mindif,dif);
    }
    cout<<mindif<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
    using namespace std;
    int main(){
		string s;
		int r=0,ans=0;
		cin>>s;
		for(int i=0;i<s.size();i++){
			if(r==0){
				r++;
				if(s[i]=='p'){
					ans--;
				}
			}
			else{
				r--;
				if(s[i]=='g'){
					ans++;
				}
			}
		}
		cout<<ans<<endl;
      return(0);
    }

Measured memory_bytes: 512
N = input()
list=[]
flg = 0 
for i in range(N):
    list.append(map(int, raw_input().split()))
if N == 1:
	rem = abs(list[0][1]) + abs(list[0][2])
	if rem == 1:
		print("Yes")
	else:
		print("No")
else:
	for i in range(N-1):
		rem = abs(list[i][1]-list[i+1][1]) + abs(list[i][2]-list[i+1][2])
		time = list[i+1][0]-list[i][0]
		if (time-rem) < 0:
			    flg = 1
		            break
		elif (time-rem) % 2 ==1:
			    flg = 1
		            break
		            
	if flg == 0:
		print("Yes")
	else:
		print("No")

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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] array = new int[n];
		int[] array_sort = new int[n];
		int p;
		int count = 0;
		String str = "YES";
		for (int i = 0; i < n; i++) {
			p = scan.nextInt();
			array[i] = p;
			array_sort[i] = p;
		}
		Arrays.sort(array_sort);
		for (int i = 0; i < n; i++) {
			if (array[i] != array_sort[i]) {
				count++;
				if (count == 3) {
					str = "NO";
					break;
				}
			}
		}
		System.out.println(str);

	}
}


Measured memory_bytes: 22868
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long ans = 0;
		for(long i = 1;i < N+1;i++){
			if(i % 3 != 0 && i % 5 != 0){
				ans += i;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35884
#include <stdio.h>
int main(void){

    int i,sum;
    char num[1001];
    
    for(;;){
        scanf("%s",&num);
        if(num[0]=='0')break;
    
    sum=0;
    for(i=0;num[i]!='\0';i++)
        sum+=num[i]-'0';
        printf("%d\n",sum);
        
    }
    return 0;
}



Measured memory_bytes: 2048
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/*
 * AtCoder Beginner Contest 102 C "Linear Approximation"
 */
public class Main {

	public static void main(String[] args) {

		InputScanner in = new InputScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = in.nextInt();
		int[] A = in.nextIntArray(N);

		int[] absA = new int[N];
		for (int i = 0; i < N; i++) {
			absA[i] = A[i] - (i + 1);
		}

		Arrays.parallelSort(absA);
		long ans = 0;
		for (int i = 0; i < N; i++) {
			ans += Math.abs(absA[i] - absA[N / 2]);
		}

		out.println(ans);

		in.close();
		out.close();

	}

	/*
	 * extends java.util.Scanner
	 */
	static class InputScanner{

		Scanner scanner;

		public InputScanner(InputStream inputStream) {
			this.scanner = new Scanner(inputStream);
		}

		public int nextInt() {
			return scanner.nextInt();
		}

		public long nextLong() {
			return scanner.nextLong();
		}

		public double nextDouble() {
			return scanner.nextDouble();
		}
		public String next() {
			return scanner.next();
		}

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

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

		public String[] nextStringArray(int n) {
			String[] ret = new String[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.next();
			}
			return ret;
		}

		public String[] nextStringArray(String splitStr) {
			String[] ret = scanner.next().split(splitStr);
			return ret;
		}

		public void close() {
			scanner.close();
		}
	}

}


Measured memory_bytes: 65304
import math

N, M, X = map(int, input().split())
C = []
A = []

for i in range(N):
    l = list(map(int, input().split())) 
    C.append(l[0])
    A.append(l[1:])

ans = math.inf

for i in range(2**N):
    a = [0]*M
    c = 0

    flag = True
    
    for j in range(N):
        if ((i >> j) & 1):
            a = list(map(sum, zip(a, A[j-1])))
            c += C[j-1]

    for x in a:
        if x < X:
            flag = False
            break
    
    if flag:
        ans = min(ans, c)

if ans == math.inf:
    ans = -1

print(ans)

Measured memory_bytes: 9196
n = int(input())
a = list(map(int, input().split()))
box = []
count = 0
zero = 0
for num in range(n):
    box.append(abs(a[num]))
for num in a:
    if num < 0:
        count += 1
    elif num == 0:
        zero += 1
box.sort()

if count % 2 == 0 or zero > 0:
    print(sum(box))
else:
    box[0] = -box[0]
    print(sum(box))

Measured memory_bytes: 14284
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int N_MAX = 10;
int main()
{
  int d,g,n,t,r,ii,i,j,res=1000;
  int p[N_MAX],c[N_MAX];
  bool f[N_MAX],ff;
  cin >> d >> g;
  n=1<<d;
  for(i=0;i<d;i++)
    cin >> p[i] >> c[i];
  for(i=0;i<n;i++){
    t=0; r=0; ii=i;
    for(j=0;j<d;j++){
      f[j]=ii%2;
      ii/=2;
      if(f[j]==1){
        t+=(j+1)*100*p[j]+c[j];
        r+=p[j];
      }
    }
    if(r>res) continue;
    ff=0;
    if(t<g)
      for(j=d-1;j>=0;j--)
        if(f[j]==0){
          if(t+(j+1)*100*p[j]<g){
            ff=1; break;
          }
          r+=(int)ceil((double)(g-t)/((j+1)*100));
          break;
        }
    if(ff==1) continue;
    if(r<res) res=r;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const int  N     =  5e5+5;
const int  mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const int  LEVEL =  log2(N)+1;

string s;

void solve(){
	cin >> s;
	if(s.back() == 's') s += "es";
	else s += 's';
	deb1(s)
}

int main(){
	GODSPEED;
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Measured memory_bytes: 3676
//frog2-->akash_codex
#include<iostream>
#include<math.h>
#include<climits>
typedef long long ll;
using namespace std;

int main(){
	ll n,k,start;
	cin>>n>>k;
	ll height[n+1],dp[n+1];
	for(ll i=0;i<=n;i++) dp[i]=INT_MAX;
	for(ll i=1;i<=n;i++) cin>>height[i];
	dp[1]=0;
	dp[2]=abs(height[2]-height[1]);
	for(ll i=3;i<=n;i++){
		if(k>=i) start=1;
		else start=i-k;
		for(ll j=start;j<i;j++) dp[i]=min(dp[i],dp[j]+abs(height[i]-height[j]));
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 5172
def p_factorization(n):
    if n == 1: return {}
    pf_cnt = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            pf_cnt[i] = cnt

    if temp != 1: pf_cnt[temp] = 1
    return pf_cnt


n = int(input())
pd = {}
for i in range(1,n+1):
    curr_p = p_factorization(i)
    for p,cnt in curr_p.items():
        pd.setdefault(p,0)
        pd[p] += cnt

ans = 0

cnt3 = 0
cnt5 = 0
cnt15 = 0
cnt25 = 0
cnt75 = 0

for v in pd.values():
    if v >= 74: cnt75 += 1
    if v >= 24: cnt25 += 1
    if v >= 14: cnt15 += 1
    if v >= 4: cnt5 += 1
    if v >= 2: cnt3 += 1


ans += cnt75
ans += max(cnt15*(cnt5-1), 0)
ans += max(0,cnt25*(cnt3-1))
ans += max(0,(cnt3-2)*(cnt5)*(cnt5-1)//2)
print(ans)

Measured memory_bytes: 62744
from bisect import bisect_right, bisect_left
from itertools import groupby, permutations, combinations
from fractions import gcd
import numpy as np
from sys import stdin, stderr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def main():
    N = int(input())
    st = dict()
    for i in range(1, N+1):
        str_i = str(i)
        s = int(str_i[-1])
        t = int(str_i[0])
        if s == 0:
            continue
        # if s > t:
        #     s, t = t, s
        num = s if s == t else s + t*10
        if num not in st:
            st[num] = 0
        st[num] += 1
    # print(st)
    ret = 0
    for k in st.keys():
        v = st[k]
        if k < 10:
            ret += v*v
        else:
            kk = (k % 10) * 10 + (k // 10)
            if kk in st:
                ret += v * st[kk]
            # else:
            #     print(k, kk)

    return ret


if __name__ == "__main__":
    print(main())

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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF INT_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

void atcoder(){
    const int MAXN=110,MAXV=101000;
    int N,W;
    cin>>N>>W;
    Vi w(N),v(N);
    REP(i,0,N) cin>>w[i]>>v[i];
    VVi dp(MAXN,Vi(MAXV,INF));
    dp[0][0]=0;
    REP(i,0,N){
        REP(j,0,MAXV){
            if(dp[i][j]<INF){
                chmin(dp[i+1][j],dp[i][j]);
                chmin(dp[i+1][j+v[i]],dp[i][j]+w[i]);
            }
        }
    }
    int ans=0;
    REP(i,0,MAXV) if(dp[N][i]<=W) ans=i;
    cout<<ans<<ENT;
}

signed main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

template<class T> void YES(T condition){ if(condition) OUT("YES"); else OUT("NO"); }
template<class T> void Yes(T condition){ if(condition) OUT("Yes"); else OUT("No"); }
template<class T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }

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

ll modpow(ll x,ll n,ll mod) {ll res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;};

const int MOD=1e9+7;
const int MAX = 700000;

struct Combination {
  vector<ll> fac,inv,finv;

  Combination() : fac(MAX),inv(MAX),finv(MAX) {
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    FOR(i,2,MAX) {
      fac[i] = fac[i-1]*i%MOD;
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
      finv[i] = finv[i-1]*inv[i]%MOD;
    }
  }

  int calc(int n, int k) {
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
  }
};

struct edge { int to,cost; };

int main() {
  // パスカルの三角形の斜番
  ll X,Y;cin>>X>>Y;
  // X軸よりに点を対称移動
  if (X<Y) swap(X,Y);
  // 最もX軸に近いところまで移動させる
  int k = 0;
  while (Y*2>X) {
    X++;Y--;
    k++;
  }

  // 対象外
  if (Y*2!=X) {
    OUT(0);
    return 0;
  }
  int n = X/2;

  // あとはC(n,k)のcomb
  Combination c = Combination();
  OUT(c.calc(n,k));

  return 0;
}

Measured memory_bytes: 16640
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

using llint = long long int;
using u64 = std::uint_fast64_t;

void solve(void){
  std::string s;
  std::cin >> s;

  int cnt = 0;
  if(s.find("R")   != std::string::npos) cnt = 1;
  if(s.find("RR")  != std::string::npos) cnt = 2;
  if(s.find("RRR") != std::string::npos) cnt = 3;
  
  std::cout << cnt << std::endl;
  
}
int main(void){
  solve();
  return 0;
}





Measured memory_bytes: 3628
N,M = map(int, input().split())
E = [[int(e) for e in input().split()] for _ in range(M)]

E.sort()
inf = 10**15
seg = [inf]*(2*N-1)

def update(k, x):
    k += N-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = min(seg[2*k+1], seg[2*k+2])
        
def query(p, q):
    p += N-1
    q += N-2
    res = inf
    while q-p > 1:
        if p&1 == 0:
            res = min(res, seg[p])
        if q&1 == 1:
            res = min(res, seg[q])
            q -= 1
        p //= 2
        q = (q-1)//2
    if p == q:
        res = min(res, seg[q])
    else:
        res = min(res, seg[p], seg[q])
    return res

update(0, 0)
for e in E:
    d = query(e[1]-1, N)
    l = query(e[0]-1, N)
    if l+e[2] < d:
        update(e[1]-1, l+e[2])

if seg[-1] == inf:
    print(-1)
else:
    print(seg[-1])

Measured memory_bytes: 80344
//ビット全探索

#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int H, W, K;
  cin >> H >> W >> K;
  vector <string> c(H);
  rep(i,H) cin >> c[i];

  int ans = 0;
  rep(is,1<<H)rep(js,1<<W){
    int cnt = 0;
    rep(i,H)rep(j,W){
      if (is>>i&1) continue;
      if (js>>j&1) continue;
      if (c[i][j] == '#') cnt ++;
    }
    if (cnt == K) ans ++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <stdio.h>

int main() {
  int a[10];
  for (int i = 0; i < 10; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < 10; i++) {
    for (int j = 9; j > i; j--) {
      if (a[j] > a[j - 1]) {
        int t = a[j];
        a[j] = a[j - 1];
        a[j - 1] = t;
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    printf("%d\n", a[i]);
  }
  return 0;
}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
int main(){
        int n,k;
        while(~getII(n,k)){
                int tot=(n-1)*(n-2)/2;
                if(k>tot){
                        puts("-1");
                        continue;
                }
                int m=n-1+(tot-k);
                printf("%d\n",m);
                FE(i,2,n) printf("1 %d\n",i);
                m-=(n-1);
                FE(i,2,n) FE(j,i+1,n){
                        if(m>0){
                                printf("%d %d\n",i,j);
                                m--;
                        }
                        else break;
                }
        }
}


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

int N;
int main(){
  pair <string,pair<int,int>> p[100];
  cin >> N;
  
  for (int i=0;i<N;i++){
    cin >> p[i].first >> p[i].second.first;
    p[i].second.first *= -1;
    p[i].second.second = i+1;
  }
  sort(p,p+N);
  
  
  for (int i=0;i<N;i++){
    cout << p[i].second.second << "\n";
  }
  return 0;
}



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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

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

    int ans = 0, res = 0;
    for(int i = 0; i < n - 1; i++)
    {
        if(h[i] >= h[i + 1])
            res++;
        else
            res = 0;
        ans = max(ans, res);
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 640
n= int(input())
bdic = {'A':0,'B':1,'O':2}
aot = [[0 for i in range(3)] for i in range(3)]
ans=0
for i in range(n):
    s=input()
    subab=0
    for i in range(len(s)-1):
        if s[i]=='A' and s[i+1]=='B':subab+=1
    ans += subab
    f = 'O' if not s[0]  in bdic.keys() else s[0]
    l = 'O' if not s[-1] in bdic.keys() else s[-1]
    aot[bdic[f]][bdic[l]]+=1

oa = aot[bdic['O']][bdic['A']]+aot[bdic['A']][bdic['A']]
bo = aot[bdic['B']][bdic['O']]+aot[bdic['B']][bdic['B']]
ab = aot[bdic['A']][bdic['B']]
ba = aot[bdic['B']][bdic['A']]

if   oa==0 and bo==0:ans+=max(0,ba-1)
elif oa==0 and bo!=0:ans+=min(bo,ba)+max(0,ba-bo)
elif bo==0 and oa!=0:ans+=min(oa,ba)+max(0,ba-oa)
else:                ans+=min(oa,bo)+ba
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define INF 1e9
#define PI 3.141592653589793238
#define N 1000000010
#define mod 1000000007
typedef long long ll;

int main() {
    int n,ans=0;cin>>n;
    string s;cin>>s;
    for(int i=0; i<n-2; i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

ll q[4];
ll n;

int main() {
	cin >> q[3] >> q[2] >> q[1] >> q[0] >> n;
	q[2] = min(q[2], 2 * q[3]);
	q[1] = min(q[1], 2 * q[2]);
	q[0] = min(q[0], 2 * q[1]);
	n *= 4;
	ll ans = 0;
	int now = 0;
	int cnt[4] = { 8,4,2,1 };
	while (n) {
		//cout << n << endl;
		if (n <= cnt[now])now++;
		if (now <= 3) {
			ans += q[now] * (n / cnt[now]);
			n -= cnt[now] * (n / cnt[now]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }



int main() {
  ll n,a,b; cin >> n >> a >> b;
  ll ans = n / (a + b)*a;
  ll re = n % (a+b);
  ans += min(re,a);
  cout << ans << endl;
	return 0;
  }

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    vector<bool>L(50000);
    for(int i=0;i<50000;i++)L[i]=true;
    L[0]=L[1]=false;
    for(int i=2;i<50000;i++){
        if(L[i]){
            for(int j=i*2;j<50000;j+=i)L[j]=false;
        }
    }
    int n;
    while(cin>>n&&n){
        if(n%2){
            cout<<L[n-2]<<endl;
            continue;
        }
        int cnt=0;
        for(int i=2;i<=n/2;i++){
            if(L[i]&&L[n-i])cnt++;
        }
        cout<<cnt<<endl;
    }


}

Measured memory_bytes: 1200
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
     sc.Scan()
     i, e := strconv.Atoi(sc.Text())
     if e != nil {
     	panic(e)
     }
     return i
}

func gcd(a, b int) int{
     if b == 0 {
     	return a
     } else {
        return gcd(b, a % b)
     }
}

func gcd3(a, b, c int) int{
     return gcd(a, gcd(b, c))
}

func main() {
     sc.Split(bufio.ScanWords)
     n := nextInt()

     ans := 0

     for i := 1; i <= n; i++{
     	 ans += i
     }

     for i := 1; i <= n; i++{
     	 for j := i+1; j <= n; j++{
	     ans += 6 * gcd(i,j)
	 }
     }

     for i := 1; i <= n; i++{
     	 for j := i+1; j <= n; j++{
	     for k := j+1; k <= n; k++{
	     	 ans += 6 * gcd3(i,j,k)
	     }
	 }
     }

     fmt.Println(ans)
}  

Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;


int main(){
    int list[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;

    cout << list[k - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int H, W, ra, o, a[40][40], sum[40][40], dp[40][40][40][40];
inline int rng(int x1, int y1, int x2, int y2) {
	return sum[y2][x2] + sum[y1][x1] - sum[y2][x1] - sum[y1][x2];
}
int solve(int x1, int y1, int x2, int y2) {
	if (dp[y1][x1][y2][x2] != -1) return dp[y1][x1][y2][x2];
	int rng_ = rng(x1, y1, x2, y2);
	int ret = 1000000 + rng_;
	for (int i = x1 + 1; i < x2; i++) {
		int petl = rng(x1, y1, i, y2);
		int petr = rng(i, y1, x2, y2);
		if (min(petl, petr) >= o) {
			int resl = solve(x1, y1, i, y2);
			int resr = solve(i, y1, x2, y2);
			int res = (resl / 1000000 + resr / 1000000) * 1000000 + min(resl % 1000000, resr % 1000000);
			ret = max(ret, res);
		}
	}
	for (int i = y1 + 1; i < y2; i++) {
		int petl = rng(x1, y1, x2, i);
		int petr = rng(x1, i, x2, y2);
		if (min(petl, petr) >= o) {
			int resl = solve(x1, y1, x2, i);
			int resr = solve(x1, i, x2, y2);
			int res = (resl / 1000000 + resr / 1000000) * 1000000 + min(resl % 1000000, resr % 1000000);
			ret = max(ret, res);
		}
	}
	return dp[y1][x1][y2][x2] = ret;
}
int main() {
	while (cin >> H >> W >> ra, H) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) cin >> a[i][j];
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + a[i][j];
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				for (int k = i + 1; k <= H; k++) {
					for (int l = j + 1; l <= W; l++) dp[i][j][k][l] = -1;
				}
			}
		}
		o = sum[H][W] - ra;
		int ret = solve(0, 0, W, H);
		cout << ret / 1000000 << ' ' << ret % 1000000 - o << endl;
	}
}

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

#define vi vector<int>
#define pb push_back

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(0,min(b,d)-max(a,c)) << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.Set as S

main :: IO ()
main = do
    [n, m] <- getInts
    edges <- fmap sort $ forM [1..m] $ \_ -> do
        [a, b] <- getInts
        pure (a, b)
    putStrLn $ if fst (edges !! 0) /= 1
                    then "0"
                    else show $ solve 1 [2..n] $ S.fromList edges


type Node = Int
type Edge = (Node, Node)

solve :: Node -> [Node] -> S.Set Edge -> Int
solve _ [] _ = 1
solve current unvisited edges =
    if S.null edges
       then 0
       else sum $ map go nextNodes
    where
        nextTarget = S.map fromJust . S.delete Nothing $ S.map (getConnected current) edges
        nextNodes = map fst $ S.toList nextTarget
        nextEdges = S.map snd nextTarget
        go nextNode = solve nextNode (filter (/= nextNode) unvisited) $ S.difference edges nextEdges

{-
solve :: Node -> [Node] -> [Edge] -> Int
solve _ [] _ = 1
solve _ _ [] = 0
solve current unvisited edges =
    sum $ map go nextTarget
    where
        nextTarget = mapMaybe (getConnected current) edges
        nextNodes = map fst nextTarget
        nextEdges = map snd nextTarget
        go (nextNode, nextEdge) = solve nextNode (filter (/= nextNode) unvisited) (filter (/= nextEdge) edges)
-}

getConnected :: Node -> Edge -> Maybe (Node, Edge)
getConnected current e@(a, b)
    | current == a = Just (b, e)
    | current == b = Just (a, e)
    | otherwise = Nothing

getInts :: IO [Int]
getInts = map read . words <$> getLine


Measured memory_bytes: 1020
#include<stdio.h>

int main(void){

    int r,c,i=0,j=0;
    scanf("%d %d", &r, &c);
    int R,C;
    R=r+1;
    C=c+1;
    int D[R][C];

    for(i=0;i<r+1;i++){
        for(j=0;j<c+1;j++){
            D[i][j]=0;
        }
    }

    for(i=0;i<r;i++){
        for(j=0;j<c+1;j++){
            if(j<c){
                scanf("%d", &D[i][j]);
                D[r][j]+=D[i][j];
                D[i][c]+=D[i][j];
            }else{
                break;
            }

        }
        D[r][c]+=D[i][c];
    }

    for(i=0;i<r+1;i++){
        for(j=0;j<c+1;j++){
            if(j==c){
                printf("%d",D[i][j]);
            }else{
            printf("%d ",D[i][j]);
            }
        }
        printf("\n");
    }


    return 0;
}


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

int main(){
    int N, L;
    cin >> N >> L;
    int knot[N];
    for(int i = 0; i < N; i++){
        cin >> knot[i];
    }
    for(int i = 0; i < N - 1; i++){
        if(knot[i] + knot[i + 1] < L){
            continue;
        }
        cout << "Possible" << endl;
        for(int j = 0; j < i; j++){
            cout << j + 1 << endl;
        }
        for(int j = N - 2; j >= i; j--){
            cout << j + 1 << endl;
        }
        return 0;
    }
    cout << "Impossible" << endl;
}


Measured memory_bytes: 1152
from collections import deque

n, m = map(int,input().split())
turo = [[] for i in range(n+1)]
sirusi = [-1 for i in range(n+1)]

for i in range(m):
    tmp = list(map(int,input().split()))
    turo[tmp[0]].append(tmp[1])
    turo[tmp[1]].append(tmp[0])

sirusi[1] = 0

q = deque()
q.append(1)

while len(q) != 0:
    x = q.popleft()
    for i in turo[x]:
        if sirusi[i] == -1:
            sirusi[i] = x
            q.append(i)

print('Yes')
for i in range(n+1):
    if i != 0 and i != 1:
        print(sirusi[i])


Measured memory_bytes: 34048
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  string s;
  cin>>s;
  repn(i,s.size()-1){
    if(s[i]=='r'){
      if(s[i-1]!='e'){cout<<"NO"<<endl;return 0;}
      if(s[i-2]=='s'){
	if(s[i-3]=='a' && s[i-4]=='r' && s[i-5]=='e') i-=5;
	else{cout<<"NO"<<endl;return 0;}
      }
      else if(s[i-2]=='m'){
	if(s[i-3]=='a' && s[i-4]=='e' && s[i-5]=='r' && s[i-6]=='d') i-=6;
	else{cout<<"NO"<<endl;return 0;}
      }
    }else if(s[i]=='m'){
      if(s[i-1]=='a' && s[i-2]=='e' && s[i-3]=='r' && s[i-4]=='d') i-=4;
      else{cout<<"NO"<<endl;return 0;}
    }else if(s[i]=='e'){
      if(s[i-1]=='s' && s[i-2]=='a' && s[i-3]=='r' && s[i-4]=='e') i-=4;
      else{cout<<"NO"<<endl;return 0;}
    }
    else{cout<<"NO"<<endl;return 0;}
  }
  cout<<"YES"<<endl;
  return 0;
}





Measured memory_bytes: 512