akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    int a,b;
    char op;
    cin>>a>>op>>b;
    if(op=='+')cout<<a+b<<endl;
    else cout<<a-b<<endl;
   
}

   


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

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

using namespace std;

int main(){
  string s;cin>>s;
  int result=0;
  rep(i, s.size())if(s[i]=='1')result++;
  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <numeric>
using namespace std;

typedef long long LL; typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,a[110],cnt=0;
    vector<int> ans;

    cin >> n >> m;
    REP(i,m){
        cin >> a[i];
        if(a[i]%2==1) {
            swap(a[i],a[cnt]);
            cnt++;
        }
    }

    if(cnt>2){
        cout << "Impossible" <<endl;
        return 0;
    }
    if(m!=1)swap(a[1],a[m-1]);
    REP(i,m-1) cout << a[i] <<' ';
    cout << a[m-1]<<endl;
    if(m==1){
        a[1]=0;
        m=2;
    }
    cout << (a[0]>1?m:m-1) <<endl;
    REP(i,m-1){
        if(i==0) {if(a[0]>1) cout <<a[i]-1<<' ';}
        else cout << a[i] <<' ';
    }
    cout << a[m-1]+1<<endl;



    return 0;
}


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

int main() {
  string s; cin >> s;
  bool f = false;
  rep(i, 3)
    if (s[i] == '7') f = true;
  puts(f ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define MAX (int)1e+5

int main() {
    int N;
    int a;
    pair<int, int> A[MAX];

    cin >> N;
    
    for (int i=0; i<N; i++) {
        cin >> a;
        A[i] = make_pair(a, i+1);
    }

    sort(A, A+N);

    for (int i=0; i<N; i++) printf("%d ", A[i].second);

    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using   namespace      std;
typedef long long      LL;
typedef vector<int>    VI;
typedef pair<int,int>  PII;

int main(){

	string s;
	cin>> s;
	sort(s.begin(), s.end());
	if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3])
		cout<< "Yes"<< endl;
	else
		cout<< "No"<< endl;

	return 0;
}

Measured memory_bytes: 256
#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  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    LL N,M;cin >> N >> M;
    if(N >= 2 && M >= 2)cout << (N - 2) * (M - 2) << endl;
    else if(N == 1 && M == 1)cout << 1 << endl; 
    else if(N == 1)cout << M - 2 << endl;
    else if(M == 1)cout << N - 2 << endl;
}

Measured memory_bytes: 256
#include<iostream> 
using namespace std; 
int main()
{ int a, b, x;
 cin >> a >> b >> x;
 if( a > x ){
 cout << "NO";
 return 0;
 }
else{
 if( b < x - a ){
 cout << "NO";
 return 0;
  }}
  cout << "YES";
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
    public static int helperFunc(int num1, int num2) { 
        if (num1 == 0) {
          return num2; 
        }
        if (num2 == 0) {
          return num1; 
        } 
        if (num1 == num2) { 
            return num1;
        }
       
        if (num1 > num2) {
        	return helperFunc(num1-num2, num2);
        } else {
        	return helperFunc(num1, num2-num1);
        } 
    } 
	      

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		
		System.out.println(helperFunc(a,b));

	}

}


Measured memory_bytes: 26124
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = list(iss())
    S = S[:-1]
    while S[:len(S) // 2] != S[len(S) // 2:]: S = S[:-1]
    print(len(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N = int(input())
S = input()
from collections import deque

def is_ok(l):
    hs = set()
    q = deque()
    for i in range(N-l+1):
        h = hash(S[i:i+l])
        if h in hs:
            return True
        q.append(h)
        if len(q) >= l:
            hs.add(q.popleft())
    return False

ok = 0
ng = N//2+1
while ng-ok > 1:
    m = (ng+ok)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)

Measured memory_bytes: 3712
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class AC>void r(AC &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int x,y;
int main(){
	r(x);r(y);
	printf("%.10lf\n",(double)x/y);
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>

int main() {
    ll n;bool flag=true; cin>>n;
    vl a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    if(n%2==0){
        for(int i=0;i<n-1;i+=2)if(a[i]!=a[i+1])flag=false;
        if(a[0]==0)flag=false;
    }else{
        if(a[0]!=0)flag=false;
        if(n>1)for(int i=1;i<n-1;i+=2)if(a[i]!=a[i+1])flag=false;
    }
    ll ans=1;rep(i,n/2)ans=ans*2%1000000007;
    if(flag)cout<<ans<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
ll mod = 1000000007;
signed main(){

    int h,w,x,y;
    cin >> h >> w;
    vector<vector<char>> v(h,vector<char> (w));

    for(int i=0;i < h;i++)
    {
        for(int j=0;j < w;j++)
        {
            cin >> v.at(i).at(j);
        }
    }

    queue<int> q;
    q.push(0);q.push(0);

    while(q.size()>0){
        x=q.front();
        q.pop();
        y=q.front();
        q.pop();
        v.at(x).at(y)='.';
        bool f=false;

        if(x<h-1 && v.at(x+1).at(y)=='#'){
            q.push(x+1);
            q.push(y);
            f=true;
        }
        if(y<w-1 && v.at(x).at(y+1)=='#'&& f==false){
            q.push(x);
            q.push(y+1);
        }
    }
    bool flag=false;
    for(int i=0;i < h;i++)
    {
        for(int j=0;j < w;j++)
        {
            if(v.at(i).at(j)=='#'){
                flag=true;
            }
        }
    }


    if(x==h-1 && y==w-1 && flag==false){
            cout << "Possible" << endl;
        }else{
            cout << "Impossible" << endl;
        }

}




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

int main(){
  string S;
  cin >> S;
  sort(S.begin(),S.end());
  if(S=="abc"){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin>>n; vector<vector<int>>v(n,vector<int>(3)),dp(v);
  for(int i=0;i<n;i++)
  {
  	
  	cin>>v[i][0]>>v[i][1]>>v[i][2];
  	if(i>0)
  	{
		dp[i][0]=max(dp[i-1][1]+v[i][0],dp[i-1][2]+v[i][0]);
		dp[i][1]=max(dp[i-1][2]+v[i][1],dp[i-1][0]+v[i][1])  ;
		dp[i][2]=max(dp[i-1][1]+v[i][2],dp[i-1][0]+v[i][2])  ; 		
	}  	
	else
	dp[i][0]=v[i][0],dp[i][1]=v[i][1],dp[i][2]=v[i][2];
	
  }
  
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,i,j,a,b,z=0,c,d;

    scanf("%d%d",&a,&b);

   for(i=0;i<=a;i++)
   {
    c=a-i;
    d=c*4+i*2;
    if(d==b)
    z=1;

   }
   if(z==1)
   printf("Yes\n");
   else
   printf("No\n");
}   

Measured memory_bytes: 3760
import math
def main():
    a,b,x = map(int,input().split())
    if x >= a*a*b/2:
        print(math.degrees(math.atan(2*(a*a*b-x)/a**3)))
    else:
        print(90-math.degrees(math.atan(2*x/(a*b*b))))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#pragma 03
using namespace std;
bool accessed[100005];
vector <int> adjacent[100005];
void dfs(int i){
	if (accessed[i]) return;
	accessed[i] = true;
	for (int j = 0; j<adjacent[i].size(); j++) dfs(adjacent[i][j]);
}
int main(){
	int n, m, x, y, z;
	for (int i = 0; i<100005; i++){
		accessed[i] = false;
		adjacent[i].clear();
	}
	cin >> n >> m;
	for (int i = 0; i<m; i++){
		cin >> x >> y >> z;
		adjacent[x].push_back(y);
		adjacent[y].push_back(x);
	}
	int components = 0;
	for (int i = 1; i<=n; i++){
		if (!accessed[i]){
			dfs(i);
			components++;
		}
	}
	cout << components << endl;
	return 0;
}

Measured memory_bytes: 8960
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define mp(a, b) make_pair((a),(b))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;
constexpr double eps = 0.000000001;

int main() {
    ll n, x, a[100000], r = 0;
    cin >> n >> x;
    rep(i, n)cin >> a[i];
    rep(i, n - 1) {
        if (a[i] + a[i + 1] > x) {
            ll v = a[i] + a[i + 1] - x;
            r += v;
            a[i + 1] = max((ll) 0, a[i + 1] - v);
        }
    }
    cout << r << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
signed main(){
    long long h , w , ans;
    cin>>h>>w;
    if(h == 1 || w == 1){
        ans=1;
    } else {
        ans=(h/2)*w;
        if(h%2 == 1){
            ans+=(w/2)+(w%2);
        }
    }
    cout<<ans<<endl;
    return(0);
}


Measured memory_bytes: 256
/***************************************************
 * Problem Name : C - Vacation.cpp
 * Problem Link :
 * OJ           :
 * Verdict      : Trying
 * Date         : 2019-01-26
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdlib>
#include<deque>
#include<stack>
#include<map>
#include<set>
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define FileRead freopen ("/home/saikat/Desktop/logN/input.txt", "r", stdin);
#define FileWrite freopen ("/home/saikat/Desktop/logN/output.txt", "w", stdout);
#define SET(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair <ll, ll>
#define debug cout <<"#########\n";
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define Pow2(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define Max3(a, b, c) max(a, max(b, c))
#define Min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 1000005
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
std::string NumberToString ( T Number ) {
    std::ostringstream ss;
    ss << Number;
    return ss.str();
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
int ar[MAX][5];
int dp[MAX][5];
int n;
int fun (int i, int t) {
    if (i == n - 1) {
        return ar[i][t];
    }

    if (dp[i][t] != -1) return dp[i][t];

    int ret1 = 0, ret2 = 0;

    if (t == 0) {
        ret1 = ar[i][t] + fun (i + 1, 1);
        ret2 = ar[i][t] + fun (i + 1, 2);

    } else if (t == 1) {
        ret1 = ar[i][t] + fun (i + 1, 0);
        ret2 = ar[i][t] + fun (i + 1, 2);

    } else {
        ret1 = ar[i][t] + fun (i + 1, 0);
        ret2 = ar[i][t] + fun (i + 1, 1);
    }

    return dp[i][t] = max (ret1, ret2);
}
int main () {
    __FastIO;
    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> ar[i][j];
        }
    }

    SET (dp, -1);
    int a = fun (0, 0);
    int b = fun (0, 1);
    int c = fun (0, 2);
    cout << Max3 (a, b, c) << "\n";
    return 0;
}


Measured memory_bytes: 29056
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
#define mod 1000000007
#define pie 3.14159265358979323846
void solve()
{
	int n,k,i,s=0;
	cin>>n>>k;
	int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for(i=0;i<k;i++)
	s+=a[i];
	cout<<s;
}
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


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

const int MAXN = 3 * 1e2;
double dp[MAXN+5][MAXN+5][MAXN+5];

double calcdp(int n, int c1, int c2, int c3){
	if(dp[c1][c2][c3] > 0) return dp[c1][c2][c3];
	
	double p[4];
	p[1] = (double)c1/n;
	p[2] = (double)c2/n;
	p[3] = (double)c3/n;
	p[0] = 1 - p[1] - p[2] - p[3];
	if(p[0] == 1) return dp[c1][c2][c3] = 0;
	
	double res = 1;
	if(c1 > 0) res += calcdp(n,c1-1,c2,c3) * p[1];
	if(c2 > 0) res += calcdp(n,c1+1,c2-1,c3) * p[2];
	if(c3 > 0) res += calcdp(n,c1,c2+1,c3-1) * p[3];
	res /= 1 - p[0];
	
	return dp[c1][c2][c3] = res;
}


int main(){
	int n;
	cin >> n;
	vector<int> cnt(4);
	rep(i,n){
		int a;
		cin >> a;
		cnt[a]++;
	}
	
	printf("%.10f", calcdp(n,cnt[1],cnt[2],cnt[3]));
	return 0;
}

Measured memory_bytes: 219392
participant = int(input())
rate = list(map(int, input().split()))
ratecolorCheck = [0] *8
maxColor, minColor = 0, 0
for i in range(participant):
  if 1 <= rate[i] and rate[i] <= 399:
    ratecolorCheck[0] = 1
  elif 400 <= rate[i] and rate[i] <= 799:
    ratecolorCheck[1] = 1
  elif 800 <= rate[i] and rate[i] <= 1199:
    ratecolorCheck[2] = 1
  elif 1200 <= rate[i] and rate[i] <= 1599:
    ratecolorCheck[3] = 1
  elif 1600 <= rate[i] and rate[i] <= 1999:
    ratecolorCheck[4] = 1
  elif 2000 <= rate[i] and rate[i] <= 2399:
    ratecolorCheck[5] = 1
  elif 2400 <= rate[i] and rate[i] <= 2799:
    ratecolorCheck[6] = 1
  elif 2800 <= rate[i] and rate[i] <= 3199:
    ratecolorCheck[7] = 1
  else:
    maxColor += 1
for i in range(8):
  if ratecolorCheck[i] == 1:
    minColor += 1
    maxColor += 1
if minColor == 0:
  minColor = 1
print(str(minColor) + " " + str(maxColor))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int Mx = 0, num;
int A [1001], B[1001], K[1001];
int main(){
    int N, M;
    int i, j;
    cin >> N >> M;
    for (j=1; j<=M; j++) { K[j] = 0; }
    for (i=1; i<=N; i++) { cin >> A[i]; }
    for (j=1; j<=M; j++) { cin >> B[j]; }
    for (j=1; j<=M; j++) {
        for (i=1; i<=N; i++) {
            if(A[i] <= B[j]) {
                K[i]++;
                if( Mx < K[i] ){ Mx = K[i]; num = i; }
                break;
            }
        }
    }
    cout << num << endl;
    return 0; 
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
int main() {
	int n;
	cin >> n;
	VI p(n), sp(n);
	REP(i, n) {
		cin >> p[i];
		sp[i] = p[i];
	}
	sort(ALL(sp));
	int f = 0;
	REP(i, n) {
		if (p[i] != sp[i])
			f++;
	}
	if (f == 2 || f == 0)
		cout << "YES";
	else
		cout << "NO";
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <limits>
#include <numeric>
#include <utility>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#ifndef debug_on
#define debug_on 0
#endif

#define dbg \
    if(debug_on) cerr << "DEBUG:"
#define ast(cond)           \
    do {                    \
        if((cond) == false) \
        {                   \
            if(debug_on)    \
            cerr << "ASSERT" << #cond " failed at line:" << __LINE__ << endl;   \
            exit(1);        \
        }                   \
    }while(0)

int Cost(const int A[3])
{
    int cost = 0;
    cost += abs(A[1] - A[0]);
    cost += abs(A[2] - A[1]);
    return cost;
}
int main(int, char *[])
{
    int A[3];
    for(int i= 0; i < 3; ++i)
        cin >> A[i];
    sort(A, A + 3);
    int cost = std::numeric_limits<int>::max();
    do
    {
        const int c = Cost(A);
        cost = min(c, cost);
    } while(next_permutation(A, A + 3));

    cout << cost << endl;
    return 0;
}


Measured memory_bytes: 384
S = str(input())
flag = 0
a = S[:(len(S)-1)//2]
b = S[(len(S) + 3)//2-1:]

if S == S[::-1] and a == a[::-1] and b == b[::-1]:
  flag = 1
if flag == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 200000
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	int ren[SIZE];
	void init()
	{
		for (int i = 0; i<SIZE; i++)
		{
			par[i] = i;
			ran[i] = 0;
			ren[i] = 1;
		}
	}
	int find(int a)
	{
		if (a == par[a])return a;
		else return par[a] = find(par[a]);
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (ran[a]>ran[b])
		{
			par[b] = a;
			ren[a] += ren[b];
		}
		else
		{
			par[a] = b;
			ren[b] += ren[a];
		}
		if (ran[a] == ran[b])ran[b]++;
	}
};
unionfind uf;
int dat[200000];
typedef long long ll;
int main()
{
	int num;
	scanf("%d", &num);
	uf.init();
	vector<int>v;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		z--;
		v.push_back(z);
		dat[z] = i;
	}
	ll ans = 0;
	for (int i = num - 1; i >= 0; i--)
	{
		ll m = 0;
		if (dat[i] != 0)if (v[dat[i] - 1] > i)
		{
			ll t = uf.ren[uf.find(dat[i] - 1)];
			m += t*(t + 1) / 2;
			uf.unite(dat[i], dat[i] - 1);
		}
		if (dat[i] != num - 1)if (v[dat[i] + 1] > i)
		{
			ll t = uf.ren[uf.find(dat[i] + 1)];
			m += t*(t + 1) / 2;
			uf.unite(dat[i], dat[i] + 1);
		}
		ll t = uf.ren[uf.find(dat[i])];
		ans += (ll)(i + 1)*(t*(t + 1) / 2 - m);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 4472
#include <bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007

using namespace std;
typedef long long ll;

vector<int> adj[2510];
int d[2510];
bool visited[2510];

void bfs(int s)
{
	queue<int> search; search.push(s);
	d[s] = 0;
	while (!search.empty())
	{
		int u = search.front(); search.pop();
		for (int i = 0; i < adj[u].size(); i++)
		{
			int v = adj[u][i];
			if (d[v] == INF)
			{
				search.push(v);
				d[v] = d[u] + 1;
			}
		}
	}
}

int main()
{
	int h, w;
	cin >> h >> w;
	
	char grid[h + 2][w + 2];
	
	for (int i = 0; i < 2510; i++)
	{
		d[i] = INF;
	}
	
	int count = 0;
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			cin >> grid[i][j];
			if (grid[i][j] == '#') count++;
		}
	}
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			int vertex = (i - 1) * w + j;
			if (grid[i][j] == '.')
			{
				if (grid[i - 1][j] == '.') 
				{
					adj[vertex].push_back(vertex - w);
				}
				if (grid[i][j - 1] == '.') 
				{
					adj[vertex].push_back(vertex - 1);
				}
				if (grid[i][j + 1] == '.') 
				{
					adj[vertex].push_back(vertex + 1);
				}
				if (grid[i + 1][j] == '.')
				{
					adj[vertex].push_back(vertex + w);
				}
			}
		}
	}
	bfs(1);
	cout << ((d[h * w] != INF) ? h * w - d[h * w] - 1 - count : -1) << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    private String str;
    
    public Main(String str) {
        this.str = str;
    }
    
    public static void main(String[] args) {
        Main obj = new Main(scn.next());
        int lim = scn.nextInt();
        for(int i = 0; i < lim; i++) {
            switch(scn.next()) {
              case "print":
                obj.print(scn.nextInt(), scn.nextInt() + 1);
                break;
              case "reverse":
                obj.reverse(scn.nextInt(), scn.nextInt() + 1);
                break;
              case "replace":
                obj.replace(scn.nextInt(), scn.nextInt() + 1, scn.next());
                break;
            }
        }
    }
    
    public void print(int a, int b) {
        System.out.println(str.substring(a, b));
    }
    
    public void reverse(int a, int b) {
        String pre = str.substring(0, a);
        String suf = str.substring(b);
        StringBuilder sb = new StringBuilder(str.substring(a, b));
        str = pre + sb.reverse().toString() + suf;
    }
    
    public void replace(int a, int b, String ptn) {
        String pre = str.substring(0, a);
        String suf = str.substring(b);
        str = pre + ptn + suf;
    }
}

Measured memory_bytes: 30060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

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


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
using namespace std;

int main() {
	string S1, S2; cin >> S1 >> S2;
	if (S1[0] == S2[2] && S1[1] == S2[1] && S1[2] == S2[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
	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 k = sc.nextInt();
        int x = sc.nextInt();

        for (int i = x - k + 1; i < k + x; i++) {
            System.out.print(i + " ");
        }

        System.out.println();
	}
}


Measured memory_bytes: 22608
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int maxd = 2e5+10;
int arr[maxd],id[maxd],n,l[maxd],r[maxd],ll[maxd],rr[maxd];
int ls[maxd<<4],rs[maxd<<4],sz[maxd<<4],tot,rt[maxd];
void insert(int &t,int last,int l,int r,int x)
{
    t = ++tot;  ls[t] = ls[last],rs[t] = rs[last];
    sz[t] =  sz[last]+1;
    if(l==r) return ;
    int mid = (l+r)>>1;
    if(x <= mid) insert(ls[t],ls[last],l,mid,x);
    else insert(rs[t],rs[last],mid+1,r,x);
}
int query(int x,int y,int l,int r)
{
    if(sz[y] - sz[x] == 0 ) return 0;
    if(l==r) return l;
    int mid = (l+r)>>1;
    if(sz[rs[y]] - sz[rs[x]]) return query(rs[x],rs[y],mid+1,r);
    else return query(ls[x],ls[y],l,mid);
}
int findl(int x,int y,int v)
{
    int ans = y;
    int l = x,r = y;
    while(l<=r)
    {
        int mid = (l+r)>>1;
        //printf("%d %d %d\n",mid,y,query(rt[mid],rt[y],1,n+2));
        if(query(rt[mid-1],rt[y],1,n) <=v) ans = mid, r = mid-1;
        else l = mid+1;
    }
    //printf("%d\n",ans);
    if(arr[ans] <= v) ans--;
    return ans;
}
int findr(int x,int y,int v)
{
    int ans = x;
    int l = x,r = y;
    while(l<=r)
    {
        int mid = (l+r)>>1;
        if(query(rt[x-1],rt[mid],1,n) <=v) ans = mid, l = mid+1;
        else r = mid-1;
    }
    if(arr[ans] <= v) ans++;
    return ans;
}
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&arr[i]);
    for(int i=1;i<=n;i++) insert(rt[i],rt[i-1],1,n,arr[i]);
    long long ans = 0ll;
    for(int i=1;i<=n;i++)
    {
        l[i] = findl(1,i,arr[i]);
        r[i] = findr(i,n,arr[i]);
        rr[i] = min(findr(r[i]+1,n,arr[i]),n+1);
        ll[i] = max(findl(1,l[i]-1,arr[i]),0);
        //printf("%d %d %d %d %d\n",ll[i],l[i],arr[i],r[i],rr[i]);
    }
    for(int i=1;i<=n;i++)
    {
        if(r[i]!=n+1) ans += 1ll*(rr[i]-r[i]) * (i-l[i]) * arr[i]; 
        if(l[i]!=0) ans += 1ll*(l[i]-ll[i]) * (r[i]-i) * arr[i];
        //printf("%d %d %lld\n",l[i],r[i],ans - last);
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 28032
#include<stdio.h>

int main(){

    int m,n;
    scanf("%d %d",&m,&n);
    int v[m][n];
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            scanf("%d",&v[i][j]);
        }
    }
    int c[n];
    for(int i=0;i<n;i++){
        scanf("%d",&c[i]);
    }
    int sum;
    for(int i=0;i<m;i++){
        sum=0;
        for(int j=0;j<n;j++){
            sum=sum+v[i][j]*c[j];
        }
        printf("%d\n",sum);
    }

    return 0;
}



Measured memory_bytes: 2088
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n;
double p[3000],dp[3000][3000];
int main() {
	scanf("%d",&n);
	int i,j;
	for(i=1;i<=n;i++)scanf("%lf",p+i);
	dp[0][0]=1;
	double res=0;
	for(i=1;i<=n;i++) {
		for(j=0;j<=i;j++) {
			dp[i][j]+=(1-p[i])*dp[i-1][j];
			if(j) dp[i][j]+=p[i]*dp[i-1][j-1];
		}
	}
	for(i=(n+1)/2;i<=n;i++)res+=dp[n][i];
	printf("%.10f", res);
	return 0;
}

Measured memory_bytes: 68864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;
#define top front
int main(){
  int n;
  cin >> n;
  queue<char> c;
  rep(i, n){
    char tmp;
    cin >> tmp;
    c.push(tmp);
  }
  ll ans;
  bool old;
  char k = c.front();
  c.pop();
  if(k == c.front()){
    c.pop();
    ans = 6;
    old = true;
  }else{
    ans = 3;
    old = false;
  }
  while(!c.empty()){
    k = c.top();
    c.pop();
    if(k == c.top()){
      if(old) ans = ans * 3 % MOD;
      else ans = ans * 2 % MOD;
      old = true;
      c.pop();
    }else{
      if(!old) ans = ans * 2 % MOD;
      old = false;
    }
  }
  cout << ans <<endl;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[4];
    cin>>s;
    if(s[0]==s[1] && s[1]==s[2] && s[2]==s[1])
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

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

using namespace std;

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

char piece[9][5];
char put[3][3][4];

bool match(char a,char b){ return a-b=='a'-'A' || a-b=='A'-'a'; }

int dfs(int y,int x,bool *used){
	if(y==3) return 1;
	if(x==3) return dfs(y+1,0,used);

	int res=0;
	rep(i,9) if(!used[i]) rep(j,4) {
		bool ok=true;
		for(int k=1;k<=2;k++){
			int yy=y+dy[k],xx=x+dx[k];
			if(0<=yy && 0<=xx && !match(piece[i][(j+k)%4],put[yy][xx][(k+2)%4])) ok=false;
		}

		if(ok){
			rep(k,4) put[y][x][k]=piece[i][(j+k)%4];
			used[i]=true;
			res+=dfs(y,x+1,used);
			used[i]=false;
		}
	}
	return res;
}

int main(){
	int T; scanf("%d",&T);
	while(T--){
		rep(i,9){
			scanf("%s",piece[i]);
			rep(j,2) swap(piece[i][j],piece[i][3-j]);
		}

		bool used[9]={};
		printf("%d\n",dfs(0,0,used));
	}

	return 0;
}

Measured memory_bytes: 764
n=STDIN.gets.to_i

1.upto(n) {|i|
    flag=0
    n = i
    while n > 0 do
      flag=1 if (n % 10) == 3
      n /= 10
    end
    printf(" %d",i) if flag==1 ||  ((i % 3)==0)
  }
  printf("\n");

Measured memory_bytes: 8724
#include <iostream>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
const LL &lim = 1e18;


int main()
{
    cin.sync_with_stdio(0);

    int N;
    cin >> N;

    bool zero = false, surpasses = false;
    LL res = 1;
    while (N--)
    {
        LL nr;
        cin >> nr;
        
        if (nr != 0 && res > lim / nr)
        {
            surpasses = true;
        }
        else
        {
            res *= nr;
        }
        zero |= !nr;
    }

    if (zero)
    {
        cout << "0";
        return 0;
    }
    if (surpasses)
    {
        cout << "-1";
        return 0;
    }

    cout << res;
}

Measured memory_bytes: 3588
H,W = map(int, raw_input().split())
C = [map(int, raw_input().split()) for _ in range(H)]

DP = [[0]*(W+1) for _ in range(H+1)]

for i in range(1, H+1):
    for j in range(1, W+1):
        if C[i-1][j-1] != 1:
            DP[i][j] = min(
                DP[i-1][j-1],
                DP[i-1][j],
                DP[i][j-1]) + 1

ans = max([max(dp) for dp in DP]) ** 2
print ans


Measured memory_bytes: 47608
#include<bits/stdc++.h>
using namespace std;
bool a[101][101];
int main(){
	int m,n;
	char s;
	memset(a,0,sizeof(a));
	cin>>m>>n;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			cin>>s;
			if(s=='#') a[i][j]=1; 
		}
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(a[i][j]==1) cout<<"#";
			else{
                cout<<a[i+1][j+1]+a[i+1][j-1]+a[i+1][j]+a[i][j+1]+a[i][j-1]+a[i-1][j+1]+a[i-1][j]+a[i-1][j-1];
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
# B
a = int(input())
b = int(input())
c = int(input())
x = int(input())

total = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            sum_ = 500*i + 100*j + 50*k
            if sum_ == x:
                total += 1
print(total)

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

int main()
{
    int n, arr[100+5], ans = 10000000;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 0; i < n; i++)
    {
        ans = min(ans, abs(accumulate(arr, arr + i, 0) - accumulate(arr + i, arr + n, 0)));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O #-}
import Data.List

mp = 1000000007
invmod a p = invmod' a p p 0 1
    where invmod' a p q x y
            | amq==0 = mod (x+p) p
            | otherwise = invmod' q p amq (y-div a q*x) x
            where amq = mod a q
divmod a b p = mod (a * invmod b p) p
cmbmod n k p = foldl' (\a i->divmod (mod (a*(n-i+1)) p) i p) 1 [1..k]

main = do
    (h:w:a:b:_)<-map read.words<$>getLine::IO[Int]
    print $ sol h w a b

sol h w a b = foldl' (\s x-> mod (s+x) mp) 0 $ unfoldr psi (aa,na,ka, bb,nb,kb)
    where
        na = h-a-1+b
        ka = b
        aa = cmbmod na ka mp
        nb = a-1+w-b-1
        kb = w-b-1
        bb = cmbmod nb kb mp
psi (_,_,_,_,_,-1) = Nothing
psi (aa,_,_,_,_,0) = Just(aa, (0,0,0,0,0,-1))
psi dt@(aa,na,ka,bb,nb,kb) = Just ((aa*bb)`mod` mp, (aa',na+1,ka+1, bb', nb-1,kb-1))
    where
        aa' = divmod ((aa*(na+1))`mod` mp) (ka+1) mp
        bb' = divmod ((bb*kb)`mod` mp) nb mp

Measured memory_bytes: 1020
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long Int;


Int n, m, k;
Int x[108000];
Int nxt[64][108000];
Int p;
Int dif[108000];
Int finaly[108000];
Int ans[108000];

int main(){
	cin >> n;
	for(Int i = 0;i < n;i++){
		cin >> x[i];
		nxt[0][i] = i;
	}
	for(Int i = 0;i < n-1;i++){
		dif[i] = x[i+1] - x[i];
	}
	cin >> m >> k;
	for(Int i = 0;i < m;i++){
		cin >> p;
		p-=2;
		swap(nxt[0][p], nxt[0][p+1]);
	}
	for(Int i = 1;i < 63;i++){
		for(Int j = 0;j < n;j++){
			nxt[i][j] = nxt[i-1][nxt[i-1][j]];
		}
	}
	
	for(Int i = 0;i < n-1;i++){
		finaly[i] = i;
		Int tk = k;
		for(Int j = 62;j >= 0;j--){
			if(tk >= (1LL << j)){
				finaly[i] = nxt[j][finaly[i]];
				tk -= (1LL << j);
			}
		}
	}
	
	ans[0] = x[0];
	for(Int i = 0;i < n-1;i++){
		ans[i+1] = ans[i] + dif[finaly[i]];
	}
	
	for(Int i = 0;i < n;i++)cout << ans[i] << endl;
	
	return 0;
		
}


Measured memory_bytes: 53888
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

struct StronglyConnectedComponents {
  vector<vector<int>> adj;

  StronglyConnectedComponents(int n) : adj(n) {}
  void add_edge(int src, int dst) { adj[src].push_back(dst); }
  pair<vector<vector<int>>, vector<int>> get_SCC() {
    vector<vector<int>> scc;
    vector<int> S, B, index(adj.size());
    function<void(int)> dfs = [&](int u) {
      B.push_back(index[u] = S.size());
      S.push_back(u);
      for (int v : adj[u]) {
        if (!index[v])
          dfs(v);
        else
          while (index[v] < B.back()) B.pop_back();
      }
      if (index[u] == B.back()) {
        scc.push_back({});
        B.pop_back();
        for (; index[u] < (int)S.size(); S.pop_back()) {
          scc.back().push_back(S.back());
          index[S.back()] = adj.size() + scc.size();
        }
      }
    };
    for (size_t u = 0; u < adj.size(); u++)
      if (!index[u]) dfs(u);
    reverse(scc.begin(), scc.end());
    for (size_t u = 0; u < adj.size(); u++)
      index[u] = scc.size() - index[u] + adj.size();
    return make_pair(scc, index);
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int node[N][N];
  int M = 0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < i; j++) node[i][j] = node[j][i] = M++;
  debug(M);
  StronglyConnectedComponents graph(M);
  for (int i = 0; i < N; i++) {
    int prev = -1;
    for (int j = 0; j < N - 1; j++) {
      int A;
      cin >> A;
      int v = node[i][--A];
      if (prev != -1) graph.add_edge(prev, v);
      prev = v;
    }
  }
  auto scc = graph.get_SCC();
  auto id = scc.second;
  if ((int)scc.first.size() < M) {
    cout << -1 << '\n';
  } else {
    int dp[M];
    fill(dp, dp + M, 1);
    int ans = 0;
    for (int i = 0; i < M; i++) {
      int v = scc.first[i][0];
      for (int u : graph.adj[v]) {
        int j = id[u];
        dp[j] = max(dp[j], dp[i] + 1);
      }
      ans = max(ans, dp[i]);
    }
    cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 93244
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::input;
use std::cmp::{max, min};
use std::collections::{HashMap, HashSet};

fn main() {
    input! {
        S: String,
    }
    print!("{}", S);
    let T = S.chars().collect::<Vec<char>>();
    if T[S.len() - 1] == 's' {
        println!("es");
    } else {
        println!("s");
    }
}


Measured memory_bytes: 2184
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N,K; cin >> N >> K;
    int ans = 0;
    REP(i,N){
        int tmp; cin >> tmp;
        if(tmp >= K) ans++;
    }
    cout << ans << endl;

}


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

using namespace std;
typedef long long LL;
const int INF=10000;

int main(){
  int A[5];
  rep(i,5) cin >> A[i];
  int ans=INF;
  do {
    int t=0;
    rep(i,5){
      t=(t+9)/10*10;
      t+=A[i];
    }
    if(t<ans) ans=t;
  } while(next_permutation(A,A+5));
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int X,Y,n,m,x[100],y[100],i,maxx = -100,miny = 100;
    scanf("%d %d %d %d",&n,&m,&X,&Y);
    maxx = X;
    miny = Y;
    for (i = 0;i < n;i++) {
        scanf("%d",&x[i]);
        if (x[i] > maxx) maxx = x[i];
    }
    for (i = 0;i < m;i++) {
        scanf("%d",&y[i]);
        if (y[i] < miny) miny = y[i];
    }
    if (maxx < miny) {
        printf("No War\n");
    } else {
        printf("War\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define ALL(v) (v).begin(), (v).end()
//cout << std::fixed << std::setprecision(15) << y << endl;

int main(){
  ll N, K;  cin >> N >> K;
  VL x(N); 

  rep(i,0,N) cin >> x[i];
  ll ans = 1e18+5; ll tmp;
  rep(i,0,N){
    if(i > N-K) break;
    ll l, r;
    l = x[i]; r = x[i+K-1];
    tmp = min(abs(l) + abs(l-r), abs(r) + abs(l-r));
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
  string s;
  cin >> s;
  string str="";
  
  for(int i=0;i < s.size();i++){
    if(s[i] == '1'){
      str += '9';
    }
    else str += '1';
  }
  cout << str << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
static const int max_n = 10;
static const int max_d = 10;

bool is_integer(double x){
    return floor(x) == x;
}

int main(void){
    int n,d,ans=0;
    double XX[max_n][max_d];//ここをintにするといけない
    cin >> n >> d;
    for(int i=0; i<n; i++){
        for(int j=0; j<d; j++){
            cin >> XX[i][j];
        }
    }
    //全通り比較
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            double dist=0; //ここをintにするといけない
            for(int k=0; k<d; k++){
                dist += pow(abs(XX[i][k] - XX[j][k]),2);
            }
            dist = sqrt(dist);
            if(is_integer(dist)) ans += 1;
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

const int Maxn=500;

int N,M;
int A[Maxn+5][Maxn+5];

struct Node {
	int a,b,c,d;
	Node(int a1,int b1,int c1,int d1) {
		a=a1,b=b1,c=c1,d=d1;
	}
};
vector<Node> ans;

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d",&N,&M);
	for(int i=1;i<=N;i++)
		for(int j=1;j<=M;j++)
			scanf("%d",&A[i][j]);
	for(int i=1;i<=N;i++)
		for(int j=1;j<M;j++)
			if(A[i][j]&1) {
				ans.push_back(Node(i,j,i,j+1));
				A[i][j+1]++;
			}
	for(int i=1;i<N;i++)
		if(A[i][M]&1) {
			ans.push_back(Node(i,M,i+1,M));
			A[i+1][M]++;
		}
	printf("%d\n",ans.size());
	for(int i=0;i<ans.size();i++)
		printf("%d %d %d %d\n",ans[i].a,ans[i].b,ans[i].c,ans[i].d);
	return 0;
}

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

int main()
{
    long N, y=0, temp=0;
    vector<long> ret;
    cin >> N;
    long sum = N;
    for (long i = 1; i*i <= N; i++)
    {
        if((N%i)==0){
            //cout << i << endl;
            ret.push_back(i);
            if (i * i != N)
                ret.push_back(N / i);
            temp = (i - 1) + (N / i - 1);
        }
        if(sum>temp)
            sum = temp;
    }
    sort(begin(ret), end(ret));
    cout << sum << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n,m;
		ll k;
		cin>>n>>m>>k;
		ll a[n+1],b[m+1];
		a[0]=0;
		b[0]=0;
		FOR(i,1,n+1)
		{
			cin>>a[i];
			a[i]+=a[i-1];
		}
		FOR(i,1,m+1)
		{
			cin>>b[i];
			b[i]+=b[i-1];
		}
		int ans=0;
		int j=m;
		FOR(i,0,n+1)
		{
			if(k<a[i])
			break;
			while(k<(a[i]+b[j]))
			j--;
			ans=max(ans,i+j);
		}
		cout<<ans;
	}
	return 0;
}

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

int main(){
    ll n,k;
    ll wa=0;
    cin >> n >> k;
    vector <ll> a(n);
    rep(i,n){
        cin >> a[i];
        wa+=a[i];
    }
    k+=n;

    ll na;
    na=wa/k;
    ll wa2;
    ll l=na;
    ll m,r;
    r=1001001001001;

    //cout << na << endl;
    while((r-l)!=1){
        wa2=0;
        na=(l+r)/2;
        rep(i,n){
            if(a[i]%na==0){
                wa2+=(a[i]/na);
            }
            else{
            wa2+=(a[i]/na)+1;
            }
        }
        if(wa2<=k){
            r=na;
        }
        else{
            l=na;
        }
    }

    if((k-n)==0 and n==1){
        cout << a[0] << endl;
    }
    else{

    cout << r << endl;
    }
    

    return 0;
}

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

int main(){
    long long n;
    cin >> n;
    if(n % 2 == 1){
        printf("0\n");
        return 0;
    }

    long long count = 0;

    long long r = 10;

    while(r <= n){
        count += n/r;
        r *= 5;
    }

    

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[100],sum;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i],sum+=a[i];
	int ans=1e9,id;
	for(int i=0;i<n;i++)
	{
		if(ans>abs(sum-a[i]*n))
		{
			ans=abs(sum-a[i]*n);
			id=i;
		}
	}
	cout<<id<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 2e3+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

struct P{
    ll a, id;
    bool operator < (const P &rhs) const {
        return a>rhs.a;
    }
}p[maxn];

ll dp[maxn][maxn];

int main() {
    int n=read();
    for(int i=1; i<=n; ++i) {
        p[i].a=read(), p[i].id=i;
    }
    sort(p+1,p+1+n);
    int l=1, r=n;
    ll ans=0;
    for(int i=1; i<=n; ++i) {
        int len=n+1-i;
        for(int j=1; j<=n-len+1; ++j) {
            int l=j, r=l+len-1;
            dp[l+1][r]=max(dp[l+1][r],dp[l][r]+p[i].a*abs(l-p[i].id));
            dp[l][r-1]=max(dp[l][r-1],dp[l][r]+p[i].a*abs(r-p[i].id));
            if(len==1) ans=max({ans,dp[l+1][r],dp[l][r-1]});
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 26300
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int c[3][3];
	REP(i,3) REP(j,3) cin >> c[i][j];
	
	REP(i,3){
		REP(j,3){
			if(c[i][j]+c[j][i]!=c[i][i]+c[j][j]){
				cout << "No\n";
				return 0;
			}
		}
	}
	
	cout << "Yes\n";
	
	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int32_t main()
{
	int n;
	cin >> n;
	vector<int> v;
	for(int i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			if(n/i==i)
			v.push_back(i);
			else
			{
				v.push_back(i);
				v.push_back(n/i);
			}	
		}	
	}
	for(int i=-200;i<=200;i++)
	{
		for(int j=0;j<v.size();j++)
		{
			int a=i+v[j];
			int raj=a*a*a*a*a;
			int rr=i*i*i*i*i;
			
			if((raj-rr)==n)
			{
				cout << a << " " << i;
				return 0;	
			}	
		}	
	}		
}


Measured memory_bytes: 3724
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t;
  cin>>s>>t;
  if(s.size()!=t.size()-1){
    cout<<"No";
    return 0;
  }
  for(int i=0;i<s.size();i++)
    if(s[i]!=t[i]){
      cout<<"No";
      return 0;
    }
  cout<<"Yes";
}

Measured memory_bytes: 3604