akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;
int main ()
{
    int a, b, k = 0, t = 0;
    cin >> a >> b;
    string s;
    cin >> s;
    if(s[a] == '-')
    {
        s.erase (a,1);
        for(int i = 0; i < a + b; i++)
            {
                if(s[i] == '0' + 0 || s[i] == '0' + 1 || s[i] == '0' + 2 ||
                   s[i] == '0' + 3 || s[i] == '0' + 4 || s[i] == '0' + 5 ||
                   s[i] == '0' + 6 || s[i] == '0' + 7 || s[i] == '0' + 8 || s[i] == '0' + 9)
                k++;
                else
                t++;
            }
            if(t == 0)
                cout << "Yes";
                else cout << "No";
    }
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    np.set_printoptions(threshold=20)
    N = int(input())
    a = list(map(int, input().rstrip().split()))
    print(sum(a) - N)


if __name__ == '__main__':
    main()


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

int main()
{
 int k,n;
  cin>>k>>n;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  int maxi=-1,prev=0;
  for(int i=0;i<n;i++)
  {
   maxi=max(maxi,abs(prev-a[i])); 
    prev=a[i];
  }
  maxi=max(maxi,k-a[n-1]+a[0]);
  cout<<k-maxi<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<map>
using namespace std;
bool table[500][500];
int main(){
	int ww;
	while(cin>>ww,ww){
		int nx=250,ny=250,n,d;
		map<int, pair<int,int> >dir;
	for(int i=0;i<500;i++)for(int j=0;j<500;j++)table[i][j]=0;
		pair<int,int>t(ny,nx);
		table[ny][nx]=1;
		dir[0]=t;
		for(int i=1;i<ww;i++){
			cin>>n>>d;
			ny=dir[n].first;
			nx=dir[n].second;
			if(d==0)nx--;
			else if(d==1)ny--;
			else if(d==2)nx++;
			else if(d==3)ny++;
			table[ny][nx]=1;
			pair<int,int>tmp(ny,nx);
			dir[i]=tmp;
			table[ny][nx]=1;
		}
	int tx=-1,ty=-1,ux=100000,uy=100000;
	for(int i=0;i<500;i++){
		for(int j=0;j<500;j++){
			if(table[i][j]==1){
				tx=max(tx,j);
				ty=max(ty,i);
				ux=min(ux,j);
				uy=min(uy,i);
			}
		}
	}
	
	cout<<tx-ux+1<<" "<<ty-uy+1<<endl;
}
	return 0;
}

Measured memory_bytes: 1452
x = int(input())
li = []
for i in range(x):
    l = list(map(int, input().split()))
    li.append(l)
dp = [[0]*3 for _ in range(x+1)]
for i in range(x):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1][j] = max(dp[i][k]+li[i][j], dp[i+1][j])
print(max(max(dp[x][0], dp[x][1]), max(dp[x][1], dp[x][2])))

Measured memory_bytes: 47344
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  
  vector<pair<int, int> > itv(M);
  for(int i = 0; i < M; i++)cin >> itv[i].second >> itv[i].first;
  
  sort(itv.begin(), itv.end());
  
  int ans = 0, t = 0;
  for(int i = 0; i < M; i++)
  {
    if(t <= itv[i].second)
	{
      ans++;
      t = itv[i].first;
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

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

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

    if (a >= 13)
        cout << b;
    else if (a >= 6 && a <= 12)
        cout << b / 2;
    else
        cout << 0;
}


Measured memory_bytes: 256
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ abcd ] = readMany(1)
    const nums = abcd.split('').map(it => parseInt(it))

    const ops = [ false, false, false ] // false: -, true: +
    for (let i = 0; i < 2 ** ops.length; i += 1) {
        for (let j = 0; j < ops.length; j += 1) {
            ops[j] = (1 << (ops.length - 1 - j)) & i
        }

        let calculated = nums[0]
        for (let j = 0; j < ops.length; j += 1) {
            if (ops[j]) {
                calculated += nums[j + 1]
            } else {
                calculated -= nums[j + 1]
            }
        }

        if (calculated == 7) {
            let answer = nums[0] + ''
            for (let j = 0; j < ops.length; j += 1) {
                if (ops[j]) {
                    answer += '+'
                } else {
                    answer += '-'
                }
                answer += nums[j + 1]
            }
            answer += '=7'
            return console.log(answer)
        }
    }
})()


Measured memory_bytes: 7372
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while(getline(ss,x,c)) v.emplace_back(x); return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;
int d[112][112];
typedef pair<pii,int> piii;
int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,m;
  cin>>n>>m;
  vector<piii> es(m);
  for(piii &e:es) cin>>e.X.X>>e.X.Y>>e.Y, --e.X.X, --e.X.Y;
  fill(d[0],d[112],MOD);
  rep(i,n) d[i][i]=0;
  for(piii e:es){
    MN(d[e.X.Y][e.X.X],e.Y);
    MN(d[e.X.X][e.X.Y],e.Y);
  }
  rep(k,n)rep(i,n)rep(j,n) MN(d[i][j],d[i][k]+d[k][j]);
  int re=0;
  for(piii e:es){
    int f=1;
    rep(i,n)rep(j,n) if(d[i][e.X.X]+e.Y+d[e.X.Y][j]==d[i][j] ||
			d[i][e.X.Y]+e.Y+d[e.X.X][j]==d[i][j]){
      //if(f) out(i,j,e,1);
      f=0;
    }
    if(f) ++re;
  }
  cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))

A.sort()
flag = True

if N%2==1:
    b=[0]
    for i in range(1, N):
        c=i
        if i%2==1:
            c += 1
        b.append(c)
    if A != b:
        print(0)
    else:
        if N==1:
            print(1)
        else:
            ans = 2
            for i in range((N-1)//2-1):
                ans *= 2
                ans = ans % (10**9+7)
            print(ans)
    
else:
    d=[]
    for i in range(N):
        e=i
        if i%2==0:
            e += 1
        d.append(e)
    
    if A != d:
        print(0)
    else:
        ans = 2
        for i in range(N//2-1):
            ans *= 2
            ans = ans % (10**9+7)
        print(ans)

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

int main(){
  //int a,b;
  string a;//, b, c, d;
  cin >> a;//>> b;// >> c >> d;
  //cin >> s;
  int ans = 0;
  if(a.at(0)=='-')ans--;
  else ans++;
    if(a.at(1)=='-')ans--;
  else ans++;
    if(a.at(2)=='-')ans--;
  else ans++;
    if(a.at(3)=='-')ans--;
  else ans++;
  //else if(abs(a-b)<=d&&abs(b-c)<=d)cout << "Yes" << endl;
  //else cout << "NO" << endl;
cout << ans << endl;
  return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+23;
int p[N];

void solve() {
  int n, k; scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", p+i);
  }
  double sum = 0;
  for (int i = 0; i < k; ++i) {
    sum += (p[i]+1)/2.;
  }
  double ans = sum;
  for (int i = k; i < n; ++i) {
    sum -= (p[i-k]+1)/2.;
    sum += (p[i]+1)/2.;
    ans = max(ans, sum);
  }
  printf("%.6lf", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 4588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	static int x, y;
	
	static void input() throws IOException {
		int[] num = readMultiInt();
		x = num[0];
		y = num[1];
	}
	
	static void process() {
	}
	
	static int gcd(int num1, int num2) {
		if(num2 == 0) {
			return num1;
		} else {
			return gcd(num2, num1 % num2);
		}
	}
	
	static void output() {
		System.out.println(gcd(x, y));
	}
	
	//??\?????±?????¨???
	static BufferedReader in;
	
	static void initBufferedReader() {
		in = new BufferedReader(new InputStreamReader(System.in));
	}
	
	static String readString() throws IOException {
		return in.readLine();
	}
	
	static int readInt() throws NumberFormatException, IOException {
		return Integer.valueOf(readString());
	}
	
	static int[] readMultiInt() throws IOException {
		String input = readString();
		String[] values = input.split(" ");
		int[] result = new int[values.length];
		for (int i = 0; i < values.length; i++) {
			result[i] = Integer.valueOf(values[i]);
		}
		return result;
	}
	
	static String arrayToString(int[] data) {
		String result = "";
		for (int i = 0; i < data.length; i++) {
			if (i >= data.length - 1) {
				result += String.valueOf(data[i]);
			} else {
				result += String.valueOf(data[i]) + " ";
			}
		}
		return result;
	}
	
	static long factional(int n) {
		int result = 1;
		for (int i = 1; i <= n; i++) {
			result *= i;
		}
		return result;
	}
	
	public static void main(String[] args) throws IOException {
		initBufferedReader();
		input();
		process();
		output();
	}
	
}

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

int main()
{
  priority_queue<int> pqi;
  string str;
  while (cin >> str, str != "end"){
    if (str == "insert") {
      int n;
      cin >> n;
      pqi.push(n);
    }
    else if (str == "extract") {
      cout << pqi.top() << "\n";
      pqi.pop();
    }
  }
}

Measured memory_bytes: 7052
N,K = map(int,input().split())
Data = list(map(int,input().split()))
Dic = {}
for d in Data:
    if d in Dic.keys():
        Dic[d]+=1
    else:
        Dic[d]= 1
kind = len(Dic)

sortedDic = sorted(Dic.items(),key=lambda x:x[1])

ans = 0
cnt = kind-K
for k,v in sortedDic:
    if cnt <= 0:
        break
    else:
        cnt -= 1
        ans += v
print(ans)

Measured memory_bytes: 39064
#include<bits/stdc++.h>
#include<vector>
#define inf 10000000000000
#define ll unsigned long long
#define boostUP ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fsr(i,n) for(ll i=0;i<n;i++)
#define fcr(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define sz(arr) sizeof(arr)/sizeof(arr[0])
#define mod 1000000007;

using namespace std;
// lower_bound
// it returns pos of the elmnt which is not less then the query elmnt

int main() {
    int n; cin >> n;
    vector<int>v(n,0),p(n,0),q(n,0),tmp(n,0);
    for(int i = 0; i < n; i++){
        v[i] = i+1;
        tmp[i] = i+1;
        cin >> p[i];
    }
    for(int i = 0; i < n; i ++)
        cin >> q[i];
    int count = 1, a=1,b=1, flag = 0;
    while(next_permutation(v.begin(),v.end())){
        count++;
        if(v==p){
            a = count;break;
        }
    }
    count = 1;
    while(next_permutation(tmp.begin(),tmp.end())){
        count++;
        if(tmp==q){
            b = count;break;
        }
    }
    cout << abs(a-b) << endl;
}





Measured memory_bytes: 3632
// 個数制限なしナップサック問題
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>
#include <set>
using namespace std;

static const int MAX_N = 110;
static const int MAX_W = 10010;

int dp[MAX_N][MAX_W];

int main() {

    int N, W;
    cin >> N >> W;
    
    int v[N], w[N];
    for(int i = 0; i < N; i++) {
        cin >> v[i] >> w[i];
    }

    for (int i = 0; i < N; i++) {
        for(int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i+1][j] = dp[i][j];
            } else {
                dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]] + v[i]);
            }
        }
    }

    cout << dp[N][W] << endl;
    
    

    return 0;
}


Measured memory_bytes: 7052
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  while(1){
    ll n;
    cin>>n;
    if(n==0) break;
    vector<ll> v(n);
    rep(i,n) v[i]=i+1;
    ll ans=0;
    ll sum=0;
    ll right=0;
    rep(left,n){
      while(right<n && sum+v[right]<=n){
        sum+=v[right];
        right++;
      }
     
      if(sum==n && right-left>=2) ans++;
      if(left==right) right++;
      else sum-=v[left];
    }
    cout<<ans<<endl;
  }
  
}


Measured memory_bytes: 3172
#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++)

int main(){
    ll N;
    cin >> N;
    vector<ll> H(N);
    vector<bool> v(N, false);
    rep(i, 0, N) cin >> H[i];
    rep(i, 0, N-1){
        if(H[i] > H[i+1]){
            H[i]--;
            v[i] = true;
        }
    }
    for(ll i = N-1; i > 0; i--){
        if(H[i] < H[i-1]){
            if(v[i-1]){
                cout << "No" << endl;
                return 0;
            }else{
                H[i-1]--;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

 
int main(){
  int a,b,c,x,y,z=0;
  cin >> a >> b >> c >> x >> y;
  ll ans=a*x+b*y;
  int piz=max(x,y);
  while(x>0||y>0){
    if(x>0)x-=1;
    if(y>0)y-=1;
    z+=2;
    ll cur=a*x+b*y+c*z;
    ans = min(ans,cur);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    h,w = map(int,input().split())
    n = int(input())
    a = list(map(int,input().split()))
    c = [[0 for i in range(w)] for i in range(h)]
    p = [0,0]
    up = 1
    for i in range(n):
        cnt = 0
        while cnt<a[i]:
            c[p[0]][p[1]] = i+1
            cnt += 1
            if up==1 and p[1] < w-1:
                p[1] += 1
            elif up == 1 and p[1] == w-1:
                p[1] = w-1
                p[0] += 1
                up = 0
            elif up == 0 and p[1] > 0:
                p[1] -= 1
            elif up == 0 and p[1] == 0:
                p[1] = 0
                p[0] += 1
                up = 1
    for i in range(h):
        print(' '.join([str(x) for x in c[i]]))

if __name__ == "__main__":
    main()


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

int main(){
	string s;
	cin>>s;
	ll red=0,blue=0;
	for(ll i=0;i<s.length();i++){
		if(s[i]=='0'){
			red++;
		}else{
			blue++;
		}
	}
	cout<<min(red,blue)*2<<endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int cnt[50] = {}, a, b;
  for (int i=0; i<M; i++) {
    cin >> a >> b;
    a--;
    b--;
    cnt[a]++;
    cnt[b]++;
  }
  for (int i=0; i<N; i++)
    cout << cnt[i] << endl;
  return 0;
}

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

int cnt;

void insertionSort(int A[], int n, int g) {
    int i, j, v;
    for (i = g; i < n; i++) {
        v = A[i];
        j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void shellSort(int A[], int n) {
    int m, g, i;
    int size = 100;
    int *G;

    G = (int *)malloc(sizeof(int) * size);
    if (G == NULL) exit(0);

    cnt = 0;

    // G[i]を生成
    for (m = 0, g = 1; g <= n; m++) {
        if (m >= size) {
            size = size + 100;
            G = (int *)realloc(G, sizeof(int) * size);
            if (G == NULL) exit(0);
        }
        G[m] = g;
        g = 3 * g + 1;
    }

    // 実行と出力
    printf("%d\n", m);
    for (i = m - 1; i >= 0; i--) {
        printf("%d", G[i]);
        if (i) printf(" ");
        else printf("\n");
        insertionSort(A, n, G[i]);
    }
    printf("%d\n", cnt);
    for (i = 0; i < n; i++) printf("%d\n", A[i]);

    free(G);
}

int main(void) {
    int A[1000000];
    int n, i;
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", A + i);
    shellSort(A, n);
    return 0;
}



Measured memory_bytes: 5588
R, C, K = map(int, input().split())

item = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    item[r][c] = v

# 多次元配列を生成する際、使いたい引数を逆順で書くと上手くいく

# dp = [[[0 for _ in range(4)] for _ in range(C + 1)] for _ in range(R + 1)]
# とするとTLEだった。(R+1)*4(C+1)だと通るみたいだが、あまり本質的ではない気がする。
# 以下ではdp0,dp1,dp2,dp3という4つの配列を作ることにする。

dp0 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]
dp1 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]
dp2 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]
dp3 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]

for i in range(R + 1):
    for j in range(C + 1):

        # 下に移動する場合、アイテムの個数はリセットされる
        if i <= R - 1:
            # 移動先のアイテムを取らない場合
            dp0[i + 1][j] = max(dp0[i + 1][j],
                                dp0[i][j],
                                dp1[i][j],
                                dp2[i][j],
                                dp3[i][j])
            # 移動先のアイテムを取る場合
            dp1[i + 1][j] = max(dp1[i + 1][j],
                                dp0[i][j] + item[i + 1][j],
                                dp1[i][j] + item[i + 1][j],
                                dp2[i][j] + item[i + 1][j],
                                dp3[i][j] + item[i + 1][j])

        # 右に移動する場合、アイテムの個数は維持される
        if j <= C - 1:
            dp0[i][j + 1] = max(dp0[i][j + 1],
                                dp0[i][j])
            dp1[i][j + 1] = max(dp1[i][j + 1],
                                dp1[i][j])
            dp2[i][j + 1] = max(dp2[i][j + 1],
                                dp2[i][j])
            dp3[i][j + 1] = max(dp3[i][j + 1],
                                dp3[i][j])
            # 現在のアイテム数が3未満(0 or 1 or 2)の場合、移動先のアイテムをとることが可能                             [k + 1], now + item[i][j + 1])
            dp1[i][j + 1] = max(dp1[i][j + 1],
                                dp0[i][j] + item[i][j + 1])
            dp2[i][j + 1] = max(dp2[i][j + 1],
                                dp1[i][j] + item[i][j + 1])
            dp3[i][j + 1] = max(dp3[i][j + 1],
                                dp2[i][j] + item[i][j + 1])

# 最終的にR行で取るアイテムの個数についてそれぞれ調べる、3個が最適とは限らない
ans = max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1])
print(ans)


Measured memory_bytes: 474296
/**
 * @author karayuu
 */
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }
    if (a + b == 15) {
        println("+")
        return
    }
    if (a * b == 15) {
        println("*")
        return
    }

    println("x")
}

Measured memory_bytes: 38016
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long idx=0;
    long A, B;
    cin >> A >> B;
    long x_A, x_B, x_A_max, x_B_max;
    //A = x * 1.08 - x = 0.08 * x = 8  / 100 * x ⇔ x = A * 100 / 8
    //B = x * 1.10 - x = 0.10 * x = 10 / 100 * x ⇔ x = B * 100 / 10
    //if(A * 100 % 8)
    if(A * 100.0 / 8 > A * 100 / 8) x_A = A * 100 / 8 + 1;
    else    x_A = A * 100 / 8;
    x_B = B * 10;
    cerr << x_A * 0.08 << ":" << A << ":" << x_A << endl;
    x_A_max = (A + 1) * 100 / 8;
    x_B_max = (B + 1) * 10;
    //cerr << x_A << ":" << x_B << endl;
    //cerr << x_A_max << ":" << x_B_max << endl;
    long lowest_x=-1;
    // x_A <= lowest_x < x_A_max and x_B <= lowest_x < x_B_max
    for(size_t i=x_A;i<x_A_max; i++)
    {
        if(x_B <= i && i < x_B_max)
        {
            lowest_x = i;
            break;
        }
    }
    cout << lowest_x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int A[200];
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    for (int k = 0; ; k++) {
        for (int i = 0; i < n; i++) {
            if (A[i] & 1) {
                cout << k << endl;
                return 0;
            } else {
                A[i] /= 2;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
main(void)
{
    int n;
    cin>>n;
    for(int i=1;i<26;i++)
    {
        if(n%(i*4)==0)
        {
            cout<<"Yes";
            exit(0);
        }
        else
        {
            int d=n%(i*4);
            if(d%7==0)
            {
                cout<<"Yes";
                exit(0);
            }
        }
    }
    for(int i=1;i<20;i++)
    {
        if(n%(i*7)==0)
        {
            cout<<"Yes";
            exit(0);
        }
        else
        {
            int d=n%(i*7);
            if(d%4==0)
            {
                cout<<"Yes";
                exit(0);
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
/*
  	Coded by Apojacsleam
*/
#include<cstdio>
#include<algorithm>
using namespace std;
struct NODE{
	int belong,year,num,tt;
}a[100001];
bool cmp(NODE A,NODE B)
{
	return (A.belong==B.belong)?(A.year<B.year):(A.belong<B.belong);
}
bool cmp2(NODE A,NODE B){return A.num<B.num;}
void write(int x)
{
	if(x<10) printf("00000");
	else if(x<100) printf("0000");
	else if(x<1000) printf("000");
	else if(x<10000) printf("00");
	else if(x<100000) printf("0");
	printf("%d",x);
	
}
int n,m,t;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) scanf("%d%d",&a[i].belong,&a[i].year),a[i].num=i;
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<=m;i++)
	{
		if(a[i].belong!=a[i-1].belong) t=1;
		else t++;
		a[i].tt=t;
	}
	sort(a+1,a+m+1,cmp2);
	for(int i=1;i<=m;i++)
	 write(a[i].belong),write(a[i].tt),putchar('\n');
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
// #define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
// using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
// typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
// 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; }

using namespace std;

int main()
{
  int N;
  long long K;
  cin>>N>>K;
  vector<int>A;
  A.resize(N);
  rep(i,0,N){
    cin>>A[i];
  }
  
  vector<int>visitTimes(N,0);
  int i=0;
  while(visitTimes[i]<1 && K>0){
    visitTimes[i]++;
    i=A[i]-1;
    K--;
  }
  if(K==0){
    cout<<i+1<<endl;
    return 0;
  }
  
  int countInLoop=0;
  while(visitTimes[i]<2 && K>0){
    visitTimes[i]++;
    i=A[i]-1;
    K--;
    countInLoop++;
  }
  if(K==0){
    cout<<i+1<<endl;
    return 0;
  }
  
  //cout<<countInLoop<<endl;
  
  int numberPlace=K%countInLoop;
  rep(j,0,numberPlace){
    i=A[i]-1;
  }
  
  //cout<<numberPlace<<endl;
  
  cout<<i+1<<endl;
  
  return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
const int N=100+10;
int n;
char A[N],B[N],C[N];

int main()
{
	scanf("%d",&n);
	scanf("%s%s%s",A+1,B+1,C+1);
	int ans=0;
	for (int i=1;i<=n;i++) {
		if (A[i]==B[i] && B[i]==C[i]) ans+=0;
		else if (A[i]!=B[i] && A[i]!=C[i] && B[i]!=C[i]) ans+=2;
		else ans+=1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N;
  cin >> N;
  int ans = 100000;
  int sum_A = 0, sum_B = 0;
  for (int i = 1; i < N; i++){
    sum_A = findSumOfDigits(i);
    sum_B = findSumOfDigits(N - i);
    ans = min(ans, sum_A + sum_B);
  }
  cout << ans << endl;
}
    
  
  

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if a*500+b*100+c*50 == X:
                cnt += 1
                
print(cnt)
            

Measured memory_bytes: 3060
#include <bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v)              \
  cerr << #v ":[ ";          \
  for (auto macro_vi : v)    \
  {                          \
    cerr << macro_vi << " "; \
  }                          \
  cerr << "]" << endl;
#define ddump(v)                     \
  cerr << #v ":" << endl;            \
  for (auto macro_row : v)           \
  {                                  \
    cerr << "[";                     \
    for (auto macro__vi : macro_row) \
    {                                \
      cerr << macro__vi << " ";      \
    }                                \
    cerr << "]" << endl;             \
  }
#define damp(m)                                                   \
  for (auto macro_pair : m)                                       \
  {                                                               \
    cerr << macro_pair.first << ":" << macro_pair.second << endl; \
  }
#define dpair(p) cerr << #p ":" \
                      << "(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define itr(macro_v, i) macro_v.begin() + i
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<char>> g(h, vector<char>(w, '#'));
  vector<vector<int>> ans(h, vector<int>(w, 0));
  queue<pair<int, int>> que;
  rep(i, h)
  {
    rep(j, w)
    {
      cin >> g[i][j];
      if (g[i][j] == '#')
      {
        que.push(make_pair(i, j));
        ans[i][j] = -1;
      }
    }
  }
  int num = 1;
  while (!que.empty())
  {
    // d(num);
    pair<int, int>
        tmp = que.front();
    int x = tmp.first, y = tmp.second;
    ans[x][y] = num;
    que.pop();
    int p = y - 1;
    // left
    while (0 <= p and ans[x][p] == 0)
    {
      ans[x][p] = num;
      p--;
    }
    // riht
    p = y + 1;
    while (p < w and ans[x][p] == 0)
    {
      ans[x][p] = num;
      p++;
    }
    num++;
  }
  int start = -1;
  for (int i = 0; i < h; i++)
  {
    if (ans[i][0] != 0)
    {
      start = i;
    }
  }

  for (int i = start; 0 <= i; i--)
  {
    if (ans[i][0] == 0)
    {
      for (int j = 0; j < w; j++)
      {
        ans[i][j] = ans[i + 1][j];
      }
    }
  }
  for (int i = start; i < h; i++)
  {
    if (ans[i][0] == 0)
    {
      for (int j = 0; j < w; j++)
      {
        ans[i][j] = ans[i - 1][j];
      }
    }
  }
  // ddump(ans);
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      cout << ans[i][j] << ' ';
    }
    cout << endl;
  }
  return 0;
}

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

N = int(input())
huga = tuple(map(int,input().split())) 

MinLen = 999999999999999
for i in range(min(huga),max(huga)+1):
    Len = 0
    for j in huga:
        Len += (j-i) ** 2
    if Len < MinLen:
      MinLen = Len
print( MinLen )


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

using namespace std;

typedef long long ll;
const ll MOD = 1000000007;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> r;
	if (n % 2 == 1) r.emplace_back(0);
	for (int i = 1 + n % 2; i < n; i += 2) {
		r.emplace_back(i);
		r.emplace_back(i);
	}
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	bool flag = true;
	for (int i = 0; i < n; i++) {
		if (a[i] != r[i]) {
			flag = false;
			break;
		}
	}
	if (!flag) cout << 0 << endl;
	else cout << modpow(2, n / 2) << endl;
	return 0;
}

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

class Solver {
  private int sumDigits(int a) {
    int sum = 0;
    while (a > 0) {
      sum += a % 10;
      a /= 10;
    }
    return sum;
  }
  
  private int sumDigitsTwo(int n, int a) {
    return sumDigits(a) + sumDigits(n - a);
  }
  
  public int solve(int n) {
    int min = sumDigitsTwo(n, 1);
    for (int a = 2; a < n; a++) {
      int b = n - a;
      min = Math.min(min, sumDigitsTwo(n, a));
    }
    return min;
  }
}

public class Main {
  private static void execute(ContestReader reader, PrintWriter out) {
    out.println(new Solver().solve(reader.nextInt()));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(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 int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
}

class Algorithm {
  private static void swap(Object[] list, int a, int b) {
    Object tmp = list[a];
    list[a] = list[b];
    list[b] = tmp;
  }
  
  public static <T extends Comparable<? super T>> boolean nextPermutation(T[] ts) {
    int rightMostAscendingOrderIndex = ts.length - 2;
    while (rightMostAscendingOrderIndex >= 0 &&
        ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostAscendingOrderIndex + 1]) >= 0) {
      rightMostAscendingOrderIndex--;
    }
    if (rightMostAscendingOrderIndex < 0) {
      return false;
    }
    
    int rightMostGreatorIndex = ts.length - 1;
    while (ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostGreatorIndex]) >= 0) {
      rightMostGreatorIndex--;
    }
    
    swap(ts, rightMostAscendingOrderIndex, rightMostGreatorIndex);
    for (int i = 0; i < (ts.length - rightMostAscendingOrderIndex - 1) / 2; i++) {
      swap(ts, rightMostAscendingOrderIndex + 1 + i, ts.length - 1 - i);
    }
    return true;
  }
}



Measured memory_bytes: 22996
from collections import deque

N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    edge[u-1].append([v-1, w])
    edge[v-1].append([u-1, w])
    
d = [0]*(N)

q = deque()
q.append([0, 0])
visited = [0]*(N)
while q:
    temp = q.pop()
    for L in edge[temp[0]]:
        if visited[L[0]] == 0:
            d[L[0]] = L[1] + temp[1]
            q.append([L[0], d[L[0]]])
            visited[L[0]] = 1
            
for i in range(N):
    print(d[i]%2)

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

int main() {
  int N;
  cin >> N;
  vector<int> num(110);
  for(int i=0;i<N;i++) {
    cin >> num.at(i);
  }
  sort(num.begin(),num.end());
  reverse(num.begin(),num.end());
  int sum_a=0,sum_b=0;
  for(int i=0;i<N;i++) {
    if(i%2==0) sum_a+=num.at(i);
    else sum_b+=num.at(i);
  }
  cout << sum_a-sum_b << endl;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    S = input()
    ans = 0
    for n in range(N + 1):
        c = 0
        for s in set(S[:n]):
            if S[n:].count(s) > 0:
                c += 1
        ans = max(ans, c)
    print(ans)


main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n ; j++)

int main(void) {
  int n, INF = 1e9 + 7;
  cin >> n;
  vector <int> v(n);
  ffor(n) cin >> v[i];
  vector <int> dp(n, INF);
  dp[0] = 0;
  dp[1] = abs(v[1] - v[0]);
  for(int i = 2; i < n; i++) {
    dp[i] = min(dp[i - 1] + abs(v[i] - v[i - 1]), dp[i - 2] + abs(v[i] - v[i - 2]));
  }
  cout << dp.back() << '\n';
}

Measured memory_bytes: 3960
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] S = new String[n];
    for (int i = 0; i < n; i++) {
      S[i] = sc.next();
    }
    int[][] alp = new int[n][26];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < S[i].length(); j++) {
        alp[i][S[i].charAt(j) - 'a']++;
      }
    }
    int[] count = new int[26];
    Arrays.fill(count, Integer.MAX_VALUE);
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < n; j++) {
        if (alp[j][i] < count[i]) {
          count[i] = alp[j][i];
        }
      }
    }
    String ans = "";
    for (int i = 0; i < 26; i++) {
      int length = count[i];
      for (int j = 0; j < length; j++) {
        ans += Character.toString((char)(i + 'a'));
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair < ll, ll >&a, const pair < ll, ll >&b){
    return ((a.ss < b.ss) || (a.ss == b.ss && a.ff < b.ff));
}

signed main(){ 
    IOS
    //io_set();
    ll n;
    cin >> n;
    ll m = n, s = 0;
    while(n){
        s+=(n%10);
        n/=10;
    }
    if(m % s  == 0){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
    return 0;
}



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

vector<int >b;
int main ()
{
    int k,a,b;
    cin>>k>>a>>b;

    for(int i=a;i<=b;i++)if(i%k==0) {cout<<"OK"<<endl;return 0;}
    cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
int main(){
    fastread;
    ll n,i,j,k,l,m;
   cin>>n;
   ll sum=1000*(ll)(n/500);
   n%=500;
   sum+=5*(ll)(n/5);
   cout<<sum;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
S = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(1<<N):
    ok = True
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i&(1<<(s-1)):
                cnt += 1
        if cnt%2 != P[j]:
            ok = False
            break
    if ok:
        ans += 1
print(ans)


Measured memory_bytes: 9188
#include "bits/stdc++.h"
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int x, int y) {                                                             //return x^y in order(log(y))
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}

template<class T>
struct Dijkstra {
private:
  int n;
  vector<vector<pair<T, T>>> graph;

public:
  vector<T> shortest_path;
  Dijkstra(vector<vector<pair<T, T>>> &G): n(G.size()) { //
    graph = G;
    shortest_path.assign(n, (T)INF);
  }
  void dijkstra(int s) {
    rep(i, n) {
      shortest_path[i] = (T)INF;
    }
    shortest_path[s] = 0;
    priority_queue<pair<T, T>, vector<pair<T, T>>, greater<>> que;
    que.push({0, s});
    while (!que.empty()) {
      pair<T, T> p = que.top();
      que.pop();
      int v = p.second;
      if (shortest_path[v] < p.first) continue;
      for (auto e: graph[v]) {
        if (shortest_path[e.first] > shortest_path[v] + e.second) {
          shortest_path[e.first] = shortest_path[v] + e.second;
          que.push({shortest_path[e.first], e.first});
        }
      }
    }
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int V, E, r;
  cin >> V >> E >> r;
  vector<vector<pair<int, int>>> graph(V);
  rep(i, E) {
    int s, t, d;
    cin >> s >> t >> d;
    graph[s].emplace_back(t, d);
  }
  Dijkstra<int> s(graph);
  s.dijkstra(r);
  FOR(i, s.shortest_path) {
    if (i != INF)
      cout << i << endl;
    else
      cout << "INF" << endl;
  }
}


Measured memory_bytes: 30748
l = int(input())
n = int(input())
mom = 0
for _ in range(n):
  x, w = map(int, input().split())
  mom += x * w

weight = []
while mom:
  if mom < 0:
    add_weight = min(-mom, 50000)
    mom += add_weight
    weight.append((1, add_weight))
  elif mom > 0:
    add_weight = min(mom, 50000)
    mom -= add_weight
    weight.append((-1, add_weight))

print(len(weight))
for t in weight:
  print(*t)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
const int INF=(int)10e9;

int main() {
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	    cin>>a[i];
	vector<int> dp(n);
	fill(dp.begin(),dp.end(),0);
    for(int i=1;i<n;i++)
    {
       dp[i]=INF;
       for(int j=1;j<=k;j++)
       {
           if(i-j>=0)
           dp[i]=min(dp[i],abs(a[i]-a[i-j])+dp[i-j]);
       }
    }
    
    cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
int f[100010],n,h[100010],k;
int fuck(int i);
int min(int i,int k)
{
    int m=1000000007,j;
    for(j=1;j<=k;j++)
    {
        if((fabs(h[i]-h[i+j])+fuck(i+j))<m)
        m=fabs(h[i]-h[i+j])+fuck(i+j);
    }
    return m;
}
int fuck(int i)
{
    if(f[i]==-1)
    {
        if(i==n-1)
        return f[i]=0;
        else if(i>=n-k && i<n-1)
        return f[i]=min(i,n-i-1);
        else
        return f[i]=min(i,k);
    }
    else 
    return f[i];
}
int main()
{
    int i,ans;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&h[i]);
        f[i]=-1;
    }
    ans=fuck(0);
    printf("%d\n",ans);
    return 0;
}

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

int main() {
    long h;
    int num;
    long sum = 0;

    cin >> h;
    num = floor(log2(h)) + 1;

    for (int i=0; i < num; i++) {
        sum += pow(2, i);
    }

    cout << sum << endl;
}

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> campas(h, vector<int>(w));
    for (int i=0; i<h; i++){
        string s;
        cin >> s;
        for (int j=0; j<w; j++){
            if (s[j] == '#') campas[i][j] = 1;
            else campas[i][j] = 0;
        }
    }
    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            if (campas[i][j] == 0) continue;
            if ((0 <= i+1) && (i+1 < h)) {if (campas[i+1][j] > 0) campas[i][j] += 1;}
            if ((0 <= i-1) && (i-1 < h)) {if (campas[i-1][j] > 0) campas[i][j] += 1;}
            if ((0 <= j+1) && (j+1 < w)) {if (campas[i][j+1] > 0) campas[i][j] += 1;}
            if ((0 <= j-1) && (j-1 < w)) {if (campas[i][j-1] > 0) campas[i][j] += 1;}
        }
    }
    string ans="Yes";
    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            if (campas[i][j] == 1) ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main(){
	int number[5];
	int k;
	int i , min=123 , max=0;
	for(i = 0 ; i != 5 ; i++){
		scanf("%d" , &number[i]);
		if(number[i] < min) min=number[i];
		if(number[i] > max) max=number[i];
	}
	scanf("%d",&k);
	if(max-min <= k) printf("Yay!\n");
	else printf(":(\n");
	
	return 0;
}

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

int main()
{	
	int A,B = 0;
  	int result = 0;
  	cin >> A >> B;
  	if (B % A == 0){
      result = A + B;
    }else{
      result = B - A;
    }
  	cout << result << endl;
    return 0;
}

Measured memory_bytes: 256