akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int N = 200003, M = N << 1;

int n, k;
int a[N], b[N];
char s[N];

int main()
{
    scanf("%s", s + 1);
    if (s[2] == 'R') s[2] = 'B';
    else s[2] = 'R';
    cout << s + 1 << endl;
    return 0;
}

Measured memory_bytes: 3760
n=int(input())
a=list(map(int,input().split()))
ans=0
right=0
np=a[0]
nx=a[0]
for i in range(n):
    left=i
    if i!=0:
        np-=a[left-1]
        nx^=a[left-1]
    while np==nx:
        right+=1
        if right==n:
            break
        np+=a[right]
        nx^=a[right]
    else:
        np-=a[right]
        nx^=a[right]
    right-=1
    ans+=(right-left+1)
print(ans)

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



int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> d(K);
  vector<vector<ll>> A(K);
  rep(i,K)
  {
    cin>>d.at(i);
    rep(j,d.at(i))
    {
      ll kai;
      cin>>kai;
      A.at(i).push_back(kai);
    }
  }
  vector<ll> sunuke(N);
  rep(i,K)
  {
    rep(j,d.at(i))
    {
      sunuke.at(A.at(i).at(j)-1)=1;
    }
  }
  ll ans=0;
  rep(i,N)
  {
    if(sunuke.at(i)==0)
    {
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

long long p[200005];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	long long n, r = 0, w = 0, minm, m = 0;
	char c;
	cin >> n;
	for(long long i = 1; i <= n; ++i){
		cin >> c;
		if(c == 'R'){
		    p[i] = 1;
		    ++r;
		}
		else ++w;
	}
	if(r == 0 or w == 0){
		cout << 0;
		return 0;
	}
	minm = 100000000;
	for(long long i = r + 1; i <= n; ++i) m += p[i];
	minm = min(m, minm);
	cout << minm;

	return 0;
}



Measured memory_bytes: 5152
#include <iostream>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int h, w, a, b;
int ans[1000][1000];

int main() {
	int i, j;
	
	cin >> h >> w >> a >> b;
	
	rep(i, b) {
		rep(j, a) ans[i][j] = 1;
	}
	
	for (i = b; i < h; i++) {
		for (j = a; j < w; j++) {
			ans[i][j] = 1;
		}
	}
	
	rep(i, h) {
		rep(j, w) {
			cout << ans[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>


#define INF 100000000
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; }

using namespace std;

int main(){
  int count=0, i,j,k,n,d,a[100];
  cin >>n;

  for(i=0;i<n;i++)cin >>a[i+1];

  for(i=1;i<n+1;i++){
    if(i!=a[i]){
      count++;
    }
  }

  if(count==2||count==0)cout <<"YES"<<endl;
  else cout <<"NO"<<endl;

  return 0;
}

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

using namespace std;
using ll = long long;

int main(){
    int x;
    cin >> x;
    for(int a = -118; a <= 119; a++){
        for(int b = -119; b <= 118; b++){
            if(a*a*a*a*a - b*b*b*b*b == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }

}

Measured memory_bytes: 3636
N = int(input())
ans = [0 for _ in range(1,10101)]

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            n = x*x + y*y + z*z + x*y + y*z + z*x
            if n < N+1:
                ans[n-1] += 1

print(*ans[:N],sep='\n')

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

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

const int INF = 1e9 + 7;

using namespace std;

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

	int n;
	cin >> n;

	vector<int> x(n);
	rep (i, 0, n)
		cin >> x[i];

	vector<int> s = x;
	sort(s.begin(), s.end());
	int mid_id = n / 2;

	rep (i, 0, n) {
		if (x[i] < s[mid_id])
			cout << s[mid_id] << endl;
		else

			cout << s[mid_id - 1] << endl;
	}

	return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int sx,sy,tx,ty,x,y;

signed main() {
    cin >> sx >> sy >> tx >> ty;
    x = tx-sx;
    y = ty-sy;
    rep(i,y) cout << 'U';
    rep(i,x) cout << 'R';
    rep(i,y) cout << 'D';
    rep(i,x+1) cout << 'L';
    rep(i,y+1) cout << 'U';
    rep(i,x+1) cout << 'R';
    cout << "DR";
    rep(i,y+1) cout << 'D';
    rep(i,x+1) cout << 'L';
    cout << 'U' << endl;
}




Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemE solver = new ProblemE();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemE {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[1 << n];
            for (int i = 0; i < a.length; i++) {
                a[i] = in.nextInt();
            }

            int[] max1 = new int[1 << n];
            int[] max2 = new int[1 << n];
            Arrays.fill(max1, -1);
            Arrays.fill(max2, -1);
            for (int mask = 0; mask < 1 << n; mask++) {
                update(mask, mask, a, max1, max2);
                for (int bit = 0; bit < n; bit++) {
                    if ((mask & (1 << bit)) == 0) {
                        continue;
                    }
                    int nmask = mask ^ (1 << bit);
                    update(max1[nmask], mask, a, max1, max2);
                    update(max2[nmask], mask, a, max1, max2);
                }
            }

            long ans = 0;
            for (int k = 1; k < 1 << n; k++) {
                ans = Math.max(ans, a[max1[k]] + a[max2[k]]);
                out.println(ans);
            }
        }

        private void update(int i, int mask, int[] a, int[] max1, int[] max2) {
            if (i < 0) {
                return;
            }
            if (i == max1[mask] || i == max2[mask]) {
                return;
            }
            if (max1[mask] < 0 || a[max1[mask]] <= a[i]) {
                max2[mask] = max1[mask];
                max1[mask] = i;
            } else if (max2[mask] < 0 || a[max2[mask]] <= a[i]) {
                max2[mask] = i;
            }
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main()
{
    int a, b, c, k;
    int sum = 0;
    cin >> a >> b >> c >> k;
    if (k < a) rep(i, k) sum++;
    else if (k < a+b) rep(i, a) sum = a;
    else {
        rep(i, a) sum = a;
        rep(i, k-a-b) sum--;
    }
    
    cout << sum << endl;
    
    return 0;
}

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

int main(){
    string s, a, b;
    cin >> s;
    while(true){
        s.pop_back();
        a = s;
        b = s;
        a = a.substr(0, s.length()/2);
        b = b.substr(s.length()/2, s.length() - (s.length()/2) );
        if(a == b){
            cout << s.length() << endl;
            break;
        }
    }
}

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


int main() {
	
	int n;
	cin>>n;
	string a[n];
	map<string,int> m;
	for(int i=0;i<n;i++){
	    cin>>a[i];
	    m[a[i]]++;
	}
	vector<int> v;
	for(int i=0;i<n;i++){
	    v.push_back(m[a[i]]);
	}
	sort(v.begin(),v.end());
	 int z=v[v.size()-1];
	 for(auto it=m.begin();it!=m.end();it++){
	     if(it->second==z){
	         cout<<it->first<<endl;
	     }
	 }
	
	
	
	
	return 0;
}

Measured memory_bytes: 27640
#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll; 
const ll MOD = 1000000007;

int main()  
{ 
    FAST_INP;
    int n;
    cin >> n;
    string s;
    cin >> s;
	int r=0, w=0, swap=0;
	for (int i =0; i < n;++i) {
		if (s[i]=='W') ++w;
		else ++r;
	}
	int ans = min(r, w);
	for (int i=0;i<r;++i) {
		if (s[i]=='W') ++swap;
	}
	ans=min(ans, swap);
	cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 3724
line = input()
line = line.rstrip().split(' ')

x = int(line[0])
n = int(line[1])

line = input()
line = line.rstrip().split(' ')

p = []

for i in range(n):
    p.append(int(line[i]))
p.sort()

if  n == 0:
    print(x)
else:
    min = p[0] - 1
    max = p[-1] + 1
    answer = 1000
    for i in range(min, max + 1):
        if i in p:
            continue
        if abs(x - i) < abs(x - answer):
            answer = i

    print(answer)


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N;
  string s;
  cin >> N >> s;
  for (char c : s) {
    c = ((c - 'A' + N) % 26) + 'A';
    cout << c;
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

char s[4], ju[6];

int judge()
{
    if (ju[0]&1 && ju[2]&1) return 0;
    if (ju[0]&2 && ju[2]&8) return 1;
    if (ju[0]&8 && ju[2]&2) return 1;
    if (ju[4]&1 && ju[5]&4) return 1;
    if (ju[4]&4 && ju[5]&1) return 1;
    if (ju[4]&2 && ju[5]&2) return 2;
    if (ju[4]&8 && ju[5]&8) return 2;
    if (ju[0]&4 && ju[2]&4) return 2;
    if (ju[1]&2 && ju[3]&8) return 2;
    if (ju[1]&8 && ju[3]&2) return 2;
    return 3;
}

int main()
{
    for(;;)
    {
        memset(ju, 0, sizeof(ju));
        for (int i = 0; i < 6; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                scanf("%s", s);
                if (s[0] == '#') return 0;
                for (int k = 0; k < 3; k++)
                {
                    if (s[k] == '*')
                    {
                        if (j == 0) ju[i] |= 4;
                        if (j == 2) ju[i] |= 1;
                        if (k == 0) ju[i] |= 8;
                        if (k == 2) ju[i] |= 2;
                    }
                }
            }
        }
        printf("%d\n", judge());
    }
    return 0;
}

Measured memory_bytes: 1132
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int a[10][10];
	int h,w;
	cin>>h>>w;
	for(int i=0;i<10;i++)
		for(int j=0;j<10;j++)
			cin>>a[i][j];
	for(int k=0;k<10;k++)
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
	int s=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			int x;
			cin>>x;
			if(x==-1)
				continue;
			s+=a[x][1];
		}
	}
	cout<<s;
	return 0;
}

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

#define int long long int
#define vi vector<int>
#define pii pair<int,int>
#define pq priority_queue<int>
#define pb push_back
#define INF 1000000000000000000
#define modu 1000000007
#define out(a) cout<<a
#define out2(a,b) cout<<a<<" "<<b
#define out3(a,b,c) cout<<a<<" "<<b<<" "<<c
#define in(a) cin>>a
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define spc <<" "
#define nl <<"\n"
#define khubTesh(ti) cout<<"Case "<<ti<<": "

void testCase(int ti,int ans){
    khubTesh(ti);
    out(ans) nl;
}

void debug(string pr,vector<int> var)
{
    cout<<pr;
    for(int i=0;i<var.size();i++) cout<<" "<<var[i];
    cout<<endl;
}

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
}
const int MaxSize=100010;
int n;
int a[MaxSize],b[MaxSize],c[MaxSize];
int ans[MaxSize][4];

int dp(int at,int na){
    //cout<<at<<" "<<na<<endl;
    if(at>n) return 0;
   // cout<<"passed"<<endl;
    if(ans[at][na]!=-1) return ans[at][na];
    int a1=0,b1=0,c1=0;
    if(na!=1) a1=dp(at+1,1) + a[at];
    if(na!=2) b1=dp(at+1,2) + b[at];
    if(na!=3) c1=dp(at+1,3) + c[at];
   // debug("at,na,a1,b1,c1,a[at],b[at],c[at],ans[at][na]",{at,na,a1,b1,c1,a[at],b[at],c[at],ans[at][na]});
    return ans[at][na]=max(max(a1,b1),c1);
}

int32_t main(){
    faster();
    #ifdef OFFLINE
      freopen("in.txt", "r", stdin);
      freopen("out.txt", "w", stdout);
    #endif
    //Now I will start writing codes and start preparation to get errors
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=3;j++) ans[i][j]=-1;
    }
    cout<<dp(1,0);
    return 0;
}


Measured memory_bytes: 10368
#include <stdio.h>
#include <string.h>
#define BMAX 16
#define MOD 1000000007

int main(void)
{
  int i, j, k, n, x, y, z, xyz, mask, idx = 0, res = 1, dp[2][1<<BMAX] = {0};
  scanf("%d %d %d %d", &n, &x, &y, &z);
  xyz = (1 << (x + y + z - 1)) | (1 << (y + z - 1)) | (1 << (z - 1));
  mask = ((1 << (x + y + z)) - 1) >> 1;
  dp[idx][0] = 1;
  for (i = 0; i < n; i++) {
    memset(dp[idx^1], 0, sizeof(dp[idx^1]));
    for (j = 0; j <= mask; j++) {
      if (dp[idx][j] > 0) {
        for (k = 0; k < 10; k++) {
          int used = (j << (k + 1)) | (1 << k);
          if ((used & xyz) != xyz) dp[idx^1][used&mask] = (dp[idx^1][used&mask] + dp[idx][j]) % MOD;
        }
      }
    }
    idx ^= 1;
  }
  for (i = 0; i < n; i++) res = (res * 10LL) % MOD;
  for (i = 0; i <= mask; i++) res = (res - dp[idx][i] + MOD) % MOD;
  printf("%d\n", res);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,m;
int main()
{
    int a,b;
    cin>>n>>a>>b;
    int t=b-a-1;
    if(t%2==0)
        printf("Borys\n");
    else printf("Alice\n");
    return 0;
}


Measured memory_bytes: 256
from math import ceil
N=int(input())
A=list(map(int, input().split()))

pre=(A[0]==1)
count=0
ans=0
if pre:
  count+=1
for i in range(1,N):
  if pre:
    if A[i]!=i+1:
      ans+=ceil(count/2)
      count=0
      pre=False
    else:
      count+=1
  else:
    if A[i]==i+1:
      count+=1
      pre=True
if pre:
  ans+=ceil(count/2)
print(ans)

Measured memory_bytes: 13812
#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()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	sort(ALL(v));
	int a = v[n - 1];
	int b = 0;
	int mn = INF;
	rep(i,n-1) {
		if (mn > abs(v[i] - a / 2.0)) {
			mn = abs(v[i] - a / 2.0);
			b = v[i];
		}
	}
	cout << a << " " << b << endl;
}

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

Measured memory_bytes: 3780
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.first+a.second > b.first+b.second; }

signed main() {
  SS(int,n,k);
  SV(int,a,n);
  sort(all(a));
  ll sum=0;
  rep(i,k){
      sum+=a[i];
  }
  p(sum);
}

Measured memory_bytes: 3648
// ---------- begin scannner ----------
#[allow(dead_code)]
mod scanner {
    use std::str::FromStr;
    use std::str::SplitWhitespace;
    use std::io::Read;
    use std;
    pub struct Scanner<'a> {
        it: SplitWhitespace<'a>
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a String) -> Scanner<'a> {
            Scanner {
                it: s.split_whitespace()
            }
        }
        pub fn next<T: FromStr>(&mut self) -> T {
            match self.it.next().unwrap().parse::<T>() {
                Ok(v) => v,
                _ => panic!("Scanner error")
            }
        }
        pub fn next_chars(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}
// ---------- end scannner ----------

use std::io::Write;

fn main() {
    let sc = scanner::read_string();
    let mut sc = scanner::Scanner::new(&sc);
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    run(&mut sc, &mut out);
}

fn run(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let n: usize = sc.next();
    let k: usize = sc.next();
    let mut elem = vec![false; n];
    for _ in 0..k {
        let d: usize = sc.next();
        for _ in 0..d {
            let a: usize = sc.next();
            elem[a - 1] = true;
        }
    }
    let mut ans = 0;
    for e in elem {
        if !e {
            ans += 1;
        }
    }
    writeln!(out, "{}", ans).ok();
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef long long ll;
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX / 100;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
const double PI = 3.14159265358979323846;

typedef pair<ll, ll> P;

struct Witness {
    int to;
    bool is_honest;
};

int check(int i, int n, vector<vector<Witness>> &witness) {
    for (int j = 0; j < n; j++) {
        if (((i >> j) & 1) == 0) {
            continue;
        }
        for (Witness &w : witness[j]) {
            bool h = (i >> w.to) & 1;
            if (h != w.is_honest) return -1;
        }
    }
    return __builtin_popcount(i);
}

int main() {

    int n;
    cin >> n;

    vector<vector<Witness>> witness(n);

    rep(i, n) {
        int a;
        cin >> a;
        rep(j, a) {
            int x, y;
            cin >> x >> y;
            x--;
            Witness w{x, y == 1};
            witness[i].push_back(w);
        }
    }

    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        int now = check(i, n, witness);
        cmax(ans, now);
    }
    cout << ans << endl;

}

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()
using ll = long long;
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; }
//vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値));
//vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2));  // 初期値を省略

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n; cin >> n;
	vector<string> s(n); rep(i,n) cin >> s[i];
	//map<string,int> mp;
	
	sort(all(s));
	//cout << endl;
	
	int c=1;
	int mx=0;
	
	
	rep(i,n-1){
		
		if(s[i]==s[i+1]){
			c++;
			if(i==n-2){
				chmax(mx,c);
				c=1;
				break;
			}
			continue;
		}
		
		else{
			chmax(mx,c);
			c=1;
		}
	}
	
	c=1;
	
	//cout << mx << endl;
	
	rep(i,n-1){
		
		if(s[i]==s[i+1]){
			c++;
			if(i==n-2){
				if(c==mx)cout << s[i] << endl;
			}
			continue;
		}
		
		else{
			if(c==mx) cout << s[i] << endl;
			c=1;
		}
	}
	if(mx==1) cout << s[n-1] << endl;
	
	
	
	return 0;
}



Measured memory_bytes: 12928
def main():
	N = int(input())
	T = [0]*N
	A = [0]*N
	for i in range(N):
		T[i], A[i] = map(int, input().split())

	total_t = T[0]
	total_a = A[0]
	for i in range(N):
		if total_t == T[i] and total_a == A[i]:
			continue
		current_t = total_t//T[i] if total_t%T[i]==0 else (total_t//T[i])+1
		current_a = total_a//A[i] if total_a%A[i]==0 else (total_a//A[i])+1
		n = max(current_t, current_a)
		total_t = n*T[i]
		total_a = n*A[i]

	print(total_a+total_t)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define MAXN 200000
#define LL long long
#define DB double
#define FR first
#define SE second
int a[MAXN+5];
LL ans;
LL L1[MAXN],L2[MAXN+5],R1[MAXN+5],R2[MAXN+5];
LL lsum[MAXN+5],rsum[MAXN+5];
int n;
int get_num(int p)
{
	if(p==0)return 0;
	if(p%2==1)return 1;
	return 2;
}
int main()
{
	ans=1000000000;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
    lsum[i]=lsum[i-1]+a[i];
    for(int i=n-1;i>=0;i--)
    rsum[i]=rsum[i+1]+a[i+1];
    for(int i=1;i<=n;i++)a[i]=get_num(a[i]);
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0)L1[i]=min(L1[i-1]+2,lsum[i]);
        else if(a[i]==1)L1[i]=min(L1[i-1]+1,lsum[i]);
        else L1[i]=min(L1[i-1],lsum[i]);
        if(a[i]==0)L2[i]=min(L1[i],min(L2[i-1]+1,lsum[i]));
        else if(a[i]==1)L2[i]=min(L1[i],min(L2[i-1],lsum[i]));
        else L2[i]=min(L1[i],min(L2[i-1]+1,lsum[i]));
    }
    for(int i=n-1;i>=0;i--)
    {
        if(a[i+1]==0)R1[i]=min(R1[i+1]+2,rsum[i]);
        else if(a[i+1]==1)R1[i]=min(R1[i+1]+1,rsum[i]);
        else R1[i]=min(R1[i+1],rsum[i]);
        if(a[i+1]==0)R2[i]=min(R1[i],min(R2[i+1]+1,rsum[i]));
        else if(a[i+1]==1)R2[i]=min(R1[i],min(R2[i+1],rsum[i]));
        else R2[i]=min(R1[i],min(R2[i+1]+1,rsum[i]));
    }
    for(int i=0;i<=n;i++)
    {
    	//printf("%d %lld %lld\n",i,L1[i]+R2[i],L2[i]+R1[i]);
        ans=min(ans,min(L1[i]+R2[i],L2[i]+R1[i]));
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 10368
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
ans, m = 0, 1e9
for i in range(N):
  if abs((T-H[i]*0.006) - A) < m:
    ans = i+1
    m = abs((T-H[i]*0.006) - A)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i<n;i++)
using ll = long long;
using P = pair<ll,ll>;
 
int main(){
  ll n;cin>>n;
  vector<ll> v(n);
  ll sum = 0;
  rep(i,n) {
    cin>>v.at(i);
    sum+=v.at(i);
  }
  ll ave = sum/n;
  ll ans = 0;
  rep(i,n){
    ans += (ave - v.at(i)) * (ave - v.at(i));
  }
  ave++;
  ll ans2 = 0;
  rep(i,n){
    ans2 += (ave - v.at(i)) * (ave - v.at(i));
  }
  ans = min(ans,ans2);
  cout << ans << endl;
}

Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}
int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a==0)	cout<<1;
	else if(b==0)	cout<<2;
	else if(c==0)	cout<<3;
	else if(d==0)
		cout<<4;
	else
		cout<<5;
	
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}




Measured memory_bytes: 3652
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner input=new Scanner(System.in);
		int a=input.nextInt();
		int b=input.nextInt();
		System.out.println(gcd(a,b));
	}
	
	public static int gcd(int a,int b){
		return b==0 ? a : gcd(b,a%b);
	}

}

Measured memory_bytes: 26204
#include <stdio.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const int INF = (1 << 30);

int H, W;
char s[101][101];
int cnt[101][101];
typedef struct{int x; int y;} P;
const int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};
P que[10101];

int solve() {
    int qf = 0, qb = 0;
    rep(i, H) rep(j, W) cnt[i][j] = INF; 
    que[qb].x = 0, que[qb++].y = 0;
    cnt[0][0] = 1;
    while(qb - qf > 0) {
        int cx = que[qf].x, cy = que[qf++].y;
        rep(i, 4) {
            int nx = cx + dx[i], ny = cy + dy[i];
            if(nx >= 0 && nx < H && ny >= 0 && ny < W) {
                if(s[nx][ny] != '#' && cnt[nx][ny] == INF) {
                    cnt[nx][ny] = cnt[cx][cy] + 1;
                    que[qb].x = nx, que[qb++].y = ny;
                }
            }
        }
    }
    if(cnt[H-1][W-1] == INF) return -1;
    int tmp = 0;
    rep(i, H) rep(j, W) if(s[i][j] == '.') tmp++;
    return (tmp - cnt[H-1][W-1]);
}

int main(){
    scanf("%d%d", &H, &W);
    rep(i, H) scanf("%s", s[i]);
    printf("%d\n", solve());
}

Measured memory_bytes: 1776
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(0, 0); }
	V<V<pin>> qab(2);
	int sz = ab.size();
	qab[0].reserve(sz);
	qab[1].reserve(sz);
	for (pin& x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2)); }
	}
	rep(i, 2) {
		int c = 0;
		for (pin& x : qab[1-i]) {
			int qc = (2 * x.first + x.second) % 3;
			c ^= (qc + 1);
		}
		if (!c) {
			pin ans = solve(qab[i], ex - 1);
			ans.first *= 2; ans.second *= 2; ans.second += i;
			return ans;
		}
	}
	pin ans = solve(qab[0], ex - 1);
	int val = ans.second-1;
	int c = 0;
	for (pin& x : qab[1]) {
		int w = val - x.second;
		if ((w & x.first) == w) { c ^= 1; }
	}
	ans.first *= 2; ans.first++; ans.second *= 2; ans.second -= c;
	return ans;
}
signed main() {
	cin.tie(0); ios::sync_with_stdio(false);
	long long inf = 2e17;
	int n; cin >> n;
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; cin >> a >> b;
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 70);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}


Measured memory_bytes: 7808
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

max_x = max(x)
min_y = min(y)

if X < Y and max_x < min_y:
    X += 1
    max_x += 1
    if (X <= max_x and max_x <= Y) or (X <= min_y and min_y <= Y):
        print('No War')
    else:
        print('War')
else:
    print('War')

Measured memory_bytes: 3064
N=int(input())
B=list(map(int, input().split()))
S=0
for x in reversed(range(0,N)):
    if x==N-1:
        S=S+B[N-2]
        AA=B[N-2]
    if x!=N-1 and x!=0:
        if B[x]>=B[x-1]:
            S=S+B[x-1]
            AA=B[x-1]
        if B[x]<B[x-1]:
            S=S+B[x]
            AA=B[x-1]
    if x==0:
        if AA>=B[0]:
            S=S+B[0]
        if AA<B[0]:
            S=S+AA
print(S)



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

typedef long long ll;

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

    int n,r;
    cin >> n >> r;
    int ans;
    if(n>=10) ans = r;
    else ans = r+100*(10-n);
    cout << ans << endl;
    return 0;
}

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

#define SWAP(a,b) ((a != b)? (a += b,b = a - b,a -= b) : 0 ) //数値のみ
#define SWAPs(type,a,b) { type temp = a; a = b; b = temp; } //型指定する ポインタ, 構造体等
#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
  int a, b, n, ans = 0;
  //string s, t;
  cin >> a;
  //vector<ll> c(n), v(n);
  //rep(i, n) cin >> c.at(i);
  cout << ((a+999)/1000)*1000 - a << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long

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

    int n, k;
    cin >> n >> k;

    priority_queue<int> que;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        que.push(a);
    }

    while (que.size() && k) {
        que.pop();
        k--;
    }

    int ans = 0;
    while (que.size()) {
        ans += que.top();
        que.pop();
    }

    cout << ans << endl;
}


Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CINS(int, a, N)
    ll sum = 0;

    for (int i = 0; i < N; i++) {
        sum += a[i];
    }

    ll sum1 = a[0], sum2 = sum - a[0];
    ll MIN = fabs(sum1-sum2);

    for (int i = 1; i < N-1; i++) {
        sum1 += a[i];
        sum2 -= a[i];
        MIN = min(MIN, (ll)fabs(sum1 - sum2));
    }

    cout << MIN << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int a[2][100]={0};
int flag[2][100];
int su;

int dfs(int building,int level,int count){
	int ret_a=200,ret_b=200,ret_c=200,ret_d=200;
	if(level==su-1 && a[building][level]!=2) return 0;
	if(level>=su) return 200;
	if(flag[building][level]<=count && flag[building][level]!=-1) return 200;
	else{
		flag[building][level]=count;
		if(a[building][level]==2) ret_d=dfs(building,level-1,count);
		else if(a[building][level+1]==1 && a[building][level]==1) ret_c=dfs(building,level+1,count);
		else{
			ret_b=dfs((building+1)%2,level+2,count+1)+1;
			ret_a=dfs((building+1)%2,level+1,count+1)+1;
		}
		if(ret_a<ret_b) ret_b=ret_a;
		if(ret_c<ret_d) ret_d=ret_c;
		if(ret_b<ret_d) ret_d=ret_b;
		return ret_d;
	}

}

int main(){
	int i,dfs_a,dfs_b;
	while(1){
		for(i=0;i<100;i++){
			flag[0][i]=-1;
			flag[1][i]=-1;
		}
		scanf("%d",&su);
		if(su==0) break;
		for(i=0;i<su;i++) scanf("%d",&a[0][i]);
		for(i=0;i<su;i++) scanf("%d",&a[1][i]);
		dfs_a=dfs(0,0,0);
		dfs_b=dfs(1,0,0);
		if(dfs_a<dfs_b) dfs_b=dfs_a;
		if(dfs_b>=200) printf("NA\n");
		else printf("%d\n",dfs_b);
	}
	return 0;
}

Measured memory_bytes: 612
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
cnt_0 = 0
cnt_2 = 0
for i in range(n):
    if a[i] % 4 == 0:
        cnt_2 += 1
    elif a[i] % 2 == 1:
        cnt_0 += 1
if (cnt_2 >= cnt_0 - 1 and cnt_2 + cnt_0 == n) or cnt_2 >= cnt_0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14252
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)

ll x[500000];
ll s = 250000;
ll e = 250001;
int main() {
	ll n; cin >> n;
	repe(i, 1, n) {
		ll a; cin >> a;
		if (i & 1) {
			x[s] = a;
			s--;
		}
		else {
			x[e] = a;
			e++;
		}
	}

	if (n & 1) {
		rep(i, s + 1, e) {
			cout << x[i];
			if (i != e - 1) {
				cout << " ";
			}
		}
	}
	else {
		rep_r(i, s + 1, e) {
			cout << x[i];
			if (i != s) {
				cout << " ";
			}
		}
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define IL inline
#define _ 524288
#define ll long long
using namespace std;

IL int gi(){
	int data=0,fu=1; char ch=0; while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')fu=-1,ch=getchar();
	while('0'<=ch&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar(); return data*fu;
}

int Ans,n,A[_],B[_];
struct Item{int a,b;}E[_],F[_];

IL bool cmp1(Item x1,Item x2){
	return x1.a^x2.a?x1.a<x2.a:x1.b<x2.b;
}
IL bool cmp2(Item x1,Item x2){
	return x1.a^x2.a?x1.a<x2.a:x1.b>x2.b;
}

IL int Calc(int p,int q){
	int ret=0;
	for(int i=1;i<=n;++i)F[i]=E[i];
	sort(F+1,F+n+1,cmp1);
	for(int i=1;i<=n;++i){
		bool flag=false;
		for(int j=1;j<i;++j)if(F[i].a-p==F[j].a&&F[i].b-q==F[j].b)flag=true;
		if(!flag)++ret;
	}
	int ret2=0;
	sort(F+1,F+n+1,cmp2);
	for(int i=1;i<=n;++i){
		bool flag=false;
		for(int j=1;j<i;++j)if(F[i].a-p==F[j].a&&F[i].b-q==F[j].b)flag=true;
		if(!flag)++ret2;
	}
	return min(ret,ret2);
}

int main(){
	n=gi();
	for(int i=1;i<=n;++i)E[i].a=gi(),E[i].b=gi();
	Ans=n;
	for(int i=1,p,q;i<=n;++i)
		for(int j=1;j<i;++j){
			p=E[i].a-E[j].a; q=E[i].b-E[j].b;
			if(p<0)p=-p,q=-q;
			Ans=min(Ans,Calc(p,q));
			Ans=min(Ans,Calc(p,-q));
		}
	cout<<Ans<<endl;
	return 0;
}


Measured memory_bytes: 2304
def devisor(n):
    cnt=0
    d=[]
    for i in range(1,round(n**0.5)+1):
        if n%i==0:
            cnt+=1
            d.append(i)
            if n//i!=i:
                cnt+=1
                d.append(n//i)
    return cnt,d

N=int(input())
ans=devisor(N-1)[0]-1

D=devisor(N)[1]

for d in D:
    if d==1:
        continue
    n=N
    while n%d==0:
        n=n//d
    if n%d==1:
        ans+=1

print(ans)

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

int main(){
	int h,w,i;
	
	refrain:
	cin>>h;
	cin>>w;
	
	if(h==0&&w==0) return 0;
	
	for(i=0;i<w;i++){
		cout<<"#";
	}
	cout<<endl;
	for(i=2;i<h;i++){
		cout<<"#";
		for(int j=2;j<w;j++){
			cout<<".";
		}
		cout<<"#"<<endl;
	}
	for(i=0;i<w;i++){
		cout<<"#";
	}
	cout<<endl;
	cout<<endl;
	
	goto refrain;
}

Measured memory_bytes: 1152
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  int N, K, ans = 0, maxi = 0, count ;
  string S ;
  cin >> S ;
  for(int i=0;i<3;i++){
    if(S[i] == 'R'){
      maxi++ ;
      ans = max(ans, maxi) ;
    }
    else{
      maxi = 0 ;
    }
  }
  cout << ans << endl ;
  return 0 ;
}  

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    int y = x / 500 * 1000 + x % 500 / 5 * 5;
    cout << y << endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
pn = list(map(int, input().split()))
cn = list(map(int, input().split()))

ans = -float('inf')

for i in range(n): #start
    start = i
    now = start
    total = 0
    ls = [0]

    for j in range(1, k+1):
        now = pn[now]-1
        total += cn[now]
        ans = max(ans, total)
        ls.append(total)
        if now == start:
            rp = j
            break
    else:
        continue

    if total <= 0:
        continue
    else:
        if k % rp == 0:
            s = k % rp
            ans2 = total * (k // rp-1) + max(ls)
            ans = max(ans, ans2)
        else:
            s = k % rp
            ans2 = total * (k//rp) + max(ls[:s+1])
            ans = max(ans, ans2)
print(ans)

Measured memory_bytes: 80104
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

class CMakeARectangle {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll n;
        in>>n;
        map<ll,ll> a;
        rep(i,n){
            ll tmp;
            in>>tmp;
            a[tmp]++;
        }
        ll ans=0;
        ll ma=0;
        for(auto i: a){
            if(i.second >= 2) {

                ans=max(ans,ma*i.first);
                ma=max(ma,i.first);
            }
            if(i.second >= 4) ans=max(ans,i.first*i.first);


        }
        out<<ans<<endl;


	}
};


int main() {
	CMakeARectangle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 6528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	static int[] ary;
	static int N;
	static int sum=1;
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		N=sc.nextInt();
		ary=new int[N];
		for(int i=0; i<N; i++) {
			ary[i]=sc.nextInt();
			sum*=3;
		}
		int jyogai=1;
		for(int i=0; i<N; i++) {
			if(ary[i]%2==0) {
				jyogai*=2;
			}
			else {
				jyogai*=1;
			}
		}
		pl(sum-jyogai);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static final int lowerBound(final int[] arr, final int value) {
		int low = 0;
		int high = arr.length;
		int mid;
		while (low < high) {
			mid = ((high - low) >>> 1) + low;    //(low + high) / 2 (オーバーフロー対策)
			if (arr[mid] < value) {
				low = mid + 1;
			} else {
				high = mid;
			}
		}
		if(low<arr.length) {
			return low;
		}
		else {
			return -1;
		}
	}
}


Measured memory_bytes: 21204
#include <stdio.h>

int main(){
	int a,b;
	
	scanf("%d %d",&a,&b);
	for (int i =0; i<1010 ; i++){
		if((i*8)/100== a && (i*10)/100==b){
			printf("%d\n",i);
			return 0;
		}
	}
	printf("-1\n");

	
	return 0;
}

Measured memory_bytes: 1712
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, m;
    cin >> n >> m;
    if (n > m) cout << "safe";
    else cout << "unsafe";
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    vector<int> rank(2, 0);
    cin >> rank[0] >> rank[1];
    if (rank[0] == 1 && rank[1] == 1) {
        cout << 1000000 << endl;
    } else {
        int ans = 0;
        for(int i = 0; i < 2; i++) {
            if (rank[i] == 1)
                ans += 300000;
            else if (rank[i] == 2)
                ans += 200000;
            else if (rank[i] == 3)
                ans += 100000;
        }
        cout << ans << endl;
    }
    return 0;
}



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

int main() {
  int N; cin >> N;
  for(int i = 1; i <= 50000; i++) {
    if(int(i * 1.08) == N) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <iosfwd>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
// O(log N)　keyのある場所を返す。なかったら-1を返す
int search(int key, vector<int> a){
  int right = a.size() + 1;
  int left = 0 - 1;
  while(right >= left){
    int middle = left + (right - left) / 2;
    if(a[middle] == key) return middle; //keyが入ってる場所を返す
    else if(a[middle] > key) right = middle - 1;
    else if(a[middle] < key) left = middle + 1;
  }
  //なければ-1を返す
  return -1;
}
int sum(int a){
  if(a == 0) return 0;
  return sum(a - 1) + a;
}
int main(){
  string s;
  cin >> s;
  int len = s.length() - 1;
  vector<int> n(len + 1);
  rep(i, len + 1) n[i] = int(s[i] - '0');
  ll sum = 0;
  for(int i = 0; i < (1 << len); i++){
    bitset<10> a(i);
    ll current = n[0];
    rep(j, len){
      if(a.test(j)){
        sum += current;
        current = n[j + 1];
      }else{
        current *= 10;
        current += n[j + 1];
      }
    }
    sum += current;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
#define INF 1000000000
#define PI 3.14159265359

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

    int n,k;
    cin >> n >> k;
    vi cnt(n);
    for(int i=0;i<k;i++){

        int d=0;

        cin >> d;
        vi ls(d);
        for(int j=0;j<d;j++){
            cin >>ls.at(j);
        }

        for(int j=0;j<d;j++){
            cnt.at(ls.at(j)-1) +=1;
        }

    }
    int ans = 0;

    for(int i=0;i<n;i++){
        if (cnt.at(i)==0){
            ans += 1;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 3628