akhauriyash/Code-Regression huggingface dataset:
A=list(input())
b=[]
for i in range(2**3):
  b.clear()
  for j in range(3):
    if (i>>j)&1:
      b.append("+")
    else:
      b.append("-")
  c=eval(A[0]+b[0]+A[1]+b[1]+A[2]+b[2]+A[3])
  if c==7:
    print(A[0]+b[0]+A[1]+b[1]+A[2]+b[2]+A[3]+"=7")
    exit()

Measured memory_bytes: 9072
<?php
	while (true) {
		$n = trim(fgets(STDIN));
		list($h, $w) = explode(" ", $n);

		if ($h == 0 && $w == 0) break;

		for ($i = 0; $i < $h; $i++) {
			$flag = (($i+1) % 2 != 0) ? false : true;
			for ($j = 0; $j < $w; $j++) {
				print ($flag) ? "." : "#";
				$flag = !$flag;
			}
			print "\n";
		}

		print "\n";
	}

Measured memory_bytes: 6596
import java.io.*;
import java.util.*;

public class Main {
    Scanner sc;

    Main() {
        sc = new Scanner(System.in);
    }

    int n;
    
    boolean init() {
        n = sc.nextInt();
        if (n == 0) return false;
        return true;
    }

    int[] a;
    int[] b;
    void solve() {
        a = new int[4];
        b = new int[4];
        for (int i = 0; i < 4; i++) a[i] = sc.nextInt();
        for (int i = 0; i < 4; i++) b[i] = sc.nextInt();

        // 実数部
        int r = a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3];
        // i
        int i = a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2];
        // j
        int j = a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1];
        // k
        int k = a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0];

        System.out.printf("%d %d %d %d\n", r, i, j, k);
    }

    void run() {
        while (init()) {
            for (int i = 0; i < n; i++) 
                solve();
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 13000
IDENTIFICATION DIVISION.
PROGRAM-ID. 145B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 S     PIC X(100).
01 N     PIC 9(3).
01 H     PIC 9(2).
01 A     PIC 9(1).
*>
PROCEDURE DIVISION.
  ACCEPT N.
  ACCEPT S.
*>
  DIVIDE N BY 2 GIVING H REMAINDER A.
  IF (A = 0)
    IF (S(1:H) = S(H + 1:H))
      DISPLAY 'Yes'
    ELSE
      DISPLAY 'No'
    END-IF
  ELSE
    DISPLAY 'No'
  END-IF.
*>
  STOP RUN.


Measured memory_bytes: 384
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String T = sc.next();
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < T.length();i++){
			if(T.charAt(i) == '?'){
				sb.append("D");
			}else{
				sb.append(T.charAt(i));
			}
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 33100
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		char c = br.readLine().charAt(0);
		if(Character.isUpperCase(c))
			System.out.println("A");
		else
			System.out.println("a");
	}
}

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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    long n, a, b;
    long ans = 0;
    cin >> n >> a >> b;
    if((b - a) % 2 == 0){
        cout << (b - a) / 2  << endl;
        return 0;
    }else{
        if(b-1 < n-a){
            ans += a;
            b -= a;
            a = 1;
            ans += (b-a) / 2;
        }else{
            ans += n-b+1;
            a += n-b+1;
            b = n;
            ans += (b-a) / 2;
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3660
#include <iostream>
#include <set>
#include <cmath>
using namespace std;

const int m=256;

int main()
{
  int n,s,a,c,I[256],anss,ansa,ansc;

  for(;;){
    cin>>n;
    if(!n) break;
    for(int i=1;i<=n;i++)
      cin>>I[i];
    int max=n;
    double min=100000.0;
    for(s=0;s<=15;s++)
      for(a=0;a<=15;a++)
	for(c=0;c<=15;c++){
	  int o,r=s,cou=0,x[256]={0};
	  for(int i=1;i<=n;i++){
	    r=(a*r+c)%m; o=(I[i]+r)%m;
	    cou+=x[o]==0;
	    if(max<cou) break;
	    x[o]++;
	  }
	  if(cou<=max){
	    max=cou;
	    double h=0;
	    for(int i=0;i<m;i++)
	      if(x[i]) h-=(double)x[i]/n*log((double)x[i]/n);
	    if(h+1e-9<min){
	      min=h; anss=s; ansa=a; ansc=c;
	    }
	  }
	}
    cout<<anss<<" "<<ansa<<" "<<ansc<<endl;
  }
}


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

int main(void) {
	int s;
	cin >> s;
	vector<int> m(1000010);
	int ans = 0;

	for (int i = 1; i <= 100000; i++) {
		m[s]++;
		if(m[s] == 2) {
			ans = i;
			break;
		}
		if (s % 2 == 0) {
			s /= 2;  
		} else {
			s = 3*s + 1;
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int h, w;
    cin >> h >> w;

    int cnt = 0;
    rep(i, h){
        rep(j, w){
            char c;
            cin >> c;

            if(c == '#'){
                cnt++;
            }
        }
    }

    if(cnt == h + w - 1){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

int dp[4][101][51001];

void solve(){
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return;
		vector<pair<int, int>> inputs;
		REP(i, n) {
			int a, b;
			cin >> a >> b;
			inputs.push_back(mp(a, b));
		}
		inputs.push_back(mp(0, 1e9));
		reverse(ALL(inputs));
		REP(t, 4) {
			REP(i, 101) {
				REP(q, 51001) {
					dp[t][i][q] = 1e9;
				}
			}
		}
		dp[0][0][0] = 0;
		int ans = -1;
		int tmp = 1;
		for (int i = 0; i <= 50500; ++i) {
			if (inputs.back().second == i) {
				for (int t = 1; t <= 3; ++t) {
					REP(q, 101) {
						REP(j, 4) {
							dp[j][q][i + t] = 1e9;
						}
					}
				}
				REP(q, 101) {
					REP(j, 4) {
						if (q != inputs.back().first) {
							dp[j][q][i] = 1e9;
						}
					}
				}
				for (int j = 3; j >= 1;--j) {
					swap(dp[j][inputs.back().first][i], dp[j - 1][inputs.back().first][i]);
				}
				dp[0][inputs.back().first][i] = 1e9;
				int ok = 0;
				REP(j, 4) {
					if (dp[j][inputs.back().first][i] != 1e9) ok = 1;
				}
				
				if (ok == 0) {
					ans = tmp;
					break;
				}
				tmp++;
				inputs.pop_back();
			}
			REP(t, 4) {
				for (int q = 0; q < 101; ++q) {
					if (q != 100) {
						dp[t][q + 1][i + t + 1] = min(dp[t][q + 1][i + t + 1], dp[t][q][i] + 1);
					}
					if (q != 0) {
						if(q == 1){
							dp[0][q - 1][i + t + 1] = min(dp[0][q - 1][i + t + 1], dp[t][q][i] + 1);
						}
						dp[t][q - 1][i + t + 1] = min(dp[t][q - 1][i + t + 1], dp[t][q][i] + 1);
					}
					dp[t][q][i + 1] = min(dp[t][q][i + 1], dp[t][q][i]);
				}
			}
		}
		if (ans != -1) {
			cout << "NG " << ans << endl;
			continue;
		}
		cout << "OK " << dp[0][0][50500] << endl;
	}
}

#undef int
int main() {
	init();
	solve();
}


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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif

using namespace std;

void solve(ll X) {
    if (X == 7 || X == 5 || X == 3) cout << "YES" << endl;
    else cout << "NO" << endl;
}


void main_(istream &cin) {
    ll X;
    cin >> X;
    solve(X);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

vector<pair<ll, int> > prime_factorize(ll n) {
  vector<pair<ll, int> > res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i) continue;
    res.push_back(make_pair(i, 0));
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n, p;
    cin >> n >> p;
    vector<pair<ll, int> > v;
    v = prime_factorize(p);
    ll ans = 1;
    rep (i, v.size()) {
        rep (j, v[i].second / n) ans *= v[i].first;
    }
    cout << ans << endl;
    
    return 0;
}



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

using namespace std;
#define endl "\n"

const int MOD = 1000000007;
int main()
{
	string a, b, c;
	cin >> a >> b>> c;
	cout <<a[0]<< b[1] << c[2] << endl;
	
	
	return 0;
}


Measured memory_bytes: 3588
from itertools import permutations
from heapq import *
from collections import defaultdict
from math import log
from itertools import accumulate
from collections import deque
#maxv=[0]
import sys
sys.setrecursionlimit(100100)

import math
from math import ceil
from copy import deepcopy


N,M=map(int,input().split())
T=[[] for i in range(N)]
for i in range(M):
    u,v=map(int,input().split())
    u,v=u-1,v-1
    T[u].append(v)
    T[v].append(u)
list=list(range(1,N))
ans=0
for l in permutations(list):
    t=True
    for i in range(N-1):
        if i==0:
            if not l[0] in T[0]:
                t=False
                break
        else:
            if not l[i] in T[l[i-1]]:
                t=False
                break
    if t:
        ans+=1
print(ans)


Measured memory_bytes: 39920
if __name__ == '__main__':
    n, k = map(int, input().split())
    trees = [0] * n
    for i in range(n):
        trees[i] = int(input())
    trees.sort()

    ans = 10 ** 9
    for i in range(n - k + 1):
        diff = trees[i + k - 1] - trees[i]
        if diff < ans:
            ans = diff
    print(ans)

Measured memory_bytes: 7472
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;

const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;


int main(){
    while(1){
        int n;
        scanf("%d",&n);
        if(!n)break;

        vector<P> patients(n);
        for(int i=0;i<n;i++){
            int p,d1,d2;
            scanf("%d%d%d",&p,&d1,&d2);
            patients[i] = P(d1+d2,p);
        }
        sort(patients.begin(),patients.end());
        cout << patients[n-1].second << " " << patients[n-1].first << endl;
    }

    return 0;
}

Measured memory_bytes: 1288
#include<iostream>
using namespace std;
int main(){
    //S, H, C, D
    int num;
    int card[4][13];
    for(int i=0; i<4; i++){
        for(int j=1; j<=13; j++){
            card[i][j]=0;
        }
    }
    cin >> num;
    for(int i=0; i<num; i++){
        char mark_s;
        int number, mark;
         cin >> mark_s >> number;
         if(mark_s=='S') mark=0;
         else if(mark_s=='H') mark=1;
         else if(mark_s=='C') mark=2;
         else if(mark_s=='D') mark=3;
         else mark=0;
         
         card[mark][number] = 1;
    }
    for(int i=0; i<4; i++){
        for(int j=1; j<=13; j++){
            if(card[i][j]==0){
                if(i==0) cout << 'S' <<" " << j <<endl;
                else if(i==1) cout << 'H' <<" " << j <<endl;
                else if(i==2) cout << 'C' <<" " << j <<endl;
                else if(i==3) cout << 'D' <<" " << j <<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <cmath>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n,t,e; cin>>n>>t>>e;
    rep(i,n){
        int x; cin>>x;
        if((t+e)%x<=e){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 1164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int h = sc.nextInt();
		int w = sc.nextInt();
		long res = 0;
		long[][] floyd = new long[10][10];
		
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				floyd[i][j] = sc.nextLong();
			}
		}
		
		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					floyd[i][j] = Math.min(floyd[i][j], floyd[i][k] + floyd[k][j]);
				}
			}
		}
		
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				int wall = sc.nextInt();
				if (wall != -1) {
					res += floyd[wall][1];
				}
			}
		}
		
		
		System.out.println(res);
	}
  
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      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: 25684
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //string[] str = Console.ReadLine().Split(' ');
            //int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');

            int n = int.Parse(str[0]);
            int m = int.Parse(str[1]);

            int ans = n * (n - 1) / 2 + m * (m - 1 )/ 2;

            Console.WriteLine(ans);


            //ここまで
        }



    }

}


Measured memory_bytes: 13140
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int n; cin>>n;
    vector<ll> a(n), c(n);
    for(int i=0; i<n; i++) cin>>a[i], c[--a[i]]++;

    ll sum = 0;
    for(int i=0; i<n; i++){
        sum += c[i] * (c[i] - 1) / 2;
    }

    for(int i=0; i<n; i++){
        ll ans = sum;
        ans -= c[a[i]] * (c[a[i]] - 1) / 2;
        ans += (c[a[i]] - 1) * (c[a[i]] - 2) / 2;
        cout << ans << endl;
    }

    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int max_s = 0;
    vector<int> s;
    for (int i=0; i<N; i++){
        int in;
        cin >> in;
        max_s = max(max_s, in);
        s.push_back(in);
    }
    int M = max_s * N;
    vector<bool> dp(M+1);
    for (int i=1; i<=M; i++){
        dp[i] = false;
    }
    dp[0] = true;

    for (auto x : s){
        for (int i=M; i>=0; i--){
            if (i >= x && dp[i-x]){
                dp[i] = true;
            }
        }
    }
    for (int i=0; i<=M; i++){
        if ((M-i)%10 != 0 && dp[M-i]){
            cout << M-i << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

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

int main(void){
    ll n;
    cin>>n;
    if(n>=400&&599>=n){
        cout<<8<<endl;
    }else if(n>=600&&799>=n){
        cout<<7<<endl;
    }else if(n>=800&&999>=n){
        cout<<6<<endl;
    }else if(n>=1000&&1199>=n){
        cout<<5<<endl;
    }else if(n>=1200&&1399>=n){
        cout<<4<<endl;
    }else if(n>=1400&&1599>=n){
        cout<<3<<endl;
    }else if(n>=1600&&1799>=n){
        cout<<2<<endl;
    }else if(n>=1800&&1999>=n){
        cout<<1<<endl;
    }
}


Measured memory_bytes: 3672
#include<map>
#include<iostream>
#include<string>
using namespace std;

int main()
{
	int a, b;
	std::cin >> a >> b;
	int c;
	c= (a + b) % 2 ? (a + b) / 2 +1 : (a + b) / 2;
	cout << c;

	return 0;
}

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

int main() {
    int n, a[100010];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    sort(a, a + n);

    int idx = 1;
    vector<pair<int, int > > v;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] == a[i + 1]) idx++;
        else {
            v.emplace_back(a[i], idx);
            idx = 1;
        }
    }
    v.emplace_back(a[n - 1], idx);

    bool ok = false;
    if (v.size() == 1) {
        if (v[0].first == 0) ok = true;
    }
    else if (v.size() == 2) {
        if (v[0].second == n/3 && v[1].second == 2 * n / 3) {
            if ((v[1].first ^ v[1].first) == v[0].first) ok = true;
        }
        if (v[0].second == 2*n/3 && v[1].second == n / 3) {
            if ((v[0].first ^ v[0].first) == v[1].first) ok = true;
        }
    }
    else if (v.size() == 3) {
        if (v[0].second == v[1].second && v[1].second == v[2].second) {
            if ((v[0].first ^ v[2].first) == v[1].first) ok = true;
        }
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;

}


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

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

    int n;
    cin >> n;
    if(n >= 1000) cout << "ABD" << endl;
    else cout << "ABC" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>
#include <set>

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;

using namespace std;

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

    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        ma[a] = max(ma[a], h[b]);
        ma[b] = max(ma[b], h[a]);
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (ma[i] < h[i])
        {
            ans++;
        }
    }

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

Measured memory_bytes: 3964
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
main() {
  int N,M; cin>>N>>M;                                // 入力を得る
  if(N>=M) { cout<<0<<endl; exit(0); }               // 全ての地点にコマを置ける
  vector<int> X(M); for(auto& x:X) cin>>x;           // 入力を得る
  sort(X.begin(), X.end());                          // 地点らを整列する
  vector<int> dist;                                  // distance; 地点同士の距離
  for(int i=1;i<M;++i) dist.push_back(X[i]-X[i-1]);  // 条件より地点は重ならない
  sort(dist.begin(), dist.end());                    // 距離で整列する
  vector<int> sum=dist;                              // sum 累積和
  for(int i=1;i<sum.size();++i) sum[i]+=sum[i-1];    // 累積和を得る
  cout<< sum[sum.size()-N] <<endl;                   // コマの数だけ移動せずにすむ距離がある
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb  push_back
int32_t main()
{
     string S;
     cin>>S;
     if(S=="RRR")
     cout<<3;
     else if((S=="RRS") || (S=="SRR"))
     cout<<2;
     else if ((S=="RSS") || (S=="SSR") || (S=="SRS") || (S=="RSR"))
     cout<<1;
     else
     cout<<0;

     return 0;
    

}


Measured memory_bytes: 3584
def parser(left, right):
    if S[left] == '(' and S[right - 1] == ')':
        cnt = 0
        for i in range(left + 1, right - 1):
            if S[i] == '(':
                cnt += 1
            elif S[i] == ')':
                cnt -= 1
            elif cnt == 0 and S[i] == '+':
                return [max(x, y) for x, y in zip(parser(left + 1, i), parser(i + 1, right - 1))]
            elif cnt == 0 and S[i] == '*':
                return [min(x, y) for x, y in zip(parser(left + 1, i), parser(i + 1, right - 1))]
    elif S[left] == '-':
        return [2 - x for x in parser(left + 1, right)]
    elif S[left] == 'P':
        return [i // 9 % 3 for i in range(27)]
    elif S[left] == 'Q':
        return [i // 3 % 3 for i in range(27)]
    elif S[left] == 'R':
        return [i % 3 for i in range(27)]
    else:
        return [int(S[left]) for _ in range(27)]


while True:
    S = input()
    if S == '.':
        break
    print(parser(0, len(S)).count(2))

Measured memory_bytes: 7692
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {

  trait Monoid[A]{
    def op(a1: A, a2: A): A
    def zero: A
  }

  type Per = List[Int]
  type Rot = Dice => Dice

  object DiceRoll extends Monoid[Rot]{

    def op(rot1: Rot, rot2: Rot): Rot = (dice: Dice) => rot2(rot1(dice))
    def zero: Rot = (dice: Dice)=>dice

    val north = List(2,6,3,4,1,5).map(_ - 1)
    val east = List(4,2,1,6,5,3).map(_ - 1)
    val ccw = List(1,4,2,5,3,6).map(_ - 1)

    def rot(perm: Per): Rot = (dice: Dice) => Dice(perm.map(dice.pip))

    def axial(f: Rot): List[Rot] = List(zero,f,op(f,f),op(op(f,f),f))

    def enumerateTop(f: Rot = zero, n: Int = 6): List[Rot] = {
      if(n<=0)List[Rot]()
      else if(n%2==0) f :: enumerateTop(op(f,rot(north)),n-1)
      else f :: enumerateTop(op(f,rot(east)),n-1)
    }

    def enumerate: List[Rot] = enumerateTop().flatMap( e => axial(rot(ccw)).map(op(e,_)))
  }

  case class Dice(pip: List[Int]){
    lazy val all: List[Dice] = DiceRoll.enumerate.map(_(Dice(pip)))
    def ===(that: Dice): Boolean = pip.corresponds(that.pip)(_ == _)
    def ==(that: Dice): Boolean = all.exists(_ === that)
  }

  def main(args: Array[String]): Unit = {
    val pip1 = readLine.split(" ").map(_.toInt).toList
    val pip2 = readLine.split(" ").map(_.toInt).toList
    println(if(Dice(pip1) == Dice(pip2)) "Yes" else "No")
  }
}

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

#define MAX 1000

std::vector<int>Graph[MAX];
bool visited[MAX], recstack[MAX];

int N;

bool dfs(int current) {


    if (!visited[current]) {
        visited[current] = recstack[current] = true;

        int next;

        for (unsigned long i = 0; i < Graph[current].size(); i++) {
            next = Graph[current][i];
            if (!visited[next] && dfs(next)) return  true;
            else if(recstack[next]) return true;
        }
    }
    recstack[current] = false;
    return false;
}

void isCycle() {
    for (int i = 0; i < N; i++) {
        visited[i] = false;
        recstack[i] = false;
    }

    for (int i = 0; i < N; i++) {
        if (dfs(i)) {
            std::cout << 1 << std::endl;
            return;
        }
    }
    std::cout << 0 << std::endl;

}


int main()
{
    int Edges;
    std::scanf("%d %d", &N, &Edges);
    int start, target;

    for (int i = 0; i < Edges; i++) {
        std::scanf("%d %d", &start, &target);
        Graph[start].push_back(target);
    }

    isCycle();

    return 0;
}



Measured memory_bytes: 3276
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define _GLIBCXX_DEBUG
#define INF 100000010
using namespace std;
const int mod = 1000000007;


int main(){
    int N;
    cin>>N;
    vector<int> A(N,0);
    for(int i=0; i<N-1; i++){
        int a;
        cin>>a;
        A[a-1]++;
    }
for(int i=0; i<N; i++){
   cout<< A[i]<<endl;}
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
#define INF 0x3f3f3f3f
template<typename T>
void read(T &x)
{
    char ch=getchar();
    int f=1;
    for (x=0;ch!='-'&&(ch<'0'||ch>'9');ch=getchar());
    if (ch=='-') f=-1,ch=getchar();
    for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
    x*=f;
}
int n,m,k,ans,x,y;
char mp[810][810];
bool vis[810][810];
queue<PII> q;
queue<int> dp;
char getopt()
{
	char ch=getchar();
	while (ch!='#'&&ch!='.'&&ch!='S') ch=getchar();
	return ch;
}
int calc(int x,int y)
{
	if (min(min(x-1,n-x),min(y-1,m-y))==0) return 0;
	return (min(min(x-1,n-x),min(y-1,m-y))-1)/k+1;
}
void bfs(int x,int y,int deep)
{
	q.push(make_pair(x,y));
	vis[x][y]=1;
	dp.push(0);
	while (!q.empty())
	{
		PII tmp=q.front();
		q.pop();
		int h=dp.front();
		dp.pop();
		if (h>k) continue;
		ans=min(ans,calc(tmp.first,tmp.second));
		for (int i=0;i<4;i++)
		{
			int newx=tmp.first+dir[i][0];
			int newy=tmp.second+dir[i][1];
			if (newx>=1&&newx<=n&&newy>=1&&newy<=m&&mp[newx][newy]=='.'&&!vis[newx][newy])
			{
				vis[newx][newy]=1;
				q.push(make_pair(newx,newy));
				dp.push(h+1);
			}
		}
	}
}
int main()
{
	read(n),read(m),read(k);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			mp[i][j]=getopt();
			if (mp[i][j]=='S')
				x=i,y=j;
		}
	ans=INF;
	bfs(x,y,0);
	printf("%d",ans+1);
	return 0;
} 


Measured memory_bytes: 1536
#include<stdio.h>
#include<stdlib.h>

int main(){
  int total = 0, i, j;
  for(i = 1; i <=9; i++){
    for(j = 1; j <= 9; j++){
      total = i * j;
      printf("%dx%d=%d\n", i, j, total);
    }
  }
    return 0;
}

Measured memory_bytes: 524
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());

    let a = io.readn::<i64>(3);

    io.writeln(a[2] / a[0] * a[1]);
}

static MOD: i64 = 1000000007;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 4352
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctype.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    string ans = "ABC";
    cout << ans << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int num;
    for(int i=0;i<n;i++)
    {
        cin>>num;
        if(num%2==0 && num%3!=0 && num%5!=0)
        {
            cout<<"DENIED";
            return 0;
        }
    }
    cout<<"APPROVED";
}

Measured memory_bytes: 256
function main()
	N = parse.(Int,readline())
	inputs = [parse.(Int,split(readline())) for _=1:N]
	
	p=0
	cnt=0
	for input in inputs
		if input[1] == input[2]
			p+=1
		else
			p=0
		end
		if p ==3
			cnt+=1
		end
	end
	println(cnt > 0 ? "Yes" : "No")
end

main()

Measured memory_bytes: 177728
import sys

sys.setrecursionlimit(10**8)
n,m = map(int,input().split())
graph = [[]for i in range(n)]
visited = [0]*n
def all_v(visited):
    cnt = 0
    for x in visited:cnt+=x
    return cnt == n
def dfs(now):
    visited[now] = 1
    if all_v(visited):return 1
    res = 0
    for next in graph[now]:
        if visited[next]:continue
        res += dfs(next)
        visited[next] = 0
    return res
    
for i in range(m):
    a,b = map(int,input().split())
    a-=1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
print(dfs(0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int k,tmpa,tmpb,tmpc,tmp;
    cin>>k;
    int ans=k*(k+1)/2;
    for(int a=1;a<=k;a++){
        tmpa=a;
        for(int b=a+1;b<=k;b++){
            tmpa=a;
            tmpb=b;
            while(1){
                int d=tmpb%tmpa;
                if(d==0)break;
                else{
                    tmpb=tmpa;
                    tmpa=d;
                }
            }
            ans+=tmpa*6;
            for(int c=b+1;c<=k;c++){
                tmp=tmpa;
                tmpc=c;
                while(1){
                    int d=tmpc%tmp;
                    if(d==0)break;
                    else{
                        tmpc=tmp;
                        tmp=d;
                    }
                }
                ans+=tmp*6;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#define MN 20000
int n,a[MN+5],b[MN+5],p[MN+5];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	for(int i=1;i<=n;i++){
		a[i]=i*30000;
		b[i]=(n-i+1)*30000;
	}
	for(int i=1;i<=n;i++)
		a[p[i]]+=i;
	for(int i=1;i<=n;i++)
		printf("%d ",a[i]);
	putchar('\n');
	for(int i=1;i<=n;i++)
		printf("%d ",b[i]);
	putchar('\n');
}

Measured memory_bytes: 768
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        this.Length = inpt[0];
        this.ColorCount = inpt[1];

        this.Ieakan = new int[this.ColorCount, this.ColorCount];
        for (int i = 0; i < this.ColorCount; i++) {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            for (int j = 0; j < this.ColorCount; j++) {
                this.Ieakan[i, j] = inpt[j];
            }
        }

        for (int i = 0; i < 3; i++) {
            this.color[i] = new int[ColorCount];
        }
        for (int i = 0; i < this.Length; i++) {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            for (int j = 0; j < this.Length; j++) {
                int pos = (i + j) % 3;
                int col = inpt[j] - 1;
                this.color[pos][col]++;
            }
        }

        int ans = int.MaxValue;
        for (int i = 0; i < ColorCount; i++) {
            for (int j = 0; j < ColorCount; j++) {
                for (int k = 0; k < ColorCount; k++) {
                    if(i==j||j==k||k==i) {
                        continue;
                    }
                    int subTotal = ColorChange(0, i);
                    subTotal += ColorChange(1, j);
                    subTotal += ColorChange(2, k);
                    ans = Math.Min(ans, subTotal);
                }
            }
        }
        Console.WriteLine(ans);
    }

    private Dictionary<int, Dictionary<int, int>> dic = new Dictionary<int, Dictionary<int, int>>();
    private int ColorChange(int idx, int toC) {
        if(!dic.ContainsKey(idx)) {
            dic.Add(idx, new Dictionary<int, int>());
        }        
        if(dic[idx].ContainsKey(toC)) {
            return dic[idx][toC];
        }

        int subTotal = 0;
        for (int i = 0; i < this.color[idx].Length; i++) {
            int fromC = i;
            int count = color[idx][fromC];
            subTotal += (this.Ieakan[fromC,toC] * count);
        }
        dic[idx][toC] = subTotal;
        return subTotal;
    }

    private int[][] color = new int[3][];

    private int Length;
    private int ColorCount;

    private int[,] Ieakan;



    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"




2 3
0 1 1
1 0 1
1 4 0
1 2
3 3


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 17620
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,X=mi()
    M = []
    for i in range(N):
        m = ii()
        M.append(m)

    M.sort()
    X -= sum(M)
    k = X//M[0]
    X -= k*M[0]

    print(N+k)
        



if __name__ == "__main__":
    main()

Measured memory_bytes: 62532
#include <bits/stdc++.h>
using namespace std;
int ans = 987654321;
int dp[100][100][100];
int f(int a, int b, int c) {
    //printf("%d %d %d\n", a, b, c);

    if (dp[a][b][c] > 0)
            return dp[a][b][c];
    if (a == b && b == c) {
        return 0;
    }
    int t[6] ={987654321,987654321,987654321,987654321,987654321,987654321};
    if (a < c && b < c)
        t[0] = f(a+1, b+1, c) +1;
    if (a < b && c < b)
        t[1] = f(a+1, b, c+1) + 1;

    if (b < a && c < a)
        t[2] = f(a, b+1, c+1) + 1;

    if (a < b && a < c)
        t[3] = f(a+2, b, c) + 1;

    if (b < a && b < c)
        t[4] = f(a, b+2, c) + 1;

    if (c < a && c < b)
        t[5] = f(a, b, c+2) + 1;

    sort(t, t+6);

    dp[a][b][c] = t[0];

    return dp[a][b][c];

}

int main() {

    int a, b, c;
    cin >> a >> b >> c;

    cout << f(a,b,c) << endl;

    return 0;
}

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

double manhattan(vector<double> vx, vector<double> vy) {
    double dist = 0;
    for (int i = 0; i < vx.size(); i++) {
        dist += abs(vx[i] - vy[i]);
    }
    return dist;
}

double euclide(vector<double> vx, vector<double> vy) {
    double dist = 0;
    for (int i = 0; i < vx.size(); i++) {
        dist += pow(vx[i] - vy[i], 2);
    }
    return sqrt(dist);
}

double third(vector<double> vx, vector<double> vy) {
    double dist = 0;
    for (int i = 0; i < vx.size(); i++) {
        dist += pow(abs(vx[i] - vy[i]), 3);
    }
    return pow(dist, 1.0 / 3.0);
}

double chebyshev(vector<double> vx, vector<double> vy) {
    double _max = -2001;
    for (int i = 0; i < vx.size(); i++) {
        _max = max(_max, abs(vx[i] - vy[i]));
    }
    return _max;
}

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

    int loop;
    cin >> loop;

    vector<double> vx(loop), vy(loop);
    rep(i, loop) cin >> vx[i];
    rep(i, loop) cin >> vy[i];

    cout << fixed;
    cout << setprecision(10) << manhattan(vx, vy) << endl;
    cout << setprecision(10) << euclide(vx, vy) << endl;
    cout << setprecision(10) << third(vx, vy) << endl;
    cout << setprecision(10) << chebyshev(vx, vy) << endl;
}


Measured memory_bytes: 3444
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::cmp::{max, min} ;

fn main() {
    input! {
        n: usize,
        v: [i32; n],
    }
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    let mut v_sorted: Vec<i32> = v.clone();
    v_sorted.sort();
    v_sorted.reverse();
    for a in v {
        for &m in &v_sorted {
            if m != a || (m == a && v_sorted[1] == m) {
                writeln!(out, "{}", m).unwrap();
                break;
            }
        }
    }
}


Measured memory_bytes: 9724
#include <stdio.h>

int main(void)
{
    char num[3];
    scanf("%s", &num);

    if(( num[0] == num[1] ) && ( num[1] == num[2] ))
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
    }
    
    return 0;
}

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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const long long MOD = 998244353;
const int FACT_MAX = 1000000;
long long fact[FACT_MAX];
long long inv[FACT_MAX];
long long invfact[FACT_MAX];
long long nPr(int n, int r) { return (fact[n] * invfact[n - r]) % MOD; }
long long nCr(int n, int r) {
    return (((fact[n] * invfact[r]) % MOD) * invfact[n - r]) % MOD;
}
void initialize_fact() {
    fact[0] = 1;
    inv[0] = 0;
    inv[1] = 1;
    invfact[0] = 1;
    loop(i, 1, FACT_MAX) fact[i] = (i * fact[i - 1]) % MOD;
    loop(i, 2, FACT_MAX) inv[i] = MOD - ((MOD / i) * inv[MOD % i] % MOD);
    loop(i, 1, FACT_MAX) invfact[i] = (invfact[i - 1] * inv[i]) % MOD;
}

void solve(long long N, long long M, long long K) {
    initialize_fact();

    vector<long long> pow_m(N + 1);
    pow_m[0] = 1;
    rep(i, N) pow_m[i + 1] = (pow_m[i] * (M-1)) % MOD;

    long long ans = 0;
    rep (k, K + 1) {
        long long cmb = M;
        cmb *= nCr(N-1, k);
        cmb %= MOD;
        cmb *= pow_m[N-1-k];
        cmb %= MOD;
        ans += cmb;
        ans %= MOD;
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    long long K;
    scanf("%lld", &K);
    solve(N, M, K);
    return 0;
}


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

using namespace std;

#define int long long
#define MP make_pair
#define F first
#define S second
#define pi pair<int,int> 
#define sz(s) ((int)s.size())

const unsigned mod = 1e9 + 7;
const unsigned N = 5e5 + 4;

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

  int n;
  cin >> n;
  int rem = n - n / 500 * 500;
  int ans = 1000 * (n / 500);

  ans += 5 * (rem / 5);

  cout << ans << '\n';




  
  
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <complex>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>
#include <valarray>
#include <list>

using namespace std;

typedef long long ll;

template<class T>
struct Pi {
    T x, y;
    Pi() {}
    Pi(T xx, T yy) {
        x = xx; y = yy;
    }
    bool operator<(const Pi &r) const {
        if (x != r.x) return x < r.x;
        return y < r.y;
    }
    bool operator>(const Pi &r) const {
        if (x != r.x) return x > r.x;
        return y > r.y;
    }
    bool operator==(const Pi &r) const {
        if (x != r.x) return false;
        return y == r.y;
    }
};

template<class T>
struct Ti {
    T x, y, z;
    Ti() {}
    Ti(T xx, T yy, T zz) {
        x = xx; y = yy; z = zz;
    }
    bool operator<(const Ti &r) const {
        if (x != r.x) return x < r.x;
        if (y != r.y) return y < r.y;
        return z < r.z;
    }
    bool operator>(const Ti &r) const {
        if (x != r.x) return x > r.x;
        if (y != r.y) return y > r.y;
        return z > r.z;
    }
    bool operator==(const Ti &r) const {
        if (x != r.x) return false;
        if (y != r.y) return false;
        return z == r.z;
    }
};

const int MN = 200;
const ll INF = 1LL<<50;

ll r[MN];
int s[MN], sum[MN];
ll dp[MN][MN];
bool used[MN][MN];

ll solve(int i, int ws) {
    if (i == -1) return INF;
    if (i == 0) {
        if (ws <= s[0]) return -INF;
        else return INF;
    }
    if (ws <= 0) return -INF;
    if (used[i][ws]) return dp[i][ws];
    used[i][ws] = true;

    ll res = 1-r[i]-solve(i-1, sum[i]-ws+1);
    res = min(res, max(1LL, 1+r[i]+solve(i-1, ws)));
    return (dp[i][ws] = res);
}

int main() {
    int n; ll a, b;
    cin >> n >> a >> b;
    for (int i = n-1; i >= 0; i--) {
        cin >> r[i] >> s[i];
    }
    sum[0] = s[0];
    for (int i = 1; i < n; i++) {
        sum[i] = sum[i-1] + s[i];
    }
    ll ad = a-b;
    ll ar = -1;
    for (int i = 0; i < MN; i++) {
        if (solve(n-1, i) <= ad) ar = i;
    }
    cout << ar << " " << sum[n-1]-ar << endl;
    return 0;
}

Measured memory_bytes: 1444
#include<iostream>
#include<string>
using namespace std;
int main (void)
{
	long X;
	cin >> X;
	int GohyakuYen = (int) (X / 500);
	int Goen = ((int) (X % 500)) / 5;
	long Answer = 1000*((long)GohyakuYen) + ((long)Goen*5);
	cout << Answer << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

alice = 0
bob = 0

for i in range(n + 1):
    max_index = a.index(max(a))

    if i % 2 == 0:
        alice += max(a)

    else:
        bob += max(a)

    a[max_index] = 0

print(alice - bob)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 500


int main(){
	int a[N][N];
	f(i, N){
		f(j, N)a[i][j] = 0;
	}
	int n, m, q;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d %d", &n,&m,&q);
	f(i, m){
		scanf("%d %d", &x, &y);
		x--;
		y--;
		a[x][y]++;
	}
	f(i, n){
		for(int j=i+1;j<n;j++){
			a[i][j] += a[i][j - 1];
		}
	}
	f(j, n){
		for (int i = j; i > 0; i--){
			a[i - 1][j] += a[i][j];
		}
	}
	f(i, q){
		scanf("%d %d", &x, &y);
		x--;
		y--;
		printf("%d\n", a[x][y]);
	}



	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i, n)cin >> v[i];

    ll ans = 0;
    rep(left, min(n, k)+1)rep(right, min(n-left, k-left)+1){
        vector<ll> res = v;
        res.erase(res.begin()+left, res.end()-right);

        sort(ALL(res));

       rep(i, k-left-right){
            if(res.empty() || res.front() >= 0)break;
            res.erase(res.begin());
        }

        ans = max(ans, accumulate(ALL(res), 0LL));
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632