akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>

using namespace std;

int main() {
    int a, b, cnt = 0;
    vector< vector<int> > e(5);
    for (int i = 0; i < 3; ++i) {
        scanf("%d%d", &a, &b);
        e.at(a).push_back(b);
        e.at(b).push_back(a);
    }
    for (int i = 1; i <= 4; ++i) if (e.at(i).size() == 1) ++cnt;
    printf("%s\n", (cnt == 2 ? "YES" : "NO"));
    return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.rbegin(), a.rend());
  
  ll ans = 0;
  if (n % 2 == 0) {
    for (int i = 0; i < n; i++) {
      if (i < n / 2 - 1) ans += 2 * a.at(i);
      else if (i == n / 2 - 1) ans += a.at(i);
      else if (i == n / 2) ans -= a.at(i);
      else ans -= 2 * a.at(i);
    }
  }
  else {
    ll keep1 = 0, keep2 = 0;
    for (int i = 0; i < n; i++) {
      if (i < n / 2 - 1) keep1 += 2 * a.at(i);
      else if (i == n / 2 || i == n / 2 - 1) keep1 += a.at(i);
      else keep1 -= 2 * a.at(i);
    }
    for (int i = 0; i < n; i++) {
      if (i < n / 2) keep2 += 2 * a.at(i);
      else if (i == n / 2 || i == n / 2 + 1) keep2 -= a.at(i);
      else keep2 -= 2 * a.at(i);
    }
    ans = max(keep1, keep2);
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 1024
n = int(input())
s = input()
cnt = 0
for i in range(1000):
    p = '{:03}'.format(i)
    s2 = s
    for j in range(3):#indexのループ
        if s2.find(p[j]) == -1:
            break
        s2 = s2[s2.find(p[j]) +1:]
    else:
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin>>n>>k;
    vector<int> h;
    int s;
    rep(i, n){
        cin>>s;
        h.eb(s);
    }
    sort(all(h));
    int mi = h[k-1]-h[0];
    for(int i = 1; i < n-k+1;  i++){
        if(h[i+k-1]-h[i] < mi){
            mi = h[i+k-1]-h[i];
        }
    }
    cout<<mi<<endl;
    return 0;
}

Measured memory_bytes: 892
a, b, c = sorted(map(int, input().split()), reverse=True)

parity = (a + b + c) % 2 # 総和の偶奇
m3 = (a*3) % 2 # 最大値×3の偶奇

if parity == m3:
    x = a
else:
    x = a + 1

print((x*3 - (a+b+c)) // 2)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <queue>

using namespace std;

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

void out(int x) {
     if (x == 1)
        cout << "First\n";
     if (x == 2)
        cout << "Second\n";
     cout.flush();
     cin >> x;
     exit(0);
}

int n;
vector<vector<int> > gr;
vector<int> kol;

void dfs(int v, int pr) {
    kol[v] = 1;
    int k = 0;
    for (int i = 0; i < (int)gr[v].size(); ++i) {
        int nv = gr[v][i];
        if (nv == pr)
           continue;
        dfs(nv, v);
        kol[v] += kol[nv];
        k += (kol[nv]&1);
    }
    if (pr >= 0)
       k += ((n - kol[v])&1);
    if (k >= 2)
       out(1);
}

int main() {
    scanf("%d", &n);
    gr.assign(n, vector<int>());
    for (int i = 1; i < n; ++i) {
        int v1, v2;
        scanf("%d%d", &v1, &v2);
        --v1;
        --v2;
        gr[v2].push_back(v1);
        gr[v1].push_back(v2);
    }
    if (n&1)
       out(1);
    kol.assign(n, 0);
    dfs(0, -1);
    out(2);
    return 0;
}


Measured memory_bytes: 6272
package main

import "fmt"

func main() {
    var a, b, c int
    var divs int = 0

    fmt.Scanf("%d %d %d", &a, &b, &c)
    for i:=a; i<=b; i++ {
        if c % i == 0 {
            divs++
        }
    }

    fmt.Println(divs)
}


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

using namespace std;

typedef int64_t ll;
#define For(i, a, b) for(ll i = a; i <= b; i++)

bool ok1 = 1, ok2 = 0;
ll n, res, arr[1000010];
unordered_map <ll, ll> P;

void PrimeDefactorizeProcess(ll u)
{
    For(i, 2, sqrt(u) + 1)
    if (u > 1 && u % i == 0)
    {
        while (u % i == 0) u /= i;
        P[i]++;
    }
    if (u > 1) P[u]++;
}

void process()
{
    For(i, 1, n)
    PrimeDefactorizeProcess(arr[i]);
    for(unordered_map <ll, ll>::iterator iter = P.begin(); iter != P.end(); iter++)
        if (iter->second > 1) ok1 = 0;
    res = arr[1];
    For(i, 2, n)
    res = __gcd(res, arr[i]);
    if (res == 1) ok2 = 1;
    if (ok1)
        cout << "pairwise coprime" << "\n";
    else
        if (ok2)
            cout << "setwise coprime" << "\n";
        else
            cout << "not coprime" << "\n";
}

void input()
{
    cin >> n;
    For(i, 1, n)
    cin >> arr[i];
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
    input();
    process();
}

Measured memory_bytes: 14372
#include<stdio.h>
int main()
{
    int a, b, t;
    while(1){
        scanf("%d%d", &a, &b);
        if(a == 0 && b == 0){
            break;
        }
        else if(a > b){
            t = a;
            a = b;
            b = t;
        }
        printf("%d %d\n", a, b);
    }
    return 0;
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define nod first
#define cost second

const int MAXN = (int) 1e5;

std::vector < std::pair <int, int> > g[MAXN + 1];

bool viz[MAXN + 1];
long long sp[MAXN + 1];

void dfs(int nod) {
    viz[nod] = 1;
    for(auto it : g[nod])
       if(viz[it.nod] == 0) {
            sp[it.nod] = sp[nod] + it.cost;
            dfs(it.nod);
       }
}

int main() {
    FILE * fi, * fout;
    int i, n, q, a, b, c, k;
    //fi = fopen("A.in" ,"r");
    //fout = fopen("A.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%d" ,&n);
    for(i = 1; i < n; i++) {
        fscanf(fi,"%d%d%d" ,&a,&b,&c);
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }
    fscanf(fi,"%d%d" ,&q,&k);
    dfs(k);
    while(q) {
        q--;
        fscanf(fi,"%d%d" ,&a,&b);
        fprintf(fout,"%lld\n" ,sp[a] + sp[b]);
    }
    //fclose(fi);
    //fclose(fout);
    return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <math.h>
using namespace std;
#define PI 3.14159265358979323846L

int main(){
  int A;
  int B;
  int H;
  int M;
  long double distance;
  cin >> A >> B >> H >> M;
  long double t = 60.0 * (long double)H + (long double)M;
  long double rad = 2 * PI * (1/60.0-1/720.0) * t;
  distance = (long double)(A*A + B*B)-(long double)(2* A*B)*cos(rad);
  printf("%.15Lf", sqrt(distance));
  return 0;
}

Measured memory_bytes: 3508
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;

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

    char c;
    cin>>c;
    if(c>='A'&&c<='Z'){cout<<"A";}
    else{cout<<"a";}

    return (0);
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(ll i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
    ll l,r;
    cin>>l>>r;

    ll v;
    if(r-l+1>=2019 || l%2019>=r%2019) v=0;
    else{
        v=2019;
        REP2(i,l,r){
            REP2(j,i+1,r+1){
                v=min(v,(i*j)%2019);
            }
        }
    }

    cout<<v<<endl;

	return 0; 
}


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

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    vector<long long> b(n);
    vector<long long> c(n);
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    for (int i=0;i<n;i++){
        cin >> b[i];
    }
    for (int i=0;i<n;i++){
        cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    long long acc = 0;
    for (auto &b_i : b){
        acc += (lower_bound(a.begin(), a.end(), b_i) - a.begin()) * (c.end() - upper_bound(c.begin(), c.end(), b_i));
    }

    cout << acc << endl;
    return 0;
}

Measured memory_bytes: 2560
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=(1<<20)+5;
int f[25][N],g[N],is[25][25],nxt[N][25],n,m,k,res,lim;
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d%d",&n,&m,&k),--n,lim=(1<<n);
	memset(is,-1,sizeof(is));
	for(R int i=1,a,b,c;i<=k;++i)scanf("%d%d%d",&a,&b,&c),is[a][b-1]=c;
	fp(s,0,lim-1){
		R int p=-1;
		fd(i,n-1,0){
			if(s>>i&1)p=i;
			nxt[s][i]=p;
		}
	}
	f[n][0]=1;
	fp(i,1,m){
		fp(j,0,lim-1)g[j]=f[n][j];
		memset(f,0,sizeof(f));
		fp(j,0,lim-1)f[0][j]=g[j];
		fp(j,0,n-1)fp(k,0,lim-1)if(f[j][k])
			fp(l,0,1){
				if(is[i][j]!=-1&&l!=is[i][j])continue;
				R int t=k>>j&1;
				if(l==0&&t==1)continue;
				if(l==t)upd(f[j+1][k],f[j][k]);
				else{
					R int p=nxt[k][j];
					if(p==-1)upd(f[j+1][k|(1<<j)],f[j][k]);
					else upd(f[j+1][k^(1<<j)^(1<<p)],f[j][k]);
				}
			}
	}
	fp(i,0,lim-1)upd(res,f[n][i]);
	printf("%d\n",res);
	return 0;
}

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

int main() {
    ll n;
    cin >> n;
    vector<ll> cnt(10001000, 1);
    for (ll i = 2; i <= n; ++i) {
        for (ll j = 1; i * j <= 10001000; ++j) {
            ++cnt[i * j];
        }
    }
    ll ans = 0;
    for (ll i = 1; i <= n; ++i) {
        ans += i * cnt[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 81376
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


class CumulativeSum {
  private:
    int H_, W_;
    std::vector<std::vector<long long>> s;

  public:
    explicit CumulativeSum (int H, int W) : H_(H), W_(W) {
      s.resize(H+1); for(int i=0; i<=H; i++) s[i].resize(W+1);
      s[0][0] = 0;
      for(int i=0; i<=H_; i++) s[i][0] = 0;
      for(int i=0; i<=W_; i++) s[0][i] = 0;
    }

    void set(int i, int j, long long a) {
      s[i+1][j+1] += a;
      return;
    }

    void build() {
      for(int i=0; i<=H_; i++) for(int j=1; j<=W_; j++) s[i][j] += s[i][j-1];
      for(int i=1; i<=H_; i++) for(int j=0; j<=W_; j++) s[i][j] += s[i-1][j];
    }

    void build ( const std::vector<std::vector<long long>> &a ) {
      for(int i=1; i<=H_; i++) for(int j=1; j<=W_; j++) s[i][j] = a[i-1][j-1];
      for(int i=0; i<=H_; i++) for(int j=1; j<=W_; j++) s[i][j] += s[i][j-1];
      for(int i=1; i<=H_; i++) for(int j=0; j<=W_; j++) s[i][j] += s[i-1][j];
    }

    // h : [i,j],  w : [k,m]
    long long Get(int i, int j, int k, int m) {
      return s[j+1][m+1] - s[i][m+1] + s[i][k] - s[j+1][k];
    }
};


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll N, K; std::cin >> N >> K;
  std::vector<ll> x(N), y(N);
  std::vector<char> c(N);
  rep(i,N) std::cin >> x[i] >> y[i] >> c[i];

  rep(i,N) if ( c[i] == 'W' ) y[i] += K;

  rep(i,N) x[i] %= (2*K);
  rep(i,N) y[i] %= (2*K);

  CumulativeSum S(4*K, 4*K);
  rep(i,N) {
    S.set(x[i], y[i], 1);
    S.set(x[i]+2*K, y[i], 1);
    S.set(x[i], y[i]+2*K, 1);
    S.set(x[i]+2*K, y[i]+2*K, 1);
  }
  S.build();

  int ans = 0;
  for(int x=0; x<2*K; x++) for(int y=0; y<2*K; y++) {
    int a = S.Get(x,   x+K-1,   y,   y+K-1);
    int b = S.Get(x+K, x+K+K-1, y+K, y+K+K-1);
    ans = std::max(ans, a+b);
  }
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 127104
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int A, B, C, K;
  	cin >> A >> B >> C >> K;
  
  	if(K<=A){
    	cout << K << endl;
    }
  
  	else {
    	if (K<=A+B){
        	cout << A << endl;
        }
      
      	else{
        	cout << A*2+B-K <<endl;
        }
    }
}

Measured memory_bytes: 3564
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] b = new int[n];
        int fro = n / 2 - 1;
        int bac = n / 2;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if(i % 2 != 0){
                b[fro--] = a;
            }else{
                b[bac++] = a;
            }
        }

        if(n % 2 == 0){
            for (int i = 0; i < n; i++) {
                System.out.print(b[i] + " ");
            }
        }else{
            for (int i = 0; i < n; i++) {
                System.out.print(b[n-i-1] + " ");
            }
        }
        sc.close();
    }

}


Measured memory_bytes: 93092
n,m = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)
a = Array.new(n){|i|i}
b = Hash.new{|h,k|h[k] = [k]}

m.times do
    x,y = gets.split.map{|i|i.to_i-1}
    next if a[x] == a[y]
    x,y = y,x if b[a[x]].size > b[a[y]].size
    b[a[x]].each do |i|
        a[i] = a[y]
        b[a[y]] << i
    end
end

ans = 0
n.times do |i|
    ans += 1 if a[i] == a[p[i]-1]
end
puts ans

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

using namespace std;

int main(void){
    int N;
    cin>>N;
    vector<char> s(N);
    for(int i=0;i<N;i++){
        cin>>s[i];
    }
    int count=0;
    for(int i=0;i<N-1;i++){
        if(s[i]==s[i+1]) count++;
    }
    cout<<N-count<<endl;
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace D_ABC158
{
    class MainClass
    {

        static int[] n;

        public static void Main(string[] args)
        {
            string s = ReadLine();

            n = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);

            int nowdir = 1;

            var ll = new LinkedList<char>();
            foreach (Char c in s)
            {
                ll.AddLast(c);
            }

            for (int i = 0; i < n[0]; i++)
            {
                char[] q = Array.ConvertAll(ReadLine().Split().ToArray(), char.Parse);
                if (q[0] == '1')
                {
                    nowdir = nowdir * -1;
                }
                else
                {
                    if (nowdir == 1 ^ q[1] == '1')
                    {
                        ll.AddLast(q[2]);
                    }
                    else
                    {
                        ll.AddFirst(q[2]);
                    }
                }

            }

            if (nowdir == 1)
            {
                string ans = new string(ll.ToArray());
                WriteLine(ans);
            }
            else
            {
                var lll = ll.ToArray();
                Array.Reverse(lll);
                string ans = new string(lll);
                WriteLine(ans);
            }
        }
        static string Reverse(string s)
        {
            char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }
    }


}


Measured memory_bytes: 34716
#include<stdio.h>

int main () {
	
	
	char input[5];
	
	scanf("%[^\n]",&input);fflush(stdin);
	if (input[0] == 'H') {
		if (input[2] == 'H') printf("H");
		else printf("D");
	} else {
		if (input[2] == 'H') printf("D");
		else printf("H");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k,a,b;
	cin>>k>>a>>b;
	if((a+k-1)/k*k<=b) cout<<"OK";
	else cout<<"NG";
	return 0;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        String str = lines[0];
        String[] str1 = str.split(" ");
        int a = Integer.parseInt(str1[0]);
        int b = Integer.parseInt(str1[1]);
        int c = Integer.parseInt(str1[2]);

        if (a < b && b < c){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    
    }

  
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
  
}



Measured memory_bytes: 26364
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=3e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n,a[N],b[N];
void input()
{
	n=read<int>();
	For(i,1,n)a[i]=read<int>(),b[i]=(a[i]==i);
}
bool check(int l,int r)
{
	int L=0,R=0;
	For(i,l,r)
	{
		if(a[i]<l||a[i]>r)return false;
		if(a[i]<i)
		{
			if(L>a[i])return false;
			L=a[i];
		}
		else if(a[i]>i)
		{
			if(R>a[i])return false;
			R=a[i];
		}
	}
	return true;
}
void work()
{
	For(i,2,n-1)if(!b[i-1]&&!b[i]&&!b[i+1]){puts("No");return;}
	int r,now;
	For(l,1,n)if(b[l]==0)
	{
		r=l;now=1;
		while(r<n&&b[r+1]==now)r++,now^=1;
		if(!check(l,r)){puts("No");return;}
		l=r;
	}
	puts("Yes");
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


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

using namespace std;

int main(void) {
    int a,b,i,n,j,c=0;

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


    }

    for(i=0;i<n;i++){
            for(j=i+1;j<n;j++)
            c=c+(s[i]*s[j]);
    }
    cout << c << endl;
   return 0;
}


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

int main()
{
  while(1)
    {
      int n = 0,mx=-1,mn=1001;
      cin >> n;
      if(n==0)break;
      int avr = 0;
      for(int i=0;i<n;i++)
	{
	  int b;
	  cin >> b;
	  mx =max(b,mx);
	  mn =min(b,mn);
	  avr +=b;
	}
      cout << (avr - mx -mn) /(n -2) << endl;
    }
    


  return 0;
}


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

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

    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++) {
    	cin >> v[i];
    }
    int minnum = v[0];
    int ans = 0;
    for(int i = 0; i < n; i++) {
    	if(v[i] <= minnum) {
          ans++;
          minnum = v[i];
    	}
    }
    cout << ans << endl;
}

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


int main(){
    int a1,a2,a3,ans;
    cin >> a1 >> a2 >> a3;
    ans = a1+a2+a3;
    if(ans >= 22){
        cout << "bust";
    }else{
        cout << "win";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int INF = 1e9;

int main() {
	
	
    int n,k;
    cin>>n>>k;
    int h[n+1];
    for (int i=1; i<=n; i++){
    	cin>>h[i];
    }
    vector<int> dp(n+1, INF);
    
    dp[1]=0;
    for (int i=1; i<=n;i++){
    	for (int j=1; j<=k; j++){
    		if (i+j<=n){
    			dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j]-h[i]));	
    		}
    	}
    }
    cout<<dp[n];
}

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

int main(void) {
	long long int N,A,i,tmp,ans=1000000000000;
	scanf("%lld",&N);
	A=sqrt(N);
	for(i=A;i>0;i--){
		if(N%i==0){
			tmp=(i+N/i);
			if(ans>tmp){
				ans=tmp;
			}
			
		}
	}
	printf("%lld",ans-2);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define nn 1000008 
#define mod 998244353
int f[nn],rf[nn];
int qpow(int x,int y=mod-2){
	int res=1;while(y){
		if(y&1) res=res*x%mod;
		x=x*x%mod;y=y/2;
	}
	return res;
}
void add(int&x,int y){
	x=(x+y)%mod;
}
int C(int x,int y){
	return f[x]*rf[y]%mod*rf[x-y]%mod;
}
int walk(int x,int y){
	return C(x+y,x);
}

signed main(){
	f[0]=rf[0]=1;for(int i=1;i<nn;i++) f[i]=f[i-1]*i%mod;
	rf[nn-1]=qpow(f[nn-1]);for(int i=nn-2;i>=0;i--) rf[i]=rf[i+1]*(i+1)%mod;
	int n,m;cin>>n>>m;if(n>m) swap(n,m);int ans=0;
	for(int i=1;i<=n;i++)
		add(ans,walk(n-i,m-i)%mod*walk(i,i));
	ans=ans*qpow(2)%mod*qpow(walk(n,m))%mod;		
	cout<<(ans+m)%mod;
	
	return 0;
}
// 42 23

Measured memory_bytes: 19248
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
print((pow(10,n,R)-2*pow(9,n,R)+pow(8,n,R))%R)


Measured memory_bytes: 61908
//---------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                        NEVER  GIVE  UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//------------------------------------------------------------------------------------------------------------------------------
#define N 1000005
vector<int> v(N);
void func() {
	for(int i=2;i*i<N;i++) {
		if(v[i] != i)
			continue;
		for(int j=i*i;j<N;j+=i) {
			v[j] = min(v[j],i);
		}
	}
}
int main()
{
	
	#ifndef ONLINE_JUDGE
	freopen("C:/Users/DELL/Desktop/input.txt", "r", stdin);
	#endif

	fast;
	int n,x;
	cin>>n;
	int gcd = 0;
	bool ok = true;
	map<int,int> mp;
	for(int i=0;i<n;i++) {
		cin>>x;
		gcd = __gcd(x,gcd);
		mp[x]++;
		if((x > 1) && (mp[x] > 1))
			ok = false;
	}
	// debug1(sz(mp))
	for(int i=0;i<N;i++)
		v[i] = i;
	if(gcd != 1) {
		cout<<"not coprime";
	} else {
		if(!ok)
			cout<<"setwise coprime";
		else {
			func();
			// for(int i=1;i<=20;i++) 
			// 	cout<<i<<"\t"<<v[i]<<"\n";
			map<int,int> mp2;
			for(auto it: mp) {
				int x = it.fi;
				set<int> s;
				while(x!=1) {
					s.insert(v[x]);
					x /= v[x];
				}
				// for(auto it: s)
				// 	cout<<it<<"\t";
				// cout<<"\n";
				for(auto it2: s) {
					mp2[it2]++;
					if(mp2[it2] > 1) {
						cout<<"setwise coprime";
						return 0;
					}
				}
			}
			cout<<"pairwise coprime";
		}
	}
	return 0;
}


Measured memory_bytes: 53664
use std::io;
use std::str::FromStr;

fn main() {
    let mut buf = String::new();

    let _ = io::stdin().read_line(&mut buf);
    let vec : Vec<i64> = buf.split_whitespace().map(|x| i64::from_str(x).unwrap()).collect();

    let (a, b, c) = (vec[0], vec[1], vec[2]);

    let mut n : i64 = 0;
    for i in a..(b+1) {
        if c % i == 0 {
            n += 1;
        }
    }

    println!("{}", n);
}



Measured memory_bytes: 5032
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[200005];
int main(){
	ll m,n,i,j,k;
	cin>>m;
	for(i=1;i<=m;i++) cin>>a[i];
	sort(a+1,a+1+m);
	multiset<ll> s,ss;
	for(i=1;i<m;i++){
		s.insert(a[i]);
		ss.insert(-a[i]);
	}
	multiset<ll>::iterator it;	
	ll ans=0,l=a[m],r=a[m];
	for(i=1;i<m;i++){
		ll mx=-*ss.begin();
		ll mi=*s.begin();
		ll tmp=max(max(abs(l-mx),abs(l-mi)),max(abs(r-mx),abs(r-mi)));
		ll chose;
		if(abs(l-mx)==tmp){
			ans+=abs(l-mx);
			l=mx;
			chose=mx;
			goto l;
		}
		if(abs(l-mi)==tmp){
			ans+=abs(l-mi);
			l=mi;
			chose=mi;
			goto l;
		}
		if(abs(r-mx)==tmp){
			ans+=abs(r-mx);
			r=mx;
			chose=mx;
			goto l;
		}
		if(abs(r-mi)==tmp){
			ans+=abs(r-mi);
			r=mi;
			chose=mi;
			goto l;
		}
		l:;
		it=s.lower_bound(chose);
		s.erase(it);
		it=ss.lower_bound(-chose);
		ss.erase(it);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 10496
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<list>
#define X first
#define Y second
#define INF 987654321
#define PI 3.14159265358979323
#define MOD 20091101
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
bool dislike[10];
bool ok(int N)
{
	while (N)
	{
		int x = N % 10;
		if (dislike[x])return 0;
		N /= 10;
	}
	return 1;
}
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	while (k--)
	{
		int x;
		scanf("%d", &x);
		dislike[x] = 1;
	}
	for (int i = n;; i++)
	{
		if (ok(i))
		{
			printf("%d", i);
			return 0;
		}
	}
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int M = sc.nextInt();
      int[] H = new int[N];
      boolean[] goodFlg = new boolean[N];
      //int[][] routeNum = new int[N][N];
      for(int i = 0; i < N; i++){
        H[i] = sc.nextInt();
        goodFlg[i] = true;
      }
      
      
      // 標高を比較
      for(int i = 0; i < M; i++){
        int A = sc.nextInt()-1;
        int B = sc.nextInt()-1;
        
        if(B < A){
          int tmp = A;
          A = B;
          B = tmp;
        }
        
        //routeNum[A][B]++;
        //if(routeNum[A][B] == 2){
        //  goodFlg[A] = false;
        //  goodFlg[B] = false;
        //}
        
        if(H[A] < H[B]){
          goodFlg[A] = false;
        }else if(H[B] < H[A]){
          goodFlg[B] = false;
        }else{
          goodFlg[A] = false;
          goodFlg[B] = false;
        }
      }
      
      // 良い展望台をカウント
      int count = 0;
      for(int i = 0; i < N; i++){
        if(goodFlg[i]){
          count++;
        }
      }
      
      // 出力
      System.out.println(count);
    }
    

}

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

int main(void){
    int a, b;
    cin >> a;
    cin >> b;
    //cout<<a;
    //cout<<"\r";
    //cout<<b;
    if(a-2*b>=0){
    
    cout<<(a-2*b);
    }else{
    cout<<0;
    //cout<<"khjkwdjlxw";
    
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <iomanip> 
#include <vector> 
#include <algorithm> 
#include <numeric> 
#include <functional> 
#include <cmath> 
#include <queue> 
#include <stack> 

#define Ford(i,a,b) for (int i=(a);i<(b);i++) 
#define For(i,n) Ford(i,0,n) 
typedef long long ll; 

using namespace std;

int main(){
  int N,T;
  int costMin=1001;
  cin>>N>>T;
  int c[N],t[N];
  For(i,N) cin>>c[i]>>t[i];
  For(i,N) if(t[i] <= T) if(c[i] <= costMin) costMin=c[i];
  
  if(costMin==1001) cout<<"TLE"<<endl;
  else cout<<costMin<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;

  if (S == "SUN"){
    cout << 7 << endl;
  }
  else if (S == "MON"){
    cout << 6 << endl;
  }
  else if (S == "TUE"){
    cout << 5 << endl;
  }
  else if (S == "WED"){
    cout << 4 << endl;
  }
  else if (S == "THU"){
    cout << 3 << endl;
  }
  else if (S == "FRI"){
    cout << 2 << endl;
  }
  else if (S == "SAT"){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3624
import java.util.*;

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

		int ans;

		if (n == 1){
			ans = Integer.parseInt(sc.next());
		}else {
			ans = gcd(Integer.parseInt(sc.next()), Integer.parseInt(sc.next()));
			for(int i=2; i<n; i++){
				ans = gcd(ans, Integer.parseInt(sc.next()));
			}
		}
		System.out.println(ans);
	}

	public static int gcd(int num1, int num2) {
		int x = Math.max(num1, num2);
		int y = Math.min(num1, num2);

		while (y != 0) {
			int tmp = x;
			x = y;
			y = tmp%y;
		}
		return x;
	}
}

Measured memory_bytes: 46760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		UnionFind uf = new UnionFind(n);
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
			int x = Integer.parseInt(sc.next())-1;
			int y = Integer.parseInt(sc.next())-1;
			uf.unite(x, y);
			sc.next();
		}
		System.out.println(uf.count());
		sc.close();
	}

	public static class UnionFind {

		int par[]; int rank[]; int size[]; int count;

		public UnionFind(int n) {
			this.par = new int[n];
			this.rank = new int[n];
			this.size = new int[n];
			this.count = n;
			for(int i = 0; i < n; i++) {
				par[i] = i; rank[i] = 0; size[i] = 1;
			}
		}

		int find(int x) {//xの属する集合の根を探す
			if(par[x] == x) return x;
			else return par[x] = find(par[x]);
		}

		void unite(int x, int y) {//x,yの集合を合併
			x = find(x);
			y = find(y);
			if(x == y) return ;
			if(rank[x] < rank[y]) {
				par[x] = y;
				size[y] += size[x];
			}else {
				par[y] = x;
				size[x] = size[y];
				if(rank[x] == rank[y]) {
					rank[x]++;
				}
			}
			count--;
		}

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

		int amount(int x) {//xの属する集合の要素数
			return size[find(x)];
		}

		int count() {//集合の数
			return count;
		}
	}
}

Measured memory_bytes: 63696
n = int(input())
m = n
result = []

for i in range(2, n+1):
    
    while m%i==0:
        m = m//i
        result.append(i)
        
    if m==1:
        break
        
    if i>n**(1/2) and m==n:
        result.append(n)
        break

print(str(n)+':', *result)


Measured memory_bytes: 5624
import copy

# a = get_int()
def get_int():
    return int(input())

# a = get_string()
def get_string():
    return input()

# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]

# a_list = get_string_list():
def get_string_list():
    return input().split()

# a, b = get_int_multi()
def get_int_multi():  # a, b = get_int_multi()
    return map(int, input().split())

# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():

    a = get_int() % 1000
    if a == 0:
        print(0)
    else:
        print(1000 - a)





if __name__ == '__main__':
    main()




Measured memory_bytes: 9344
/**
 *   created: 09 August 2019  11:55:44
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	// cin>>tt;
	while(tt--){
		int t;
		cin>>t;
		if(t==1){
			cout<<"Hello World";
		}
		else{
			int a,b;
			cin>>a>>b;
			cout<<a+b;
		}
	}
	return 0;
}


Measured memory_bytes: 256
//
//AtCoder Beginner Contest 148
//A - Round One
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define reAll(x) (x).rbegin(),(x).rend()

using ll = long long;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

int main()
{
    int a, b;

    cin >> a >>  b;

    cout << 6 - a - b << endl;

    return 0;
}


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

using namespace std;

bool power2(int n) {
  if (n == 1) return true;
  if (n & 1) return false;
  return power2(n / 2);
}

int main() {
  int n;
  scanf("%d", &n);
  vector<int> x(n);
  vector<bool> isPower2(n);
  int result = 0;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    int k = ceil(log2(a));
    x[i] = k;
    result += k;
    isPower2[i] = power2(a);
  }
  vector<int> savedLeft(n), savedRight(n);
  for (int i = 1; i < n; i++) {
    int beforeBig = x[i - 1];
    int beforeSmall = x[i - 1] - !isPower2[i - 1];

    int curBig = x[i];
    int curSmall = x[i] - !isPower2[i];

    savedLeft[i] = max(
        savedLeft[i - 1] + min(beforeBig, curSmall),
        savedRight[i - 1] + min(beforeSmall, curSmall));
    savedRight[i] = max(
        savedLeft[i - 1] + min(beforeBig, curBig),
        savedRight[i - 1] + min(beforeSmall, curBig));
  }
  printf("%d\n", result - max(savedLeft[n-1], savedRight[n-1]));
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
int main(){
    int n,m,X,Y;
    cin>>n>>m>>X>>Y;
    vector<int> x(n);
    vector<int> y(m);
    rep(i,n){
        cin>>x[i];
    }
    rep(i,m){
        cin>>y[i];
    }
    all(x),all(y);
    if(x[n-1]>=y[0]){
        cout<<"War"<<endl;
    }
    else{
        if(X>=y[0]||Y<=x[n-1]){
            cout<<"War"<<endl;
        }
        else{
            cout<<"No War"<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int r;
  scanf("%d", &r);
  if (r < 1200) {
    printf("ABC\n");
  } else if (r < 2800) {
    printf("ARC\n");
  } else {
    printf("AGC\n");
  }

  return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    class Permutation<T> private constructor(private val baseIndex: Int, private var index: Int, val target: Array<T>?) {
        private var subPermutation: Permutation<T>? = null

        constructor(objs: Array<T>) : this(0, 0, objs.clone())

        init {
            if (target == null || target.isEmpty()) {
                throw IllegalArgumentException()
            }

            if (this.index < this.target.size - 1) {
                this.subPermutation = Permutation(this.baseIndex + 1, this.index + 1, this.target)
            }
        }

        operator fun next(): Boolean {
            if (this.subPermutation == null) {
                return false
            }
            val result = this.subPermutation!!.next()
            if (result) {
                return true
            }
            this.swap(this.baseIndex, this.index)
            ++this.index
            if (this.target!!.size <= this.index) {
                this.index = this.baseIndex
                return false
            }
            this.swap(this.index, this.baseIndex)
            return true
        }

        private fun swap(index1: Int, index2: Int) {
            val tmp = this.target!![index1]
            this.target[index1] = this.target[index2]
            this.target[index2] = tmp
        }
    }

    fun calcFactorial(i: Long, modNum: Long? = null): Long {
        return when {
            i == 1L -> 1L
            modNum != null -> (i * calcFactorial(i - 1, modNum)) % modNum
            else -> i * calcFactorial(i - 1)
        }
    }

    fun calcDist(one: Pair<Double, Double>, two: Pair<Double, Double>) = Math.sqrt(Math.pow(one.first - two.first, 2.0) + Math.pow(one.second - two.second, 2.0))
    val n = readLine()!!.toInt()
    val xyList = mutableListOf<Pair<Double, Double>>()
    (1..n).forEach {
        val (x, y) = readLine()!!.split(' ').map(String::toDouble)
        xyList.add(Pair(x, y))
    }
    val distMap = Array(n) { Array(n) { 0.0 } }
    for (i in 0 until n) {
        for (j in 0 until n) {
            distMap[i][j] = calcDist(xyList[i], xyList[j])
        }
    }

    val pattern = listOf(0, 1, 2, 3, 4, 5, 6, 7).subList(0, n).toTypedArray()
    val permutation = Permutation(pattern)
    var distSum = 0.0
    do {
        val target = permutation.target!!

        for (i in 0..(n - 2)) {
            distSum += distMap[target[i]][target[i + 1]]
        }

    } while (permutation.next())
    println(distSum / calcFactorial(n.toLong()).toDouble())
}



Measured memory_bytes: 38360
#include <iostream>

using namespace std;

int main()
{
	int n[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> n[i][j];
		}
	}
	for (int i = 0; i < 3; i++) {
		if (n[(i + 1) % 3][0] - n[i][0] != n[(i + 1) % 3][1] - n[i][1]
				|| n[(i + 1) % 3][0] - n[i][0] != n[(i + 1) % 3][2] - n[i][2]) {
			cout << "No" << endl;

			return 0;
		}
	}
	for (int i = 0; i < 3; i++) {
		if (n[0][(i + 1) % 3] - n[0][i] != n[1][(i + 1) % 3] - n[1][i]
			|| n[0][(i + 1) % 3] - n[0][i] != n[2][(i + 1) % 3] - n[2][i]) {
			cout << "No" << endl;

			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L
const int mxN = 1e9 + 7;


int main() {

    int n;
    cin >> n;
    vector<pair<string, int>> a(n);
    vector<pair<string, int>> ans(n);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        int x;
        cin >> x;
        a[i] = make_pair(s, x);
        ans[i] = make_pair(s, x);
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i].first == a[j].first) {
                if (a[j].second > a[i].second) {
                    swap(a[i], a[j]);
                }
            }
            else {
                break;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i] == ans[j]) {
                cout << j+1 << "\n";

            }
        }
    }

    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;
 
public class Main {
  public static void main ( String[] args ) {
 
    Scanner sc = new Scanner ( System.in );
 
    String S = sc.next();
    
    if("Sunny".equals(S)){
      System.out.println("Cloudy");
    }else if ("Cloudy".equals(S)){
      System.out.println("Rainy");
    }else{
      System.out.println("Sunny");
    }
  }
}

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

namespace Traveling_Plan
{
    class Program
    {
        /// <summary>
        /// メイン処理
        /// </summary>
        /// <param name="args">引数</param>
        static void Main(string[] args)
        {
            List<long> listA = new List<long>();

            int N = int.Parse(Console.ReadLine());
            listA.AddRange(Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse));

            long totalList = 0;
            List<long> sumMoneyList = new List<long>();
            var ryoko = new Ryoko();
            ryoko.TotalMoney(N, listA, ref totalList, ref sumMoneyList);

            foreach (long money in sumMoneyList)
            {
                // 結果出力
                Console.WriteLine(totalList - money);
            }
        }
    }

    class Ryoko
    {
        /// <summary>
        /// 旅費の計算
        /// </summary>
        /// <param name="spot">観光スポット</param>
        /// <param name="area">座標リスト</param>
        /// <returns></returns>
        public void TotalMoney(int spot, List<long> areaList, ref long totalMoney, ref List<long> sumMoneyList)
        {
            long sum = 0;

            for (int i = 0; i < spot; i++)
            {

                if (i == 0)
                {
                    // 最初の観光スポットを飛ばすときの金額差
                    sum = Math.Abs( - Math.Abs(0 - areaList[i]) - Math.Abs(areaList[i] - areaList[i + 1]) + Math.Abs(0 - areaList[i + 1]));
                    sumMoneyList.Add(sum);

                    totalMoney += Math.Abs(0 - areaList[i]);
                    continue;
                }

                if (i == spot - 1)
                {
                    // 最後の観光スポットを飛ばすときの金額差
                    sum = Math.Abs (- Math.Abs(areaList[i - 1] - areaList[i]) - Math.Abs(areaList[i] - 0) + Math.Abs(areaList[i - 1] - 0));
                    sumMoneyList.Add(sum);

                    totalMoney += Math.Abs(areaList[i - 1] - areaList[i]) + Math.Abs(areaList[i] - 0);
                    continue;
                }

                // 最初と最後以外を飛ばしたときの金額差
                sum = Math.Abs (- Math.Abs(areaList[i - 1] - areaList[i]) - Math.Abs(areaList[i] - areaList[i + 1]) + Math.Abs(areaList[i - 1] - areaList[i + 1]));

                // 金額差を格納する
                sumMoneyList.Add(sum);

                // 全ての観光スポットに行ったときの金額を計算する
                totalMoney += Math.Abs(areaList[i - 1] - areaList[i]);
            }
        }
    }
}

Measured memory_bytes: 30940
#include<iostream>
#include<queue>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int c,n,m,s,d; while(cin>>c>>n>>m>>s>>d,c){
		s--,d--;
		int a,b,f;
		int ad[n][n],cost[c+1][n];
		rep(i,n)rep(j,n)ad[i][j]=0;
		rep(i,c+1)rep(j,n)cost[i][j]=1<<20;
		rep(i,m)cin>>a>>b>>f,a--,b--,ad[a][b]=ad[b][a]=f;
		queue<pair<int,int> > F; F.push(make_pair(c,s));
		cost[c][s]=0;
		while(!F.empty()){
			int cnode=F.front().second,cc=F.front().first; F.pop();
			rep(i,n)if(ad[cnode][i]){
				if(cost[cc][i]>cost[cc][cnode]+ad[cnode][i])
				cost[cc][i]=cost[cc][cnode]+ad[cnode][i],
				F.push(make_pair(cc,i));
				if(cc>0&&cost[cc-1][i]>cost[cc][cnode]+ad[cnode][i]/2)
				cost[cc-1][i]=cost[cc][cnode]+ad[cnode][i]/2,
				F.push(make_pair(cc-1,i));
			}
		}
		int mi,mn=1<<20;rep(i,c+1)if(cost[i][d]<mn)mi=i,mn=cost[i][d];
		cout<<mn<<endl;
	}
	return 0;
}

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

int main(){
	ll n,m;
	cin >> n >> m;
	vector<pair<ll,ll>> p(n);
	rep(i,n){
		ll a,b;
		cin >> a >> b;
		p[i] = make_pair(a,b);
	}
	
	sort(p.begin(),p.end());
	
	ll ans = 0;
	ll count = 0;
	
	rep(i,n){
		rep(j,p[i].second){
			ans += p[i].first;
			count++;
			if(count == m) break;
		}
		if(count == m) break;
	}
	
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792