akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class Solve
{
    static void Main(string[] args)
    {
        new ABC_B();
    }
}
public class ABC_A
{
    public ABC_A()
    {
        var inn=Ex.ReadIntArray();
        int n = inn[0];
        int m = inn[1];
        Console.WriteLine(n*(n-1)/2+m*(m-1)/2);
    }
}
public class ABC_B
{
    public ABC_B()
    {
        string s = Ex.Read;
        int n = s.Length;
        Console.WriteLine((c1(s,1,n)  && c1(s,1,(n-1)/2)&& c1(s,(n+3)/2,n)  )? "Yes" : "No");
    }

    bool c1(string s,int ss,int ee)
    {
        int i = 0;
        while ((ss+i-1) <= (ee / 2))
        {
            if (s[ss+i-1] != s[ee - i-1]) return false;
            i++;
        }

        return true;
    }
}
public class ABC_C
{
    public ABC_C()
    {

    }
}
public class ABC_D
{
    public ABC_D()
    {

    }
}
public class ABC_E
{
    public ABC_E()
    {

    }
}
public class ABC_F
{
    public ABC_F()
    {

    }
}
public static class Ex
{
    public static string Read { get { return Console.ReadLine().Trim(); } }
    public static int ReadInt { get { return int.Parse(Read); } }
    public static long ReadLong { get { return long.Parse(Read); } }
    public static double ReadDouble { get { return double.Parse(Read); } }
    public static string[] ReadArray() { return Read.Split(' '); }
    public static int[] ReadIntArray() { return Read.Split(' ').Select(s => int.Parse(s)).ToArray(); }
    public static long[] ReadLongArray() { return Read.Split(' ').Select(s => long.Parse(s)).ToArray(); }
    public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

Measured memory_bytes: 11092
n,k=map(int,input().split())
s=0
if k%2==0:
    s0=0
    for i in range(1,n+1):
        if i%k==0:
            s0+=1
    s1=0
    for i in range(1,n+1):
        if i%k==k//2:
            s1+=1
    s=s0**3+s1**3
else:
    s0=0
    for i in range(1,n+1):
        if i%k==0:
            s0+=1
    s=s0**3
print(s)


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

using ll=long long;

int main(){
    int X; cin >> X;
    int A, B;
    bool ok=false;
    for(A=1; ; A++){
        for(B=A-1; ; B--){
            int res=pow(A, 5)-pow(B, 5);
            if(res == X){
                ok=true;
                break;
            }
            else if(res > 1000000000) break;
        }
        if(ok) break;
    }
    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 4120
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define endl "\n"
#define cv(c) (int)(c-'a')
#define db(x) cerr << #x << ": " << x << " "
#define db2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << " "
#define bn() cerr << endl
#define sep() cerr << "-------" << endl
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;

ll v[100005];
ll v1[100005];
ll pos[100005];
ll pos1[100005];
int main(){
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++){
        cin >> v[i];
    }
    for (int i = 0; i < n; i++){
        cin >> v1[i];
    }
    for (int i = 0; i < n; i++){
        pos[i] = mod + 1LL;
        pos1[i] = pos[i];
    }
    pos[0] = 1, pos1[n - 1] = 1;
    for (int i = 1; i < n; i++){
        if (v[i] == v[i - 1]) pos[i] = min(pos[i], v[i]);
        else pos[i] = 1LL;
    }
    for (int i = n - 2; i >= 0; i--){
        if (v1[i] == v1[i + 1]) pos1[i] = min(pos1[i], v1[i]);
        else pos1[i] = 1LL;
    }
    ll res = 1;

    for (int i = 0; i < n; i++){
        if (pos[i] == 1 && pos1[i] == 1){
            if (v[i] != v1[i]) res = 0;
        }
        else if (pos[i] == 1){
            if (v[i] > v1[i]) res = 0;

        }
        else if (pos1[i] == 1){
            if (v[i] < v1[i]) res = 0;
        }
    }
    if (v[n - 1] != v1[0]) res = 0;
    for (int i = 0; i < n; i++){
        res *= min(pos[i], pos1[i]);
        res %= mod;
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3328
#include<cmath>
#include<iostream>
#include<bitset>

#define MAX 10001

using namespace std;

int bComposite[MAX];

void ComputePrimes(){
	bComposite[1] = 1;
	for(int i = 4; i <= 10000; ++i){
		if( bComposite[ i ] == 0 ){
			for(int j = 2; j <= sqrt((double)i); ++j){
				if( i % j == 0 ){
					bComposite[ i ] = 1;
					break;
				}
			}
		}
		if( bComposite[ i ] == 0 ){
			for(unsigned int j = 2; i * j <= 10000; ++j){
				bComposite[ i * j ] = 1;
			}
		}
	}
}

int main()
{
	ComputePrimes();

	while( true )
	{
		int N, P = 0;
		
		cin >> N;

		if( cin.eof() )
			break;

		for(int i = 1; i <= N; ++i){
			if( !bComposite[N - i + 1] && !bComposite[ i ] )
				++P;
		}

		cout << P << '\n';
	}
	return 0;
}

Measured memory_bytes: 0
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

ll maxVec(vector<ll> &v) {
	ll ans = -INF;
	rep(i, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

vvl graph;
vvl graphRev;
vl dp;

ll solve(ll n) {
	if (dp[n] != -1)return dp[n];

	ll c = 0;
	rep(i, graphRev[n].size()) {
		c = max(c, 1 + solve(graphRev[n][i]));
	}
	dp[n] = c;
	return c;
}


int main() {
	ll n,m,x,y;
	cin >> n >> m;
	graph = vvl(n, vl(0));
	graphRev = vvl(n, vl(0));
	dp = vl(n, -1);
	vector<bool> checkStart(n, true);
	rep(i, m) {
		cin >> x >> y;
		checkStart[y - 1] = false;
		graph[x - 1].push_back(y - 1);
		graphRev[y - 1].push_back(x - 1);
	}
	vl nonOut(n,0),nonIn(n,0);
	rep(i, n) {
		if (graph[i].size() == 0) nonOut[i] ++;
		if (graphRev[i].size() == 0)nonIn[i] ++;
	}
	rep(i, n) {
		if (nonIn[i] > 0) dp[i] = 0;
	}
	ll ans = 0;
	rep(i, n) {
		if (nonOut[i] > 0) {
			ans = max(ans, solve(i));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<string>kaza(N);
  for(int i=0;i<N;i++){
    cin>>kaza.at(i);
  }
  set<string>kuzu;
  for(int j=0;j<N;j++){
    kuzu.insert(kaza.at(j));
  }
  cout<<kuzu.size()<<endl;
}

Measured memory_bytes: 25096
/*================================================
# ~  file:A.cpp
# ~~ date:2020-03-09
# ~~~author: SoMnus_L
#        |everybody finds love,in the end|
#   人の運命か,人の希望は悲しみにつづられているね
=================================================*/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define ll long long
const int N=1e6+10;
using namespace std;
typedef pair<int,int>PII;

string s;
int cnt1,cnt2;
int main(){
 ios::sync_with_stdio(false);
  cin>>s;
   for(int i=0;i<3;i++){
	if(s[i]=='A') cnt1++;
	else          cnt2++;
   }
   if((cnt1==2 && cnt2==1) || (cnt1==1 && cnt2==2))  cout<<"Yes"<<endl;
   else  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N,M,Q = map(int,readline().split())
train = [[0] * (N + 1) for i in range(N + 1)]
for i in range(M):
  l,r = map(int,readline().split())
  train[l][r] += 1
  
for i in range(len(train)):
  for j in range(1,len(train[i])):
    train[i][j] = train[i][j] + train[i][j - 1]
    
for j in range(len(train)):
  for i in range(1,len(train[i])):
    train[i][j] = train[i - 1][j] + train[i][j]

for i in range(Q):
  p,q = map(int,readline().split())
  print(train[q][q] - train[p - 1][q] - train[q][p - 1] + train[p - 1][p - 1])


Measured memory_bytes: 13628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

const int MAX = 300000;

int Ls[MAX];
int Rs[MAX];

int main()
{
	int N;
	string S;

	cin >> N >> S;

	int ans = 300001;

	int cnt = 0;

	int l = 0;
	int r = 0;
	for (int ni = 1; ni < N; ni++) {
		if (S[ni - 1] == 'W') l++;
		if (S[N - ni] == 'E') r++;

		Ls[ni] = l;
		Rs[N - ni - 1] = r;
	}

	for (int ni = 0; ni < N; ni++) {
		cnt = Ls[ni] + Rs[ni];
		ans = min(ans, cnt);
	}

	printf("%d", ans);

	return 0;
}



Measured memory_bytes: 2948
import java.util.Scanner;

class Main{
	int X;

  public static void main(String[] ar){
    new Main();
  }
  public Main(){
  	Scanner sc=new Scanner(System.in);
  	String line=sc.nextLine();
  	X=Integer.parseInt(line);  	
  	//System.out.println(X);
  	
    int E=0;
    for(double r=2;r<=10;r++){
      int a=(int)Math.pow((int)Math.pow(X+0.1, 1.0/r), r);
      if(E<a) E=a;
    } 
    System.out.println(E);
  }
}

Measured memory_bytes: 23764
MOD = 10**9 + 7
N = int(input())
S1 = input()
S2 = input()
check = []
index = 0
while index < N:
    if S1[index] == S2[index]:
        check.append(1)
        index += 1
    else:
        check.append(2)
        index += 2
ans = 3 if check[0] == 1 else 6
for i in range(1,len(check)):
    if check[i-1] == 1:
        ans *= 2
    elif check[i] == 2:
        ans *= 3
    ans %= MOD
print(ans)

Measured memory_bytes: 61888
def gcd(a,b):
    return gcd(b,a%b) if a%b else b

def break_primes(n):
    pn = n
    cnt = 0
    d = set()
    while pn % 2 == 0:
        pn //= 2
        d.add(2)
    p = 3
    while(p*p <= n):
        if pn % p == 0:
            d.add(p)
        while(pn % p == 0):
            pn //= p
        p += 2
    if pn != 1:
        d.add(pn)
    return d

def vectorize(n,primes,a):
    pn = n
    for p in range(len(primes)):
        a[p] = 0
        while pn % primes[p] == 0:
            a[p] += 1
            pn //= primes[p]


N = int(input())
A = list(map(int,input().split()))
if N == 2:
    print(max(A[0],A[1]))
if N > 2:
    primes = list(break_primes(gcd(A[0],A[1]))|break_primes(gcd(A[1],A[2]))|break_primes(gcd(A[2],A[0])))
    P = len(primes)
    vec_0 = [0 for _ in range(P)]
    vec_1 = [0 for _ in range(P)]
    vectorize(A[0],primes,vec_0)
    vectorize(A[1],primes,vec_1)
    perfect = [0 for _ in range(P)]
    perfect_idx = [ -1 for _ in range(P)]
    onemiss = [0 for _ in range(P)]
    for p in range(P):
        perfect_idx[p] = 0 if vec_0[p] < vec_1[p] else 1
        perfect[p] = min(vec_0[p],vec_1[p])
        onemiss[p] = max(vec_0[p],vec_1[p])
    vec_n = [0 for _ in range(P)]
    for n in range(2,N):
        vectorize(A[n],primes,vec_n)
        for p in range(P):
            if vec_n[p] < perfect[p]:
                onemiss[p] = perfect[p]
                perfect[p] = vec_n[p]
                perfect_idx[p] = n
            elif vec_n[p] < onemiss[p]:
                onemiss[p] = vec_n[p]
    import collections
    d = collections.defaultdict(lambda :1)
    ans = 1
    for p in range(P):
        ans *= primes[p] ** perfect[p]
        d[perfect_idx[p]] *= primes[p] ** (onemiss[p]-perfect[p])
    if len(d.items()) == 0:
        print(ans)
    else:
        print(ans*max(d.items(),key=lambda x:x[1])[1])

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

ll w[100000],d[100000];
int n,k;

bool C(ll x){
	ll cnt=0;
	rep(i,n){
		if(x<w[i])continue;
		cnt+=(x-w[i])/d[i]+1;
		if(cnt>=k)return true;
	}
	return false;
}
int main(){
	scanf("%d%d",&n,&k);
	rep(i,n)scanf("%lld%lld",&w[i],&d[i]);
	ll l=0,r=LLONG_MAX/2;
	while(l!=r){
		ll t=(l+r)/2;
		if(C(t))r=t;
		else l=t+1;
	}
	cout<<l<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

bool isACGT(char x){
  return x=='A' || x=='C' || x=='G' || x=='T';
}

int main(){
  string s;
  cin >> s;
  int n=0;
  vector<int> ans;
  for(int i=0;i<s.length();i++){
  if(isACGT(s[i])) n++;
  else {ans.push_back(n); n=0;}
  }
	ans.push_back(n);
  	cout << *max_element(ans.begin(),ans.end()) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <string.h>

void str_tolower(unsigned char *s){
	unsigned char *p;
	p = s;
	while(*p != '\0'){
		if( isupper(*p) ){
			*p = tolower(*p);
		}
		p++;
	}
}

int main(int argc, char** argv){
	short cnt;
	unsigned char w[13],t[1003], *pw,*pt;
	char end = 0;

	// Counter Reset
	cnt = 0;
	// Input W
	fgets(w,13,stdin);
	// ToLower W
	str_tolower(w);
	// Divide By Space
	pw = strtok(w, " \r\n");
	for(;;){
		// Input T
		fgets(t,1003,stdin);
		// Divide By Space
		pt = strtok(t, " \r\n");
		// Search
		while(pt != NULL ){
			// Finish Check
			if( strcmp(pt,"END_OF_TEXT") == 0 ){
				end = 1;
				break;
			}
			// ToLower T
			str_tolower(pt);
			if( strcmp(pw,pt) == 0 ){
				cnt++;
			}
			pt = strtok(NULL, " \r\n");
		}
		if( end ) {
			break;
		}
	}

	// Output
	printf("%d\n",cnt);

	return 0;
}

Measured memory_bytes: 536
from collections import deque

s = deque(input())
n = int(input())

#x.append(y)
#x.appendleft(y)

memo = 0
for i in range(n):
    q = list(input().split())
    if q[0] == '1':
        if  memo == 0: memo = 1
        else: memo = 0
    else:
        if memo == 0:
            if q[1] == '1': s.appendleft(q[2])
            else: s.append(q[2])
        else:
            if q[1] == '1': s.append(q[2])
            else: s.appendleft(q[2])

if memo == 0: print(''.join(s))
else: print(''.join(list(s)[::-1]))


Measured memory_bytes: 15896
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>
#include <array>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
#define acc(x) accumulate((x).begin(),(x).end(),0ll)
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ld pi=acos(-1);
const ll inf=(ll)1e12+1;
const int mod=1000000007;
//const int mod=998244353;

int n,m,k;
const int N=3e5+10;






int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n >> m;
    vvi vv(n,vi(m));
    vector<array<int,4>> ans;
    auto f = [&](int row){
        if(row==n-1){
            for(int i=0; i<m-1; i++){
                if(vv[row][i]&1){
                    vv[row][i]--;
                    vv[row][i+1]++;
                    ans.pb({row+1,i+1,row+1,i+2});
                }
            }
        }
        else{
            for(int i=0; i<m; i++){
                if(vv[row][i]&1){
                    vv[row][i]--;
                    vv[row+1][i]++;
                    ans.pb({row+1,i+1,row+2,i+1});
                }
            }
        }
    };
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            int u;
            cin >> u;
            vv[i][j]+=u;
        }
        f(i);
    }
    cout << ans.size() << el;
    for(auto it: ans){
        cout << it[0] << ' ' << it[1] << ' ' << it[2] << ' ' << it[3] << el;
    }
    return 0;
}






Measured memory_bytes: 6232
n,m = map(int,input().split())
sum = {}
ans = 0

for i in range(0,n):
  K = list(map(int,input().split()))
  for j in range(1,K[0] + 1):
    if K[j] not in sum:
      sum[K[j]] = 1
    else:
      sum[K[j]] += 1
for k in sum:
  if sum[k] == n:
    ans += 1
print(ans)
               


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

int main() {
  int a;cin >> a;
  a%=10;
  if (a==3) cout << "bon" << endl;
  else if (a==0 || a==1 || a==6 || a==8) cout << "pon" << endl;
  else cout << "hon" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
typedef long long ll;
ll n, sum, res;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 1; ; i++) {
        sum += i;
        if (sum >= n) {
            for (ll j = 1; j <= i; j++) {
                if (j == sum - n) continue;
                cout << j << endl;
            }
            break;
        }
    }
}


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

using namespace std;

int main (){
  int n, k;
  cin >> n >> k;
  vector<int> v(n, 0);
  for (int i = 0; i < k; i++){
    int d;
    cin >> d;
    for (int i = 0; i < d; i++){
      int m;
      cin >> m;
      v[m-1]++;
    }
  }
  cout << count(v.begin(), v.end(), 0) << "\n";
}

Measured memory_bytes: 3604
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

/*ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}*/

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

int main() {
	int a, b;
	cin >> a >> b;
	
	ll ans = 0;
	ll score = 0;
	score += (b * 1900) + ((a - b) * 100);
	ans = score * pow(2, b);
	cout << ans << endl;
}


Measured memory_bytes: 512
import std.stdio;
import std.string;
import std.algorithm;
import std.array;
import std.conv;

long to_digit(long[] numbers) {return numbers.reduce!("a * 10 + b");}

void main() {
  int times = readln.chomp.to!(int);
  foreach(t; 0..times) {
    long[] numbers = readln.chomp.dup.map!((x) => to!(long)(x - '0')).array.sort.array;
    writeln(numbers.reverse.to_digit - numbers.reverse.to_digit);
  }
}

Measured memory_bytes: 1056
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/
template<typename U, typename T> bool chmax(U& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template<typename U, typename T> bool chmin(U& a,T b) { if(a>b) { a=b; return 1; } return 0; }

struct S
{
	lnt v,w;
	S(lnt v, lnt w) : v(v),w(w) {} 
};

int main() {
	lnt n;
	std::cin >> n;
	std::vector<S> v;
	v.reserve(n+1);
	v.emplace_back(0,0);
	rep(i,n) {
		lnt a,b;
		std::cin >> a >> b;
		v.emplace_back(a,b);
	}
	// calc before for i<(1<<9)
	lnt N=1<<9;
	lnt L=1e5;
	debug(N);
	debug(v.size(),n);
	std::vector<std::vector<lnt> > pre(std::min(N,n+1),std::vector<lnt>(L+1,0));
	rep(i,std::min(N,n+1)) {
		if(i==0) continue;
		for(int j=L;j>0;j--) {
			pre[i][j]=pre[i>>1][j];
			if(j-v[i].w>=0) pre[i][j]=std::max(pre[i>>1][j],pre[i>>1][j-v[i].w]+v[i].v);
		}
	}
	auto calc = [&](auto f, lnt x, lnt l) -> lnt {
		if(x<N) return pre[x][l];
		lnt o=f(f,x>>1,l);
		if(l-v[x].w>=0) o=std::max(o,f(f,x>>1,l-v[x].w)+v[x].v);
		return o;
	};
	int q;
	std::cin >> q;
	rep(qq,q) {
		lnt v,l;
		std::cin >> v >> l;
		print(calc(calc,v,l));
	}
}


Measured memory_bytes: 409504
l = [0,0,0,0,0,0,0,0,0]
n = int(input())
a = list(map(int,input().split()))

for i in range(len(a)):
    if 1 <=  a[i] <= 399:
        l[0] = l[0] + 1
    elif 400 <=  a[i] <= 799:
        l[1] = l[1] + 1
    elif 800 <=  a[i] <= 1199:
        l[2] = l[2] + 1
    elif 1200 <=  a[i] <= 1599:
        l[3] = l[3] + 1
    elif 1600 <=  a[i] <= 1999:
        l[4] = l[4] + 1
    elif 2000 <=  a[i] <= 2399:
        l[5] = l[5] + 1
    elif 2400 <=  a[i] <= 2799:
        l[6] = l[6] + 1
    elif 2800 <=  a[i] <= 3199:
        l[7] = l[7] + 1
    else:
        l[8] = l[8] + 1
        
tokurei = 0        
for i in range(8):
    tokurei = tokurei + l[i]

if tokurei == 0:
    print('1 ' + str(l[8]) )
else:
    flag = 0
    for i in range(8):
        if l[i] > 0:
            flag = flag + 1
    print(str(flag) + ' ' + str(flag + l[8]))

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

// #define int long long
#define ll long long
#define pb push_back
#define vi vector<int>
#define vii vector<vector<int> >

template <class X> void print(X Target){ cout << Target << '\n'; }

signed main()
{
  ios::sync_with_stdio(false);
  int n;
  
  while (cin >> n, n){
    vi h(n + 1);
    for (int i = 0; i < n + 1; i++) cin >> h[i];

    for (int i = 0; i < n + 1; i++){
      vi t;
      for (int j = 0; j < n + 1; j++){
        if (i != j){
          t.pb(h[j]);
        }
      }
      int a = t[0], d = t[1] - t[0];
      int cnt = 0;
      for (int j = 0; j < n; j++){
        if (t[j] == a + j * d){
          cnt++;
        }
      }
      if (cnt == n){
        print(h[i]);
        break;
      }
    }
  }

  return (0);
}

Measured memory_bytes: 1220
#include<stdio.h>


#define MOD 1000000007
#define MAX 100001
long long int fac[MAX], finv[MAX], inv[MAX];
void MOD_COM_init(){
    fac[0] = 1;
    fac[1] = 1;
    finv[0] = 1;
    finv[1] = 1;
    inv[1] = 1;
    for(int 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;
    }
}
long long int MOD_combination(long long int n,long long int r){
    if(r<0||n<0){
        return 0;
    }
    if(n < r){
        return 0;
    }
    return (fac[n] * (finv[r] * finv[n-r] % MOD)) % MOD;
}

int main(){
    long long int n, m;
    scanf("%lld%lld", &n, &m);
    long long int a[m+2];
    a[0] = -1;
    a[m+1] = n+1;
    for(long long int i=1; i<=m; i++){
        scanf("%lld", &a[i]);
    }
    long long int ans = 1;
    MOD_COM_init();
    for(long long int i=1; i<=m+1; i++){
        //printf("%lld\n", ans);
        long long int w = (a[i]-1) - (a[i-1]+1);
        long long int buf = 0;
        for(long long int j=0; j<=w; j++){
            buf += MOD_combination(w, j);
            buf = buf % MOD;
            w--;
            //printf("  %lld\n", ans);
        }
        ans *= buf;
        ans = ans % MOD;
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 3328
N = int(input())
A = list(map(int,input().split()))
dic = {} #key(長方形の辺の要素数max:10**5/2 = 5*10**4) -> sortするとTLE
max1,max2 = 0,0
count = 0

for i in range(N):
  if(A[i] in dic):
    dic[A[i]] += 1
    if(dic[A[i]]%2 == 0):
      count += 1
      if(max1 < A[i]):
        max2 = max1
        max1 = A[i]
      if(A[i] < max1):
        max2 = max(max2,A[i])
  else:
    dic[A[i]] = 1

ans = 0
if(count >= 2):
  if(dic[max1] >= 4):
    ans = max1*max1
  else:
    ans = max1*max2
print(ans)

Measured memory_bytes: 17960
from math import ceil
X,K,D = map(int,input().split())
X = abs(X)

#とりあえず少しでも0に近づける試みをする。
tmp = abs(X)//D
if tmp >= K:
    print(X-D*K)
    exit()
K -= tmp
X -= D*tmp
if K%2 == 0:
    print(X)
else:
    print(abs(X-D))




Measured memory_bytes: 61972
import sys
sys.setrecursionlimit(10000)
N,M=map(int,input().split())
S=list(input())
T=list(input())

def gcd(x,y):
  if x==0:
    return y
  else:
    return gcd(y%x,x)

k=N*M//gcd(N,M)
X=[0]*N
for i,s in enumerate(S):
  X[i]=s
  
for i,t in enumerate(T):
  if (i*k//M)%(k//N)!=0:
    pass
  elif (i*k//M)%(k//N)==0 and X[(i*k//M)//(k//N)]==t:
    pass
  else:
    print(-1)
    exit()
    
print(k)

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

using namespace std;

int main()
{
    long long N, K; scanf("%lld%lld", &N, &K);
    // a+b = a+c = 0 mod K
    // b = c = -a mod K
    // b+c = -2a mod K = 0

    if(K % 2 == 1) {
      // K is odd -> (-2a) mod K = 0은 a mod K = 0과 동치 (역원 존재)
      printf("%lld\n", (N / K) * (N / K) * (N / K));
    }else {
      // K is even: 그건 아님.
      // a mod (K/2) = 0은 참.
      printf("%lld\n", 
        (N / K) * (N / K) * (N / K)  // a mod K = 0
        + (N / (K/2) - N / K) * ((N + K/2) / K) * ((N + K/2) / K)// a mod K = K/2
      );
    }

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;cin>>x;
    int ans = 0;
    if(x<100) ans = 0;
    else for(int i=1; i<100000/100; i++){
        if(100*i <= x && x <= 105*i) ans = 1;
    }
    cout<<ans<<endl;
    
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    cout << (!(N % 2) ? S.substr (0, N / 2) == S.substr (N / 2) ? "Yes" : "No"
                      : "No")
         << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    long long int d,t,s,a,b,c,e,f,g,h,i,j;
    cin>>d>>t>>s;
    a=t*s;
    if(a>=d)
    {
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3556
import sys

input = sys.stdin.readline


def main():
    A, B, C, D = map(int, input().split())

    while True:
        C -= B
        if C <= 0:
            ans = "Yes"
            break
        A -= D
        if A <= 0:
            ans = "No"
            break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9120
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
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;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 

 
void solve()
{
	int a ,b,c,d ;
	cin>>a>>b>>c>>d ;
	int ta = c/b + (c%b ? 1 : 0);
	int aa  = a/d + (a%d ? 1: 0) ;
	if(ta<=aa){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3848
S = input()

if S == 'SUN':
    print('7')
elif S == 'MON':
    print('6')
elif S == 'TUE':
    print('5')
elif S == 'WED':
    print('4')
elif S == 'THU':
    print('3')
elif S == 'FRI':
    print('2')
elif S == 'SAT':
    print('1')

Measured memory_bytes: 8968
#include<bits/stdc++.h>
#include<stdio.h>
#include<string>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())
#define INF 1e5
int main(){
	int a,b;
	cin>>a>>b;
	int ans=1;
	int res=b-a;
	if(b==1){
		cout<<0.0<<endl;
	}
	else{
	while (res>0){
		ans++;
		res-=a-1;
	}
	cout<<ans<<endl;}
}
	

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

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

vi x, y;
int N; 


int main(){
    cin >> N;
    x.resize(N), y.resize(N);
    map<pii, int> mp;
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i];
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(i == j) continue;
            mp[{x[i]-x[j], y[i]-y[j]}]++;
        }
    }
    int res=INF;
    for(auto p : mp){
        int cost=N-p.second;
        res=min(res, cost);
    }
    if(N == 1) res=1;
    cout << res << endl;
    return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int n;
   cin >> n;
   map<char, int> m;
   rep (i, n) {
      char c;
      cin >> c;
      m[c]++;
   }
   if (m.size() == 4) {
      puts("Four");
   } else {
      puts("Three");
   }

   return 0;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
WA, AC = "WA", "AC"

ac = [0] * (N+1)
wa = [0] * (N+1)

for i in range(1, M+1):
  p, S = input().split()
  p = int(p)
  if S == WA and ac[p] == 0:
    wa[p] += 1
  elif S == AC and ac[p] == 0:
    ac[p] = 1

wa = [v*ac[i] for i,v in enumerate(wa)]
    
print(sum(ac), sum(wa))

Measured memory_bytes: 5552
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Scan()
	var s1, _ = strconv.Atoi(stdin.Text())
	var hours = int(s1 / (60 * 60))
	var s2 = s1 % (60 * 60)
	var minutes = s2 / 60
	var seconds = s2 % 60
	fmt.Printf("%d:%d:%d\n", hours, minutes, seconds)
}



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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


ll nextInt() { ll x; cin >> x; return x;}

int main2() {
  ll N = nextInt();
  for (ll a = 1; a <= 3500; a++) {
    for (ll b = 1; b <= 3500; b++) {
      ll p = N * a * b;
      ll q = 4*a*b -N*a-N*b;
      if (q <= 0) continue;
      if (p % q == 0) {
        ll c = p / q;
        cout << a << " " << b << " " << c << endl;
        return 0;
      }
    }
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 256
import math
N,M=map(int,input().split())
reg=10**9+7

#犬と猿が隣合わない並び方*Nの階乗*Mの階乗(並べ方を順列で表現）
#入力例1
#犬と猿の数が同じ場合
#犬猿犬猿,猿犬猿犬の２通り*2の階乗*2の階乗
#どちらかが１匹多い場合
#入力例2
#犬猿犬猿犬の1通り*3の階乗*2の階乗

#ここでどちらか一方の数が他方より２以上多い場合を考えると題を満たす並べ方はない

if abs(N-M)>=2:
  print(0)
  exit()
fact=((math.factorial(N)%reg)*(math.factorial(M)%reg))%reg
if abs(N-M)==1:
  print(fact)
else:
  print((2*fact)%reg)

Measured memory_bytes: 4096
from collections import deque

N, Q = map(int, input().split())

adj = {}
val = [0 for i in range(N+1)]
ans = [0 for i in range(N+1)]
check = [False for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    if a not in adj:
        adj[a] = []
    if b not in adj:
        adj[b] = []
    adj[a].append(b)
    adj[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    val[p] += x

queue = deque([(1,0)])

while len(queue):
    q, c = queue.pop()
    check[q]=True
    ans[q] = val[q] + c
    for nq in adj[q]:
        if check[nq] == False:
            queue.append((nq,ans[q]))
print(*ans[1::])

Measured memory_bytes: 79068
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;   
const int inf = (int) 1e9+7;
pair<int,int> p[100003];
int n,m;
int v[100003];
bool f(pair<int,int> x,pair<int,int> y){
	return(x.second>y.second);
}
int ok(int x){
	if(x < 0)return -1;
	if(v[x] == x)return x;
	return v[x]=ok(v[x]);
}
int main(){
	fastIO;      
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>p[i].first>>p[i].second;
	}	  
	for(int i=0;i<m;i++)v[i]=i;
	sort(p,p+n,f);
	long long ans=0;
	for(int i=0;i<n;i++){       
		int q=ok(m-p[i].first);
		//cout<<p[i].first<<'\n';
		if(q != -1){
			ans+=p[i].second;
			v[q]=q-1;
		}
		//for(int i=0;i<m;i++)cout<<v[i]<<" ";
		//cout<<'\n';	
	}
	cout<<ans<<'\n';
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d.at(i);
  int sum = 0;
  rep(i, n) {
    for(int j = i + 1; j < n; j++) sum += d.at(i) * d.at(j);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

n,x=MI()
lis=LI()
for i in range(n):
    lis[i]=abs(lis[i]-x)
if n==1:
    print(lis[0])
    sys.exit()
a=lis[0]
b=lis[1]
for i in range(2,n):
    a=gcd(a,b)
    b=lis[i]
print(gcd(a,b))

Measured memory_bytes: 58736
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair((first), (second)))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int N;
	cin >> N;
	vector<ll> A(N + 1), B(N);
	for(int i = 0; i <= N; i++)cin >> A[i];
	for(int i = 0; i < N; i++)cin >> B[i];
	ll ans = 0;
	for(int i = 0; i < N; i ++){
		if(A[i] <= B[i]){
			B[i] -= A[i];
			ans += A[i];
			A[i] = 0;
		}
		else{
			A[i] -= B[i];
			ans += B[i];
			B[i] = 0;
		}
		if(A[i + 1] <= B[i]){
			B[i] -= A[i + 1];
			ans += A[i + 1];
			A[i + 1] = 0;
		}
		else{
			A[i + 1] -= B[i];
			ans += B[i];
			B[i] = 0;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
n,m = map(int,input().split())
city = []
for i in range(n):
    city.append([])

for i in range(1,m+1):
    a,b = map(int,input().split())
    city[a-1].append(b)
    city[b-1].append(a)

for r in city:
    print (len(r))


Measured memory_bytes: 2940
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
print((n+1)//2)


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

int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    rep(i, d){
        vector<int> s(26);
        rep(i, 26) cin >> s[i];
        int t;
        t = 2;
        cout << t << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
#include <math.h>
#include <iomanip>
#include <limits>

using namespace std;
using ll = long long;
const ll res = 1000000007;

int main() {
	ll x;
	cin >> x;
	cout << x / 500 * 1000 + x % 500 / 5 * 5 << endl;
}


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

int main() {

  int h, w;

  while(1) {

    cin >> h >> w;

    if(h==0 && w==0) {

      break;
      
    }

    for(int i=0; i<h; i++) {

      for(int j=0; j<w; j++) {

        cout << "#";

        if(j==w-1) {

          cout << endl;
          
        }
        
      }

      if(i==h-1) {

        cout << endl;
        
      }
        
    }
      
  }

  return 0;
  
}


Measured memory_bytes: 3128
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int P = sc.nextInt();

		int ans = (3 * A + P) / 2;

		System.out.println(ans);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 21076
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <queue> 
using namespace std;
int main(){
    int n;
    cin >> n;
    int count=0;
    vector<queue<int>> vec(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            int N;
            scanf("%d", &N);
            N--;
            vec[i].push(N);
        }
    }
   // cout<<vec[1].front()<<endl;
   bool kuzu=false;
    while(1){
        bool h=true;
        vector<bool> bl(n,true); 
        for(int i=0;i<n;i++){
            if(vec[i].empty()){
                continue;
            }
            int a = vec[i].front();
            if(bl[i]==false){
                continue;
            }
            if(bl[a]==false){
                continue;
            }
          //  cout<<a<<endl;
         //   cout<<"入った"<<endl;
            
            if(vec[a].front()==i){
                //cout<<"入った"<<endl;
                vec[i].pop();
                vec[a].pop();
                h=false;
                bl[i]=false;
                bl[a]=false;
             //   cout<<"i"<<i+1<<"a"<<a+1<<endl;
            }
        }
        if(h){
            break;
        }
        count++;
        if(count==20000){
            kuzu=true;
            break;
        }
    }
    bool ha=true;
    for(int i=0;i<n;i++){
        if(!vec[i].empty()){
            ha=false;
            break;
        }
    }
    if(kuzu)cout<<499500<<endl;
    else if(ha){
        cout<<count<<endl;
    }
    else{
        cout<<-1<<endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    string s;cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]=='1') s[i]='9';
        else if(s[i]=='9') s[i]='1';
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
typedef long long ll;
int main() {
	int N, Q;
	cin >> N >> Q;
	dsu d(N);
	for (int i = 0; i < Q; ++ i) {
		int t, u, v;
		cin >> t >> u >> v;
		if (t == 0) {
			d.merge(u, v);
		} else {
			cout << (d.same(u, v) ? 1 : 0) << endl;
		}
	}
}


Measured memory_bytes: 3996
import sys
readline = sys.stdin.buffer.readline

s = readline().rstrip().decode('utf-8')

class Judge():
    def __init__(self,s):
        self.s = s
        self.vowel = ["a","i","u","e","o"]
    def __call__(self):
        if self.s in self.vowel:
            print("vowel")
        else:
            print("consonant")

Judge(s)()


Measured memory_bytes: 38256
#include <iostream>

using namespace std;

int _GCD(int a, int b);
int _LCM(int a, int b);

int main()
{
	int a, b;
	
	while (cin >> a >> b) {
		cout << _GCD(a, b) << " " << _LCM(a, b) << endl;
	}
	
	return 0;
}

int _GCD(int a, int b) {
	int r;
	
	if (a < b) {
		r = a; a = b; b = r;
	}
	
	do {
		r = a % b;
		a = b;
		b = r;
	} while (r != 0);
	
	return a;
}

int _LCM(int a, int b)
{
	return (a / _GCD(a, b)) * b;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	int sum=0;
	for(int i=0;i<k;i++)
	{
		sum+=a[i];
	}
	cout<<sum;
	
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int m1, m2, d;
    cin >> m1 >> d >> m2 >> d;
    cout << (m1 != m2) << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF (1<<29)

int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
struct Rational{
	int x,y;
	Rational(){}
	Rational(int x,int y){
		int z = gcd(x,y);
		this->x=x/z;
		this->y=y/z;
	}
	Rational inverse()const{
		return Rational(y,x);
	}
	Rational operator * (Rational a)const{
		return Rational(x*a.x,y*a.y);
	}
	Rational operator + (Rational a)const{
		int z = gcd(y,a.y);
		return Rational(a.y/z*x+y/z*a.x, y/z*a.y);
	}
	Rational operator / (Rational a)const{
		return (*this)*a.inverse();
	}
	bool operator == (Rational a)const{return x*a.y == a.x*y;}
	bool operator != (Rational a)const{return !((*this)==a);}
	bool operator < (Rational a)const{return x*a.y < a.x*y;}
	bool operator > (Rational a)const{return x*a.y > a.x*y;}
};

int p,q,a,n;
Rational pq;
int dfs(Rational c,int seki,int m,int d){
	if(c==pq){
		return 1;
	}
	if(pq<c)return 0;
	int res=0;
	if(d==0)return 0;
	for(;m*seki<=a;m++){
		if(c+Rational(d,m) < pq)break;
		res += dfs(Rational(1,m)+c,seki*m,m,d-1);
	}
	return res;
}
int main(){
	while(cin>>p>>q>>a>>n,p|q|a|n){
		pq = Rational(p,q);
		cout<<dfs(Rational(0,1),1,1,n)<<endl;
	}
	return 0;
}

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

const int maxn=2e5+5;
vector<int>edg[maxn];
int dfn[maxn],dfnn[maxn],cnt;
void dfs(int nw,int fa)
{
	dfn[nw]=++cnt;
	for(int v:edg[nw])
		if(v!=fa)
			dfs(v,nw);
	dfnn[nw]=cnt;
}
int bit[maxn];
void ad(int x,int v)
{
	for(;x<=cnt+1;x+=x&-x)
		bit[x]+=v;
}
int su(int x)
{
	int re=0;
	for(;x;x-=x&-x)
		re+=bit[x];
	return re;
}
int main()
{
	int n,q,a,b,p,x;
	scanf("%d%d",&n,&q);
	for(int i=1;i<n;i++){
		scanf("%d%d",&a,&b);
		edg[a].push_back(b);
		edg[b].push_back(a);
	}
	dfs(1,0);
	while(q--){
		scanf("%d%d",&p,&x);
		ad(dfn[p],x);
		ad(dfnn[p]+1,-x);
	}
	for(int i=1;i<=n;i++)
		printf("%d ",su(dfn[i]));
	return 0;
}

Measured memory_bytes: 24832