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

int main(){
    char com[10], str[1010], p[1010], t;
    int a, b, q;
    scanf("%s", str);
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        scanf("%s", com);
        scanf("%d %d", &a, &b);
        if(com[0] == 'p'){ // print
            for(int j = a; j <= b; j++){
                printf("%c", str[j]);
            }
            printf("\n");
        }else if(com[2] == 'v'){ // reverse
            for(int j = 0; j <= (b-a)/2; j++){
                t = str[a+j];
                str[a+j] = str[b-j];
                str[b-j] = t;
            }
        }else if(com[2] == 'p'){ // replace
            scanf("%s", p);
            for(int j = 0; j <= b-a; j++){
                str[j+a] = p[j];
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2620
N,Y = map(int,input().split())
count = 0
for i in range(N + 1):
  for j in range(N + 1 - i):
    if i * 10000 + j * 5000 + (N - i - j) * 1000 == Y and N - i - j >= 0:
      x = str(i)+ ' ' + str(j) + ' ' + str(N - i - j)
      count += 1
      break
      
if count == 0:
  print('-1 -1 -1')
else:
  print(x)

Measured memory_bytes: 3064
import qualified Data.Array as A
import Data.Array ((!))

main :: IO ()
main = print . (lucas !) . read =<< getLine
    
lucas :: A.Array Int Int
lucas = A.array (0, 86) [(i, lucaNum i)|i<-[0..86]]
    where 
    lucaNum 0 = 2
    lucaNum 1 = 1
    lucaNum n = lucas!(n-1) + lucas!(n-2)

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

using namespace std;
using  ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}

int main(){
  int a,b,c,d;
  std::cin >> a>>b>>c>>d;

  while (1) {
    c-=b;

    if(c<=0){
      std::cout << "Yes" << '\n';
      break;
    }
    a-=d;


    if(a<=0){
      std::cout << "No" << '\n';
      break;
    }
    
  }

  return 0;
}


Measured memory_bytes: 3616
Tmp = []
Tmp = input().rstrip().split(' ')

nN = int(Tmp[0])
nL = int(Tmp[1])

sWord = []

for i in range(nN):
  S = input()
  sWord.append(S)

sWord.sort()

for i in range(nN):
  print('%s' %(sWord[i]), end='')

print()



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

a_sum = sum(a)
a_sum //= 2

a_sum_0 = sum(a[1::2])

ans = []
a0 = a_sum -a_sum_0
ans.append(2*a0)
a[0] -= a0
for i in range(n-1):
    ans.append(2*a[i])
    a[i+1] -= a[i]
    
print(*ans)

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

used = [False] * a[-1]
res = 0
for i in range(n):
    if used[a[i]-1]:
        continue
    if i == n - 1 or a[i] != a[i+1]:
        res += 1
    for j in range(a[i], a[-1]+1, a[i]):
        used[j-1] = True

print(res)

Measured memory_bytes: 98460
#include <stdio.h>
#include <limits.h>
int main()
{
  long long a,b,c,d;
  scanf("%ld%ld%ld%ld",&a,&b,&c,&d);
  long long n[4];
  n[0] = a*c;
  n[1] = a*d;
  n[2] = b*c;
  n[3] = b*d;
  long long max = LONG_MIN;
  //printf("%ld",max);
  int i = 0;
  while (i < 4)
  {
    if (n[i] > max)
      max = n[i];
    //printf("%ld\n",max);
    i++;
  }
  printf("%ld",max);
}

Measured memory_bytes: 1732
from sys import stdin
import numpy as np
import statistics


n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = sorted(li)
ni = lin[n//2]
iti = lin[n//2-1]

for i in range(n):
    if li[i] <= iti:
        print(ni)
    else:
        print(iti)

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

#define ll long long

void solve() {
	int n;
	string s;
	cin >> n >> s;
	char a[26];
	char c = 'A';
	for (int i = 0; i < 26; ++i) {
		a[i] = c;
		c++;
	}
	for (int i = 0; i < (int) s.size(); ++i) {
		int idx;
		for (int j = 0; j < 26; ++j)
			if (a[j] == s[i])
				idx = j;
		idx = (idx + n) % 26;
		cout << a[idx];
	}
}

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

	int t = 1;
//	cin >> t;
	while (t--) {
		solve();
	}
}


Measured memory_bytes: 3584
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    t = [[0] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                tq = [[i-1, j-1], [i-1, j], [i-1, j+1], [i, j-1], [i, j+1], [i+1, j-1], [i+1, j], [i+1, j+1]]
                for k, l in tq:
                    if 0 <= k < h and 0 <= l < w:
                        if s[k][l] != "#":
                            t[k][l] += 1
    for i in range(h):
        sp = []
        for j in range(w):
            if s[i][j] != "#":
                sp.append(str(t[i][j]))
            else:
                sp.append("#")
        print("".join(sp))


if __name__ == '__main__':
    slove()


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

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> A(H);

  for (int i=0; i<H; i++){
    cin >> A[i];
  }

  for (int i=0; i<W+2; i++){
    cout << '#';
  }
  cout << endl;
  for (int i=0; i<H; i++){
    cout << '#' << A[i] << '#' << endl;
  }
  for (int i=0; i<W+2; i++){
    cout << '#';
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

F = min(A,B,C,D,E)

if N%F != 0:
    time = N//F + 5
else:
    time = N//F + 4

print(time)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
		ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll n;
	cin>>n;
	ll a[n+1],fq[n+1],sum=0,i,ans,k,fk;
	for(i=1;i<=n;i++)fq[i]=0;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		fq[a[i]]++;
	}
	for(i=1;i<=n;i++)
	{
		if(fq[i]>1)
		sum+=(fq[i]*(fq[i]-1)/2);
	}
	for(k=1;k<=n;k++)
	{
		fk=fq[a[k]];
		if(fk<2)ans=sum;
		else
		{
			ans=sum-fk+1;
		}
		cout<<ans<<"\n";
	}
}

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

using System.Collections;

class Program
{
    static void Main()
    {
        var nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var ab = nums[0];
        var bc = nums[1];
        var ca = nums[2];

        Console.WriteLine(ab * bc / 2);

    }
    
}


Measured memory_bytes: 13396
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main(){
    int n,tmp;
    cin >> n;
    int count_a[1000001] = {0};
    int a_max = -1;
    vector<int> b;
    int count = 0;
    for(int i = 0;i < n;i++){
        cin >> tmp;
        count_a[tmp]++;
        if(a_max < tmp){
            a_max = tmp;
        }
    }

    if(count_a[1] > 1){
        cout << 0 << endl;
        return 0;
    }
    /*
    for(int i= 1;i <= a_max;i++){
        if(count_a[i] == 1){
            b.push_back(i);
        }
    }
    */

    int blength = b.size();
    bool dp[a_max+1];
    for(int i = 0; i < a_max+1;i++){
        dp[i] = true; 
    }

    for(int i= 1;i <= a_max;i++){
        if(count_a[i] >= 1){
            tmp = i;
            for(int j = tmp +tmp;j <= a_max; j+=tmp){
                dp[j] = false;
            }
        }
    }

    for(int i= 1;i <= a_max;i++){
        if(count_a[i] == 1){
            tmp = i;
            if(dp[tmp]){
                count++;
            }
        }    
    }

    cout << count << endl;
    return 0;
}

/*
5
24 11 8 3 16

4
5 5 5 5

10
33 18 45 28 8 19 89 86 2 4
*/

Measured memory_bytes: 8004
def ac(n,m,a,c):
    ans = []
    for i in range(n):
        min = 10000000000000
        bang = 0
        for w in range(m):
            if abs(a[i][0] - c[w][0]) + abs(a[i][1] - c[w][1]) < min:
                min = abs(a[i][0] - c[w][0]) + abs(a[i][1] - c[w][1])
                bang = w + 1
        ans.append(bang)
    return ans

def main():
    n , m = map(int, input().split())
    a = [list(map(int , input().split())) for i in range(n)]
    c = [list(map(int , input().split())) for i in range(m)]
    ans = ac(n , m , a , c)
    for i in range(len(ans)):
        print(ans[i])

if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
  int N, M; cin >> N >> M;
  vector<int> K(N), A(M, 0);
  for (int i = 0; i < N; ++i) {
    cin >> K[i];
    for (int j = 0; j < K[i]; ++j) {
      int m; cin >> m;
      A[m-1]++;
    }
  }

  int result = 0;
  for (int i = 0; i < M; ++i) {
    if (A[i] == N) result++;
  }

  cout << result << endl;
}

Measured memory_bytes: 256
Q = int(input())
def sieve(x):
    if x < 2: return []
    primes = [i for i in range(x)]
    primes[1] = 0
    for p in primes:
        if p > x ** (1/2): break
        if p == 0: continue
        for np in range(2 * p, x, p): primes[np] = 0
    return [p for p in primes if p != 0]

PS = sieve(10**5)

like2017 = [x for x in PS if (x+1) // 2 in PS]

import bisect
for i in range(Q):
  l, r = map(int, input().split())
  li = bisect.bisect_left(like2017, l-1)
  ri = bisect.bisect_left(like2017, r+1)
  print(ri - li)

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

bool DP(vector<int>& a, int A){    //部分和問題

    vector<vector<bool> > dp((int)a.size() + 10, vector<bool> (A + 40001, false));
    
    //dp初期条件
    dp[0][0 + 40000] = true;
    
    //dp
    for(int i = 0; i < a.size(); i++){
        for(int j = 0; j <= A + 40000; j++){
            if(j >= a[i]) dp[i + 1][j] = dp[i][j - a[i]] || dp[i + 1][j];
            
            if(j + a[i] < A + 40000) dp[i + 1][j] = dp[i][j + a[i]] || dp[i + 1][j];            
        }
    }
    if(dp[(int)a.size()][A + 40000]) return true;
    else return false;
}



int main(){


    string s; cin >> s;
    int x, y; cin >> x >> y;
    s += 'T';
    int idx;
    for(int i = 0; i < (int)s.size(); i++){

        if(s[i] == 'T'){
            idx = i;
            break;
        }
    }

    //idx進むのは確定
    x -= idx;

    vector<int> X;
    vector<int> Y;
    bool mode = true;   //Yに関しまして
    int num = 0;
    for(int i = idx + 1; i < (int)s.size(); i++){
        if(s[i] == 'T'){
            if(mode){
                Y.push_back(num);
                mode = false;
            }
            else{
                X.push_back(num);
                mode = true;
            }

            num = 0;
        }
        else num++;
    }

    X.push_back(0);
    Y.push_back(0);
    x = abs(x);
    y = abs(y);

    /*cout << x << " " << y << endl;
    for(int i = 0; i < X.size(); i++) cout << X[i] << " ";
    cout << endl;
    for(int i = 0; i < Y.size(); i++) cout << Y[i] << " ";
    cout << endl;*/    
    
    bool flag1 = false;
    bool flag2 = false;    

    
    
    flag1 = DP(X, x);
    flag2 = DP(Y, y);    

    if(flag1 && flag2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0);


int main()
{
	FASTIO;
	ll n;
	 cin>>n;
	 vector<ll>vect(n);
	 f(i,0,n)
	  cin>>vect[i];



	  ///dp[i][j] -> will denote x-y for the array starting
	  //with i and ending at j
	  ll dp[n][n] ={};

	  for(int i=0;i<n;i++)
        dp[i][i]=vect[i];

      //we just need to fill the upper triangle
      //as both upper and lower will be mirror images.
      ll times=n-1;
      for(ll diff=1;diff<=n-1;diff++,times--)
      {
          ll row=0,col=row+diff;
          for(int i=1;i<=times;i++)
          {
              dp[row][col]= max(vect[row]-dp[row+1][col],vect[col]-dp[row][col-1]);
              row++;
              col++;
          }
      }

      /*for(int i=0;i<n;i++)
      {
          for(int j=0;j<n;j++)
            cout<<dp[i][j]<<" ";
          cout<<"\n";
      }*/

	  cout<<dp[0][n-1]<<"\n";

	return 0;
}













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

# define C continue;

# define ll long long
# define ld long double

# define pb push_back
# define I insert
# define PQ priority_queue

# define vi vector < int >
# define vll vector < ll >
# define vc vector < char >
# define vb vector < bool >
# define vs vector < string >

# define vvi vector < vector < int > >
# define vvll vector < vector < ll > >
# define vvc vector < vector < char > >
# define vvb vector < vector < bool > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >

# define vpii vector < pair < int , int > >
# define vpll vector < pll >

# define F first
# define S second

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .
/// Start using lower bound !!

const int N = 1e5 + 2 ;
ll dp[N] ;

int n , w ;
pii v[N] ;

void read ()
{
    cin >> n >> w ;

    for ( int i=0 ; i < n ; i ++ )
        cin >> v[i].F >> v[i].S ;
}

void solve ( int test_case )
{
    read () ;

    memset ( dp , -1 , sizeof ( dp ) ) ;
    dp[0] = 0 ;

    for ( int i=0 ; i < n ; i ++ )
    {
        for ( int j = max ( 0 , w - v[i].F ) ; j > -1 ; j -- )
        {
            ll &ans = dp[j + v[i].F] ;

            if ( dp[j] != -1 )
                ans = max ( ans , dp[j] + v[i].S ) ;
        }
    }

    ll ans = 0 ;

    for ( int i = 0 ; i <= w ; i ++ )
        ans = max ( ans , dp[i] ) ;

    cout << ans ; line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i = 1 ; i <= t ; i ++ )
    {
        solve ( i ) ;
    }

    return 0;
}


Measured memory_bytes: 4440
#include<stdio.h>
#include<string.h>
const int N = 1300;
const int M = 256;
int main()
{
	char str[N];
	int ary[M] = {0};
	while(fgets(str, 1300, stdin))
	{
		for(int i = 0; i < strlen(str)-1; i++)
		{
			if(str[i] >= 'A' && str[i] <= 'Z')
			{
				ary[str[i] + 32]++;
			}
			else
			{
				ary[str[i]]++;
			}
		}
	}
	for(int i = 'a'; i <= 'z'; i++)
	{
		printf("%c : %d\n", i, ary[i]);
	}
	return 0;
}


Measured memory_bytes: 2712
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(a) begin(a),end(a)
#define INF 999999999
#define debug(x) cerr << #x << ":" << x << '\n'
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef unsigned long long ull;
typedef unsigned long ul;
typedef unsigned int  ui;

int main() {
	int N, A, B;
	cin >> N;
	if(N == 1) cout << "Hello World" << "\n";
	else {
		cin >> A >> B;
		cout << A + B << "\n";
	}
}


Measured memory_bytes: 256
#include<stdio.h>

int abs(int a){
  if(a >= 0){
    return a;
  }
  else{
    return -a;
  }
}

int main(void){
  int h , w , d;
  scanf("%d %d %d",&h ,&w ,&d);

  int a , iti[90002][2];
  for(int i = 0;i < h;i ++){
    for(int j = 0;j < w;j ++){
      scanf("%d",&a);
      iti[a][0] = i+1;
      iti[a][1] = j+1;
    }
  }

  int q;
  scanf("%d",&q);
  int l[q] , r[q];
  for(int i = 0;i < q;i ++){
    scanf("%d %d",&l[i] ,&r[i]);
  }

 int dcount[90002] = {0};
 for(int i = d+1;i <= h*w;i ++){
   dcount[i] = abs(iti[i][0] - iti[i-d][0]) + abs(iti[i][1] - iti[i-d][1]) + dcount[i-d];
 }

 for(int i = 0;i < q;i ++){
   printf("%d\n",dcount[r[i]] - dcount[l[i]]);
 }

  return 0;

}

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

using namespace std;

int main()
{
   string s;
   cin >> s;

   int count = 0;
   int len = s.length();

   for (int i = 0; i < len / 2; i++)
   {
      if (s.at(i) != s.at(len - 1 - i))
         count++;
   }
   cout << count << endl;
}


Measured memory_bytes: 256
N = int(input())
def prime(n):
    flag = False
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
            break
    return True
    

L = []
for i in range(2,55556):
    if prime(i) and i%5 == 1:
        L.append(i)
print(*L[:N])

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int a,p; cin >>a >>p;
  cout << (3*a+p)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int N , M , ans = 1;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        ans*=2;
    }
    cout << (1900 * M + 100 * (N - M)) * ans << endl;
}

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

int main () {
    int n,d;
    int count{0};
    
    cin >> n >> d;
    for(int i {0}; i< n; i++){
        double a,b;
        cin >> a >> b;
        if(sqrt((a*a)+(b*b))<=d) 
            count++;
    }
    cout << count << endl;
    
    
    return 0;    
}


Measured memory_bytes: 3740
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>()>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    int n=in();
    vecll a(n),b(n);
    ll suma=0,sumb=0;
    rep(i,n){
        a[i]=in();
        suma+=a[i];
    }
    rep(i,n){
        b[i]=in();
        sumb+=b[i];
    }
    ll cnt=sumb-suma;
    if(cnt<0){
        cout<<"No"<<endl;
        return 0;
    }
    ll x=cnt,y=cnt;
    rep(i,n){
        if(a[i]>b[i])y-=a[i]-b[i];
        if(a[i]<b[i]){
            if((a[i]-b[i])%2==0){
                x-=(b[i]-a[i])/2;
            }else{
                x-=(b[i]-a[i])/2+1;
                y--;
            }
        }
    }
    if(x>=0&x*2==y){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <iomanip>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pair<int,int>, int> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;

int sgn(int x){
    return x < 0 ? -1 : 1;
}

int n, k, a[100010];
int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    int best = INF;
    for (int i = k - 1; i < n; i++) {
        if (sgn(a[i]) != sgn(a[i - k + 1])) {
            int x = min(abs(a[i]), abs(a[i - k + 1]));
            best = min(best, a[i] - a[i - k + 1] + x);
        } else {
            best = min(best, max(abs(a[i]), abs(a[i - k + 1])));
        }
    }
    cout << best;
}

Measured memory_bytes: 640
N = int(input()) #1行目のNを取得する
s = [int(input()) for i in range(N)] #複数行の数値の入力を取得
max = max(s)

p = sorted(s)
next = p[-2]

ind = s.index(max)

for j in range(len(s)):
    if j==ind:
        print(next)
    else:
        print(max)

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

int main() {
	int K;
	cin >> K;
	string S;
	cin >> S;

	int i;
	string x, answer;
	if (S.size() <= K) {
		cout << S << endl;
	}
	else {
		for (i = 0; i < K; i++) {
			answer += S[i];
		}
		answer += "...";
	}
	cout << answer << endl;
	return 0;
}

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

int main() {
	string s, t;
	cin >> s >> t;
	int l = s.size();
	for (int i = 0; i < 111; i++) {
		s = s.substr(1) + s[0];
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
x = int(input())

if x ==1:
    print(1)

else:
    flag = False
    for i in range(x):
        for k in range(x-1):
            for j in range(2, 10):
                if x-i == (k+1)**j:
                    flag = True
                    print(x-i)
                    break
            if flag:
                break
        if flag:
            break

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

int main(){
  	int n;
  	int a,b;
 	cin>>n; 
  	a=(int)(n/100);
  	b=n%100;
  	if(b>10*a+a){
    	cout<<(a+1)*100+(a+1)*10+a+1<<endl;
    }else{
    	cout<<a*100+a*10+a<<endl;
    
    }

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();
		String c = scan.next();
		String ans;
		ans = c.substring(0,b-1)+c.substring(b-1,b).toLowerCase()+c.substring(b);
		System.out.println(ans);
	}
}

Measured memory_bytes: 21332
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt();
    if(b>=c&&d>=a){
      System.out.println((int)Math.min(Math.min(b-a,d-a),Math.min(b-c,d-c)));
    }else{
      System.out.println(0);
    }
  }
}


Measured memory_bytes: 24788
import java.util.*;

/**
 * Created by sonetsuyoshi on 2016/07/31.
 */
public class Main {
    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        long[] a = new long[n];
        for(int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }

        long count1 = 0;

        // first item > 0
        long[] s = new long[n];
        long[] b = new long[n];

        if(a[0] < 1) {
            b[0] = 1;
            count1 += Math.abs(a[0]) + 1;
        } else b[0] = a[0];

        s[0] = b[0];

        for(int i = 1; i < n; i++) {
            if(b[i - 1] > 0) {
                long c = -s[i - 1] - 1;
                if(c < a[i])
                    b[i] = c;
                else
                    b[i] = a[i];
                s[i] = s[i - 1] + b[i];
                count1 += Math.abs(a[i] - b[i]);
            } else {
                // b[i - 1] < 0
                long c = -s[i - 1] + 1;
                if(c > a[i])
                    b[i] = c;
                else
                    b[i] = a[i];
                s[i] = s[i - 1] + b[i];
                count1 += Math.abs(a[i] - b[i]);
            }
        }

        Arrays.fill(s, 0);
        Arrays.fill(b, 0);

        long count2 = 0;

        if(a[0] > -1) {
            b[0] = -1;
            count2 += Math.abs(a[0]) + 1;
        } else b[0] = a[0];

        s[0] = b[0];

        for(int i = 1; i < n; i++) {
            if(b[i - 1] > 0) {
                long c = -s[i - 1] - 1;
                if(c < a[i])
                    b[i] = c;
                else
                    b[i] = a[i];
                s[i] = s[i - 1] + b[i];
                count2 += Math.abs(a[i] - b[i]);
            } else {
                // b[i - 1] < 0
                long c = -s[i - 1] + 1;
                if(c > a[i])
                    b[i] = c;
                else
                    b[i] = a[i];
                s[i] = s[i - 1] + b[i];
                count2 += Math.abs(a[i] - b[i]);
            }
        }

        System.out.println(Math.min(count1, count2));
    }
}

Measured memory_bytes: 60896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
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; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int a, b;
  cin >> a >> b;
  if ((a + b) % 2) cout << "IMPOSSIBLE" << endl;
  else cout << (a + b) / 2 << endl;
}


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

using namespace std;
typedef long long ll;
const int maxn = 123456;
ll dp[110][maxn];
int w[110], v[110];
const int inf = 0x7f7f7f7f;
int main(){
//    freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, W;
    cin >> n >> W;
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < n; ++i){
        cin >> w[i] >> v[i];
//        dp[i][0] = v[i];
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= W; ++j){
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if(w[i] + j <= W){
                dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j] + v[i]);
            }
        }
    }
//    for(int i = 0; i <= n; ++i){
//        for(int j = 0; j <= W; ++j){
//            cout << dp[i][j] << " ";
//        }
//        cout << endl;
//    }
    ll res = 0;
    for(int i = 0; i <= W; ++i){
        res = max(res, dp[n][i]);
    }
    cout << res << endl;
    return 0;
}


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

int main() {
    int D, G;
    cin >> D >> G;
    vector<int> p(D), c(D);
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for (int mask = 0; mask < 1 << D; mask++) {
        int sum = G;
        int num = 0;
        int m;
        for (int i = 0; i < D; i++) {
            if (mask & 1 << i) {
                sum -= 100 * (i + 1) * p[i] + c[i];
                num += p[i];
            } else {
                m = i;
            }
        }

        if (sum >= 0) {
            int tmp = (sum + 100 * (m + 1) - 1) / (100 * (m + 1));
            if (tmp < p[m]) {
                num += tmp;
            } else {
                continue;
            }
        }

        ans = min(ans, num);
    }

    cout << ans << endl;
}

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

mod=10**9+7

s=[0]*n
s[0]=a[0]
for i in range(1,n):
    s[i]=(s[i-1]+a[i])%mod

ss=0
for i in range(n-1):
    ss+=((s[n-1]-s[i])*a[i])%mod

print(ss%mod)


Measured memory_bytes: 94008
#include <stdio.h>
#include <string.h>
 
int main(void)
{
	char s[27];
	int i,t[26]={0};
	scanf("%s",s);
	for(i=0;i<strlen(s);i++){
		t[s[i]-'a']++;
	}
	for(i=0;i<26;i++){
		if(t[i]>1){
			puts("no");
			return 0;
		}
	}
	puts("yes");
	return 0;
}

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


using namespace std;

int main(){
    int cnt = 0;
    int judge = 0;
    string s;
    cin >> s;

    for(int i = 0; i < s.length();i++){
        if(s[i] == 'o'){
            cnt++;
        }
    }

    judge = cnt + (15-s.length());

    if(judge >= 8){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
 
  // ここにプログラムを追記
  if((c == 'a') || (c == 'i') || (c == 'u') || (c == 'e') || (c == 'o')){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
alp = [chr(i + 97) for i in range(26)]

ans = [[] for _ in range(n)]
ans[0] = ['a']
for i in range(1, n):
    for j in ans[i - 1]:
        for k in range(len(set(j)) + 1):
            ans[i].append(j + alp[k])
print(*ans[n - 1], sep='\n')


Measured memory_bytes: 20488
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;


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

    int N,K;
    int count = 0;
    cin >> N >> K;
    int A;
    REP(i,N) cin >>A;

    while(N > 0){
        if(count == 0){
            N = N - K;
            count++;
        }
        else{
            N = N - K + 1;
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <utility>
#define llint long long
#define inf 1e9
#define eps 1e-8

using namespace std;

int n;
double p[105];
vector<int> G[105], revG[105];
vector<int> topo;
bool used[105];
int scc[105];
bool come[105];
double prob[105];

void tpsort(int v)
{
  used[v] = true;
  for(int i = 0; i < G[v].size(); i++){
    if(!used[G[v][i]]) tpsort(G[v][i]);
  }
  topo.push_back(v);
}
void sccdfs(int v, int id)
{
  used[v] = true;
  scc[v] = id;
  for(int i = 0; i < revG[v].size(); i++){
    if(!used[revG[v][i]]) sccdfs(revG[v][i], id);
  }
}

int main(void)
{

  while(1){
    cin >> n;
    if(n == 0) break;

    int m, x;
    for(int i = 1; i <= n; i++) revG[i].clear();
    for(int i = 1; i <= n; i++){
      cin >> p[i];
      cin >> m;
      G[i].clear();
      for(int j = 0; j < m; j++){
        cin >> x;
        G[i].push_back(x);
        revG[x].push_back(i);
      }
    }

    for(int i = 1; i <= n; i++) used[i] = false;
    topo.clear();
    for(int i = 1; i <= n; i++) if(!used[i]) tpsort(i);
    reverse(topo.begin(), topo.end());

    int id = 0;
    for(int i = 1; i <= n; i++) used[i] = false;
    for(int i = 0; i < topo.size(); i++) if(!used[topo[i]]) sccdfs(topo[i], id++);

    //for(int i = 1; i <= n; i++) cout << scc[i] << " "; cout << endl;

    int S = id;
    for(int i = 0; i < S; i++) come[i] = false;
    for(int i = 1; i <= n; i++){
      for(int j = 0; j < G[i].size(); j++){
        if(scc[i] != scc[G[i][j]]) come[scc[G[i][j]]] = true;
      }
    }
    for(int i = 0; i < S; i++) prob[i] = 1;
    for(int i = 1; i <= n; i++) prob[scc[i]] *= p[i];

    double ans = 1;
    for(int i = 0; i < S; i++){
      if(come[i]) continue;
      ans *= (1 - prob[i]);
    }
    printf("%.11f\n", ans);
  }

  return 0;
}



Measured memory_bytes: 3304
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
#define pb push_back
#define ins insert
#define pll pair<ll,ll>
#define fi first
#define se second
#define mpr make_pair
#define vtr vector
#define itor iterator 
#define N 998244353
#define endl '\n'
#define cont continue
#define MAX ll(2e5+2)
using namespace std;
ll power(ll a,ll b,ll mod=N)
{
	if(b==0)return 1;
	ll ans=1;
	while(b>0)
	{
		if(b&1)ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}
ll fact[MAX],invf[MAX];

void facto()
{
	fact[0]=fact[1]=1;
	ll i;
	for(i=2;i<=MAX-1;i++)
	{
		fact[i]=(fact[i-1]*i)%N;
	}
	invf[MAX-1]=power(fact[MAX-1],N-2);
	for(i=MAX-2;i>=0;i--)
	{
		invf[i]=(invf[i+1]*(i+1))%N;
	}
}
ll c(ll n,ll r,ll mod=N)
{
	if(n<=0 or r<0)return 0;
	if(n<r)return 0;
	if(n==r)return 1;
	ll ans=fact[n];
	ans=(ans*invf[n-r])%N;
	ans=(ans*invf[r])%N;
	return ans;
}

int main()
{
	ios;
	ll t=1;
//	cin>>t;
facto();
	while(t--)
	{
		ll n,m,k;
		cin>>n>>m>>k;
		ll ans=0,i;
		if(n==1)
		{
			cout<<m;cont;
		}
		for(i=0;i<=k;i++)
		{
			ans=(ans+(((m*c(n-1,i))%N)*(power(m-1,n-i-1)))%N)%N;
		}
		cout<<ans;
	}
}

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

int main(){
    ll n;
    cin >> n;
    vector<ll> cnt(n+1);

    ll res = 0;
    for(ll i=1;i<=n;i++) {
        for(ll j=i;j<=n;j+=i) {
            cnt[j]++;
        }
        res += (cnt[i] * i);
    }
    cout << res << endl;
}


Measured memory_bytes: 81344
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int N, M;

class Color{
public:
    double L, a, b;
    Color(double L, double a, double b): L(L), a(a), b(b){};
};

double dist(Color c1, Color c2){
    return (c1.L-c2.L)*(c1.L-c2.L) + (c1.a-c2.a)*(c1.a-c2.a) + (c1.b-c2.b)*(c1.b-c2.b);
}

void solve(){
    vector<Color> colors;
    for(int i=0; i<N; i++){
        double L, a, b; cin >> L >> a >> b;
        colors.push_back(Color(L, a, b));
    }
    
    double ans = 0;
    
    for(int i=0; i<1<<N; i++){
        vector<int> vec;
        if(__builtin_popcount(i) != M) continue;
        
        for(int j=0; j<N; j++)
            if(i>>j&1)
                vec.push_back(j);
        
        double t = 0;
        for(int j=0; j<M; j++)
            for(int k=j+1; k<M; k++)
                t += dist(colors[vec[j]], colors[vec[k]]);
        ans = max(ans, t);
    }
    
    cout << ans << endl;
    //printf("%.6f\n", ans);
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    
    cin >> N >> M;
    solve();
    
    return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int N=0,M=0,X=0,ans=INF;
  std::cin >> N>>M>>X;
  int v[N][M+1]={};
  int vv[M]={};
  rep(i,N)Rep(j,M+1)std::cin >> v[i][j];
  bool exist = false,a=true;
  for(int bit = 0;bit < (1<<N);++bit){
    int sum = 0;
    for(int i=0;i<N;++i){
      if(bit &(1<<i)){
        sum+=v[i][0];
        rep(j,M)vv[j]+=v[i][j+1];
      }
    }
    rep(i,M){
      if(vv[i]<X)a=false;
      vv[i]=0;
    }
    if(a){
      if(sum<ans)ans=sum;
      exist=true;
    }
    a=true;
    sum=0;
  }
  if(exist)std::cout << ans << '\n';
  else std::cout << -1 << '\n';
}


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

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
typedef pair<ll, int> P;

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { for (auto &_e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

int A, B, C, D, E, F;

double mR = 0.0;
int mW = 0;
int mS = 0;

bool dp[3030][3030];

void update(int W, int S) {
	double r = (1.0 * S) / (W + S);
	if (r > mR) {
		mR = r;
		mW = W;
		mS = S;
	}
	dp[W][S] = true;
}

void rec(int W, int S) {
	if (dp[W][S]) {
		return;
	}
	if (W + S > F) {
		return;
	}
	if (W + S + C <= F) {
		if (W / 100.0 * E - S >= C) {
			rec(W, S + C);
			update(W, S + C);
		}
	}
	if (W + S + D <= F) {
		if (W / 100.0 * E - S >= D) {
			rec(W, S + D);
			update(W, S + D);
		}
	}
	if (W + S + 100 * A <= F) {
		rec(W + 100 * A, S);
		update(W + 100 * A, S);
	}
	if (W + S + 100 * B <= F) {
		rec(W + 100 * B, S);
		update(W + 100 * B, S);
	}
}

int main(void) {
	cin >> A >> B >> C >> D >> E >> F;

	for (int i = 0; i < 3030; ++i) {
		for (int j = 0; j < 3030; ++j) {
			dp[i][j] = false;
		}
	}
	rec(0, 0);
	if (mW == 0) {
		mW += 100 * A;
	}
	cout << mW + mS << " " << mS << endl;
	return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using  namespace  std;
using ll=long long;
int main(){
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int count=0;
  for(int i=0;i<=a;i++){
  for(int j=0;j<=b;j++){
  for(int k=0;k<=c;k++){
  if(x==i*500+j*100+k*50){
  count++;
  break;
  }
  }
  }
  }
  cout<<count<<endl;
}


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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  lint n;
  cin >> n;
  vector< lint > cnt(1e5+1, 0);
  lint sum = 0;
  for (lint i=0; i<n; ++i) {
    lint ai;
    cin >> ai;
    cnt[ai]++;
    sum += ai;
  }
  lint q;
  cin >> q;
  for (lint ep=0; ep<q; ++ep) {
    lint b, c;
    cin >> b >> c;
    sum += cnt[b] * (c-b);
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << endl;
  }
  return 0;
}


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

int main() {

int n,m,time,x,rep = 1;

cin >> n >> m;

time =  m*1900 + (n-m)*100;

for(int i = 0;i < m;i++){
    rep *= 2;
}

x = time * rep;

cout << x << endl;

return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
X=0
for i in range(2,N):
  X^=A[i]
S=A[0]+A[1]
T=S-X
Y=0
for i in range(41):
  if (1<<(i+1))&T:
    Y+=(1<<i)
if Y^(S-Y)^X:
  print(-1)
  exit()
for i in range(41,-1,-1):
  if X&(1<<i) and (Y+(1<<i))<=A[0]:
    Y+=(1<<i)
if 0<Y<=A[0]:
  print(A[0]-Y)
else:
  print(-1)

Measured memory_bytes: 61696
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = [int(input())-1 for i in range(N)]

    cur = 0
    for i in range(2*N):
        cur = A[cur]

        if cur == 1:
            print(i+1)
            exit()

    print(-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 49112
N = int(input())
S = input()
han_1 = ''
han_2 = ''
if N % 2 != 0:
    print('No')
else:
    n = int(N/2)
    #print(n)
    for i in range(n):
        han_1 = han_1 + S[i]
    for i in range(n,N):
        han_2 = han_2 + S[i]

    if han_1 == han_2:
        print('Yes')
    else:
        print('No')

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

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

using namespace std;

const int INF=1<<29;

string s;
int dp[1000002][2];

int dfs(int i,int carry){
	if(i==s.length()) return carry;

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

	int a=s[i]-'0';
	int res=INF;
	rep(d,10){
		res=min(res,dfs(i+1,(a+d+carry)/10)+(a+d+carry)%10+d);
	}
	return dp[i][carry]=res;
}

int main(){
	memset(dp,-1,sizeof dp);

	cin>>s;
	reverse(s.begin(),s.end());
	s+="0";

	printf("%d\n",dfs(0,0));

	return 0;
}


Measured memory_bytes: 87300
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5+10;
int n, k;

void solve(int num){
	stack<int> s;
	int t = (k+1)/2;
	for(int i = 0; i < n; i++) s.push(t);
	while(num--){
		int temp = s.top();
		s.pop();
		if(temp == 1);
		else{
			s.push(temp-1);
			if(s.size() < n)
				while(s.size() != n)
					s.push(k);
		}
	}
	vector<int> v;
	while(!s.empty()){
		v.push_back(s.top());
		s.pop();
	}
	reverse(v.begin(), v.end());
	for(int i = 0; i < v.size()-1; i++){
		cout << v[i] << " ";
	}
	if(v.size() >= 1) cout << v[v.size()-1];
}
int main(){

	while(cin >> k >> n){
		if(!(k & 1)){
			cout << k/2 << " ";
			for(int i = 0; i < n - 2; i++){
				cout << k << " ";
			}
			if(n-1 > 0) cout << k;
		}
		else{
			solve(ceil((n-1)/2.0));
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 4636
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int n; readV(n);
  string[] s; readM(n, s);
  int m; readV(m);
  string[] t; readM(m, t);

  int[string] h;
  foreach (si; s) h[si]++;
  foreach (ti; t) h[ti]--;

  auto r = h.values.reduce!max;
  writeln(max(0, r));
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
	int a,b,c,x;
	cin>>a;
	cin>>b;
	cin>>c;
	cin>>x;
	int ans = 0;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			for(int k = 0; k <= c; k++){
				if( i*500 + j*100 + k*50 == x) ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}



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

#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed<<setprecision(a)<<
#define F first
#define S second
#define I insert
#define pii pair<int,int>
#define trav(a, x) for(auto& a : x)
#define rep(n) for(int i = 0;i<n;i++)
#define rrep(n) for(int i = n-1;i>=0;i--)
#define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" "; cout<<endl;
#define ingrid(data,n,commands) for(int i = 0; i<n; i++){cin>>data[i];commands}
#define section(a,b,w) set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w) set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define copy(a,w) copy(a.begin(), a.end(),back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'
#define last(a) a[sz(a)-1]

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

// Graph DFS
const int fx[] = { +1, -1, +0, +0};
const int fy[] = { +0, +0, +1, -1};

//primes for hashing 937,991,1013,1409,1741

//Returns index of first element not less than key and more than key respectively
#define lb(data,key) lower_bound(all(data),key) - data.begin();
#define up(data,key) upper_bound(all(data),key) - data.begin();
#define fnd(data,key) find(all(data),key) - data.begin();
/* Long Long Int */
#define int long long int

const int N = 1e5 + 5;

int n;
int a[N], b[N], c[N];


int dp[N][3];

void solve() {
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[1][0] = a[0];
    dp[1][1] = b[0];
    dp[1][2] = c[0];

    for (int i = 2; i <= n; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            for (int k = 0; k < 3; ++k)
            {
                if (j == k)continue;
                
                int t;
                if (j == 0) t = a[i - 1];
                else if (j == 1)t = b[i - 1];
                else t = c[i - 1];

                dp[i][j] = max(dp[i][j], dp[i - 1][k] + t);
            }
        }
    }

    cout<<max({dp[n][0], dp[n][1], dp[n][2]})<<endl;
}


signed main()
{
    FAST
    int t = 1;
    // cin>>t;
    while (t--) solve();
    return 0;

    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>

int	main(void){
	char S[1010];
	int i;

	scanf("%s", S);
	i = 0;
	while(S[i] != 0){
		i++;
	}
	if (S[i - 1] == 's'){
		strcat(S, "es");
	} else {
		strcat(S, "s");
	}
	printf("%s\n", S);
	return (0);
}


Measured memory_bytes: 1624