akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void){
    int n,i;
    long int sum=0;
    scanf("%d",&n);
    int M[n+1],H[n];
    for(i=0;i<n+1;i++){
        scanf("%d",&M[i]);
    }
    for(i=0;i<n;i++){
        scanf("%d",&H[i]);
    }
    for(i=0;i<n;i++){
        if(M[i]<H[i]){
            sum+=M[i];
            H[i]-=M[i];
            if(H[i]<M[i+1]){
                sum+=H[i];
                M[i+1]-=H[i];
            }else{
                sum+=M[i+1];
                M[i+1]=0;
            }
        }else{
            sum+=H[i];
        }
    }

    printf("%ld\n",sum);
    return 0;
}





Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        for (int j = i + 1; j < s.size(); j++) {
            if (s[i] > s[j]) {
                char k = s[j];
                s[j] = s[i];
                s[i] = k;
            }
        }
    }
    for (int i = 0; i < t.size(); i++) {
        for (int j = i + 1; j < t.size(); j++) {
            if (t[i] < t[j]) {
                char l = t[j];
                t[j] = t[i];
                t[i] = l;
            }
        }
    }
    int w = 0;
    while (true) {
        if (s.size() == w && t.size() == w) {
            cout << "No" << endl;
            break;
        } else if (s.size() == w) {
            cout << "Yes" << endl;
            break;
        } else if (t.size() == w) {
            cout << "No" << endl;
            break;
        } else if (s[w] < t[w]) {
            cout << "Yes" << endl;
            break;
        } else if (s[w] > t[w]) {
            cout << "No" << endl;
            break;
        }
        w++;
    }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int[] simen=new int[1000];
	static int[] kisu_simen=new int[48];
	static int INF=1000000007;
	public static void main(String[] args) {
		for(int i=0; i<200; i++) {
			int tmp=(i+1)*(i+2)*(i+3)/6;
			for(int j=0; j<5; j++) {
				simen[i*5+j]=tmp;
			}
		}
		int num=0;
		int counter=0;
		while(true) {
			if(counter>=47) {
				break;
			}
			else {
				if(num*(num+1)*(num+2)/6%2==1) {
					kisu_simen[counter]=num*(num+1)*(num+2)/6;
					counter++;
				}
			}
			num++;
		}
		int[] pollock=new int[1000002];
		int[] pollock_k=new int[1000002];
		Arrays.fill(pollock,INF);
		Arrays.fill(pollock_k,INF);
		pollock[0]=0;
		pollock_k[0]=0;
		int sum=0;
		for(int i=0; i<1000; i++) {
			for(int j=0; j<=Math.min(sum,1000001); j++) {
				if(pollock[j]<INF) {
					if(j+simen[i]<=1000000) {
						pollock[j+simen[i]]=Math.min(pollock[j+simen[i]], pollock[j]+1);
					}
				}
			}
			sum+=simen[i];
		}
		for(int i=0; i<48; i++) {
			for(int j=0; j<=1000000; j++) {
				if(j-kisu_simen[i]>=0) {
					pollock_k[j]=Math.min(pollock_k[j], pollock_k[j-kisu_simen[i]]+1);
				}
			}
		}
		Scanner sc = new Scanner(System.in);
		while(true) {
			int input=sc.nextInt();
			if(input==0) {
				System.exit(0);
			}
			else {
				System.out.println(pollock[input]+" "+pollock_k[input]);
			}
		}
	}
}


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

int main(){
  string s,t;int i,a=0;cin>>s>>t;
  for(i=0;i<s.size();i++){
    if(s==t) a=1;
    s=s.back()+s.substr(0,s.size()-1);
  }
  cout<<(a?"Yes":"No");
}

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

using namespace std;

template <class T>
using lim = numeric_limits<T>;

typedef long long ll;
typedef long double ld;

const int maxN = 500;
const int maxC = 30;

int D[maxC+1][maxC+1];
int counters[3][maxC+1];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	memset(D, 0, sizeof D);
	memset(counters, 0, sizeof counters);
	
	int n, c; cin >> n >> c;
	
	for (int i = 1; i <= c; i++){
		for (int j = 1; j <= c; j++){
			cin >> D[i][j];
		}
	}
	
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			int temp; cin >> temp;
			counters[(i+j)%3][temp]++;
		}
	} 
	
	int smol = lim<int>::max();
	for (int i = 0; i < c; i++){
		for (int j = 0; j < c; j++){
			if (i == j) continue;
			for (int k = 0; k < c; k++){
				if (i == k || j == k) continue;
				int total = 0;
				for (int l = 0; l < c; l++) total += D[l+1][i+1]*counters[0][l+1];
				for (int l = 0; l < c; l++) total += D[l+1][j+1]*counters[1][l+1];
				for (int l = 0; l < c; l++) total += D[l+1][k+1]*counters[2][l+1];
				smol = min(smol,total);
			}
		}
	}
	
	cout << smol << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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 S, W;
  cin >> S >> W;
  cout << (W<S?"safe":"unsafe") << endl;
}

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

int main(){
  string s, t, ans="Yes";
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if(t<=s) ans = "No";

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;
inline int rd(){
    int x=0,p=1;
    char a=getchar();
    while((a<48||a>57)&&a!='-')a=getchar();
    if(a=='-')p=-p,a=getchar();
    while(a>47&&a<58)x=(x<<1)+(x<<3)+(a&15),a=getchar();
    return x*p;
}
const int N=102;
int n,k;
int vis[N];
int ans=0;
int main(){
	n=rd(),k=rd();
	for(int i=1;i<=k;i++){
		int x=rd();
		while(x--)vis[rd()]=1;
	}
	for(int i=1;i<=n;i++)ans+=(!vis[i]);
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1596
n = int(input())
v = list(map(int,input().split()))
ecost = [n//2 for _ in range(100001)]
ocost = [n//2 for _ in range(100001)]
for i in range(n):
    if i%2 == 0:
        ecost[v[i]] -= 1
    else:
        ocost[v[i]] -= 1
e1 = ecost[1]
ve1 = 1
e2 = ecost[2]
ve2 = 2
o1 = ocost[1]
vo1 = 1
o2 = ocost[2]
vo2 = 2
for i in range(3,100001):
    ecand = ecost[i]
    ocand = ocost[i]
    if ecand <= e1:
        e2 = e1
        e1 = ecand
        ve2 = ve1
        ve1 = i
    elif ecand <= e2:
        e2 = ecand
        ve2 = i
    if ocand <= o1:
        o2 = o1
        o1 = ocand
        vo2 = vo1
        vo1 = i
    elif ocand <= o2:
        o2 = ocand
        vo2 = i
if vo1 != ve1:
    ans = o1 + e1
else:
    ans = e1 + min(o2,e2)
print(ans)
        



Measured memory_bytes: 15528
def myAnswer(N:int,M:int,S:list,C:list)-> int:
   ans=-1
   for i in range(10**N):
      if(len(str(i)) == N):
          for s,c in zip(S,C):
              tmp=list(str(i))
              if(tmp[s-1] != str(c)):
                  break
          else:
              if(ans == -1):
                  ans=i
              else:
                ans=min(ans,i)
   return ans
def modelAnswer():
   return
def main():
   N,M = map(int,input().split())
   S= []
   C = []
   for _ in range(M):
      s,c =map(int,input().split())
      S.append(s)
      C.append(c)
   print(myAnswer(N,M,S[:],C[:]))

if __name__ == '__main__':
   main()




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

int main() {
  int X,Y;
  cin >> X>>Y;
  if(Y%2!=0){
    cout<<"No"<<endl;
  }
  else if(X*2>Y){
    cout<<"No"<<endl;
  }
  else if(X*4<Y){
    cout<<"No"<<endl;
  }
  else if(X*2==Y){
    cout<<"Yes"<<endl;
  }
  else if(X*4==Y){
    cout<<"Yes"<<endl;
  }
  else {
    int A=X/2;
    if(A-X<X){
      cout<<"Yes"<<endl;
    }
    else {
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1e6 + 100;
int n; double d;
void work() {
	cin >> n >> d;

	double x, y;
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		scanf("%lf %lf", &x, &y);
	//	cout << sqrt(x*x+y*y) << endl;
		if(d >= sqrt(x*x+y*y)) {
			
			ans++;
		}
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 3256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int n,arr[100005],totalgenap,totalganjil,yangganjil;
bool ans=true;
int FPB(int a,int b)
{
	if(b==0)
		return a;
	else
		return FPB(b,a%b);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	while(true)
	{
		totalgenap=0;
		totalganjil=0;
		for(int i=1;i<=n;i++)
		{
			if(arr[i]%2==0)
				totalgenap++;
			else
				totalganjil++,yangganjil=i;
		}
		if(totalgenap%2==1)
		{
			//ans=ans&&true;		//tergantung turnya siapa
			break;
		}
		else		//if(totalgenap%2==0)
		{
			if(totalganjil>=2||(totalganjil==1&&arr[yangganjil]==1))
			{
				ans=ans^true;
				break;
			}
			arr[yangganjil]--;
			int fpb;
			fpb=arr[1];
			for(int i=2;i<=n;i++)
				fpb=FPB(fpb,arr[i]);
			for(int i=1;i<=n;i++)
				arr[i]/=fpb;
			ans=ans^true;
		}
	}
	if(ans)
		printf("First\n");
	else
		printf("Second\n");
}

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

const int MAXN = 2e5 + 10;
int n, a[MAXN], b[MAXN];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i], b[i] = a[i];
	sort(a, a + n);
	int f = a[n / 2 - 1], s = a[n / 2];
	for (int i = 0; i < n; i++) {
		if (b[i] <= f)
			cout << s;
		else
			cout << f;
		cout << '\n';
	}
}

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

using namespace std;

int main(void) {
	char s;
	cin >> s;
	if (97 <= s && s <= 122) {
		printf("a");
	}
	else
		printf("A");
}


Measured memory_bytes: 3632
H, W = map(int, input().split())

if H%3 == 0 or W%3 == 0:
    print (0)
elif H == W:
    if H%2 == 0:
        print (H//2)
    else:
        print (H-((2 * H)//6 - H//6))
else:
    if H%2 == 0 and W%2 == 0:
        print (min(H//2, W//2))
    else:
        if H%2 == 0:
            print (min(H//2, H, W))
        elif W%2 == 0:
            print (min(W//2, H, W))
        else:
            print (min(H, W))


Measured memory_bytes: 3064
s = input()
a = int(len(s))
if a == 1:
  print(int(s[0]))
elif a == 2:
  print(9)
elif a == 3:
  print(10+int(s)-100)
elif a == 4:
  print(909)
elif a == 5:
  print(910+int(s)-10000)
elif a == 6:
  print(90909)

Measured memory_bytes: 3060
N, M = map(int, input().split())
iPY = []
 
for i in range(M):
    p, y = map(int, input().split())
    iPY.append([i, p, y])
 
city_count = {}
order = {}
 
for i, p, y in sorted(iPY, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 0
    city_count[p] += 1
    order[p, i] = city_count[p]
    
for i, p, y in iPY:
    print('{:06}{:06}'.format(p, order[p, i]))

Measured memory_bytes: 44484
//Daniel Grzegorzewski
#include <bits/stdc++.h>

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

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

int main()
{
	init_ios();
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) {
		cout<<0<<"\n";
		return 0;
	}
	int res = 0;
	bool fl1 = false, fl2 = false;
	if (a%2 == 0 || b%2 == 0 || c%2 == 0)
		fl1 = true;
	if (a%2 == 1 || b%2 == 1 || c%2 == 1)
		fl2 = true;
	if (fl1 && fl2) {
		res = 1;
		if (a%2 == 0) {
			if (b%2 == 0) {
				++a;
				++b;
			}
			else if (c%2 == 0) {
				++a;
				++c;
			}
			else {
				++b;
				++c;
			}
		}
		else {
			if (b%2 == 1) {
				++a;
				++b;
			}
			else if (c%2 == 1) {
				++a;
				++c;
			}
			else {
				++b;
				++c;
			}
		}
	}
	if (a > b)
		swap(a, b);
	if (b > c)
		swap(b, c);
	while (a < c) {
		++res;
		a += 2;
	}
	while (b < c) {
		++res;
		b += 2;
	}
	cout<<res<<"\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
long long n,k,tot;
long long a[201010],b[201010],f[201010];
long long cmp(long long a,long long b)
{
	return a>b;
}
bool check(long long x)
{
	long long p=0;
	for(int i=1;i<=n;i++)
		b[i]=x/f[i];
	for(int i=1;i<=n;i++)
		p+=max(0ll,a[i]-b[i]);
	if(p<=k)
		return true;
	return false;
}
int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		tot+=a[i];
	}
	for(int i=1;i<=n;i++)
		scanf("%lld",&f[i]);
	if(tot<=k)
	{
		printf("0");
		return 0;
	}
	sort(a+1,a+n+1);
	sort(f+1,f+n+1,cmp);
	long long l=1,r=1e12,mid;
	while(l<r)
	{
		mid=(l+r)>>1;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
	}
	printf("%lld",l);
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <string>

using namespace std;

int main() {
    int N;
    cin >> N;

    int ans = 0;
    for(int i = 1; i <= N; ++i)
        if(to_string(i).size()%2 == 1)
            ++ans;

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
/*
[abc100] C - *3 or /2
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 10000;

int N;
int a[MAX_N];

ll solve() {
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int b = a[i]; b > 0 && b % 2 == 0; b /= 2) {
            ans++;
        }
    }
    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int A[1000000],n;
int binarySearch(int key){
  int left=0;
  int right=n;
  int mid;
  while(left<right){
    mid=(left + right)/2;
    if(key==A[mid])return 1;
    else if(key > A[mid])left = mid + 1;
    else if(key < A[mid])right = mid;
  }
  return 0;
}
int main(){
  int i,q,k,sum = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&k);
    if(binarySearch(k))sum++;
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int x; std::cin >> x;
  int sum = 0;
  rep(i,1,x+1) {
    sum += i;
    if (x <= sum) {
      std::cout << i << std::endl;
      return 0;
    }
  }
  assert(false);
  return 0;
}

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

template <class... Args>
void gin(Args&&... args) { (cin >> ... >> args); }
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
#define int long long

void solve(){
 int n; gin(n);
 int cnt = 1e6+10;
 int rem = 0,ans = 0;
 while(cnt--){
 	rem = (rem * 10 + 7)%n;
 	ans ++;
 	if(!rem){cout << ans ;return;}
 }
 cout <<"-1\n";

}
int32_t main()
{
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   // int tst; cin >> tst; while(tst--)
   {
   	solve();
   }
}

Measured memory_bytes: 3688
import java.util.Scanner;

//Lagrange's Four-Square Theorem
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			int c = 0;
			for(int i=0;i<=n;i++){
				if(n<i*i)break;
				for(int j=i;j<=n;j++){
					if(n<i*i+j*j)break;
					for(int k=j;k<=n;k++){
						if(n<i*i+j*j+k*k)break;
						for(int l=k;l<=n;l++){
							if(n<i*i+j*j+k*k+l*l)break;
							c+=i*i+j*j+k*k+l*l==n?1:0;
						}
					}
				}
			}
			System.out.println(c);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String ans = "Christmas";
		for(int i = 25; i > n; i--) {
			ans = ans +" Eve";
		}
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using pint = pair<int, int>;
using pll = pair<ll,ll>;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    cin.tie(0);
    int n,h;
    cin >> n >> h;
    vector<int>b(n+1,0);
    int cut_max=0,a;
    REP(i,n){
        cin >> a >> b[i];
        cut_max = max(a,cut_max);
    }
    sort(b.begin(),b.end(),greater<>());
    int index=0,count=0;
    while(h>0){
        if(cut_max<b[index]){
            h-=b[index];
            index++;
            count++;
        }
        else{
            count += (h+cut_max-1)/cut_max;
            break;
        }
    }
    COUT(count);
    return 0;
}  

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	ll n;
	cin >> n;
	
	for(ll h = 1; h <= 3500; ++h) {
		for(ll t = 1; t <= 3500; ++t) {
			ll x = n * h * t;
			ll y = 4 * h * t - n * t - n * h;
			
			if( y != 0 && x % y == 0 && x / y > 0 ) {
				cout << h << " " << t << " " << x / y << endl;
				return 0;
			}
		}			
	}
	
	return 0;
}


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

int main(){
	string s, t;

	cin >> s >> t;


	bool a = false;

if(s.size()<t.size()){
	cout << "UNRESTORABLE" << endl;
}else{

	for (int i = s.size() - t.size(); i >= 0 ; i--)
	{
		bool q = true;

		for (int j = t.size()-1; j >=0; j--){
			bool b = false;
			if (s[i+j] == t[j] || s[i+j] == '?')
			{
				b = true;
			}
			q &=b;
		}

		if(q){
			for (int j = t.size() - 1; j >= 0; j--)
			{
				s[i + j] = t[j];
			}
			a = true;
			break;
		}
	}

	if(a){
		for (int i = 0; i < s.size(); i++){
			if(s[i]=='?')
				s[i] = 'a';
		}

		cout << s << endl;
	}else{
		cout << "UNRESTORABLE" << endl;
	}
}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int k,n;
  int ans = 0;
  scanf("%d %d",&k,&n);
  
  int a[n];
  
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  int max = 0;
  int j=0;
  for(int i=0;i<n-1;i++){
    if((a[i+1]-a[i])>max){
      max=a[i+1]-a[i];
      j=i;
    }
  }
  
  ans = a[j]+k-a[j+1];
    if((k-a[n-1]+a[0])>max){
      max = k-a[n-1];
      j=n-1;
      ans=a[n-1]-a[0];
    }
    
    

    printf("%d",ans);
}
    
    
    

Measured memory_bytes: 896
using System;
using System.Collections.Generic;

namespace Atc_0020
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            var T = Console.ReadLine();

            ulong result = 0;

            for (int i = 0; i < S.Length; i++)
            {
                if (S.Substring(i, 1) != T.Substring(i, 1))
                {
                    result++;
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 36832
I = lambda: map(int, input().split())
n, m = I()
A = [list(I()) for _ in range(m)][1:]
B = [-1]*(n+1)
c = n*(n-1)//2
C = [c]
f = lambda x: x if B[x] < 0 else f(B[x])

for a, b in A[::-1]:
    a, b = sorted([f(a), f(b)])    
    if a != b:
        c -= B[a]*B[b]
        B[a] += B[b]
        B[b] = a
    C += c,
print(*C[::-1])


Measured memory_bytes: 35544
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b-1); i>=(a); i--)
#define de(x) cout << #x << " => " << x << endl
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

typedef long long ll;
typedef long double ld;

const int N = 1e2 + 7;
char tab[N][N];
int n, m;
///----------------------------------------------
char solve(int x, int y) {
	if (tab[x][y] == '#') return '#';
	int dx[] = {-1, 0, 1};
	int dy[] = {-1, 0, 1};
	int ret = 0;
	rep(i, 0, 3) rep(j, 0, 3) ret += tab[x + dx[i]][y + dy[j]] == '#';
	return ret + '0';
}
int main() {

	scanf("%d%d", &n, &m);
	rep(i, 0, n) scanf(" %s", tab[i]);
	rep(i, 0, n) rep(j, 0, m) { printf("%c", solve(i, j)); if (j == m - 1) puts(""); }
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,k,l,m;
    cin>>n;
    j=-10000;
    l=1000000;
    for(i=0;i<n;i++)
    {
        cin>>k;
        if(k>j)
        {
            j=k;
        }
        if(k<l)
        {
            l=k;
        }
    }
    cout<<abs(j-l)<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: str):
    f={"SUN":7,"MON":6,"TUE":5,"WED":4,"THU":3,"FRI":2,"SAT":1}
    print(f[S])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<stdio.h>
int main(){
  int n,a,b,i,j;
  long long s=0,c[20][20]={};
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    a=b=i%10;
    for(j=i;j;j/=10)b=j%10;
    c[a][b]++;
  }
  for(i=0;i<10;i++){
    for(j=0;j<10;j++)s+=c[i][j]*c[j][i];
  }
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

#define MAX 100001

int main() {
  int n,k;
  int count = 0;
  int a[MAX] = {};

  scanf("%d%d", &n, &k);

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

  for(int i = 1; ; i += (k-1)){
    if(i >= n) break;
    count++;
  }

  printf("%d", count);

  return 0;

}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/
/*Calculate GCD, LCM =============================*/
long long GCD(long long a, long long b){
    return (b ? GCD(b, a%b) : a);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a,b);
    return (a/g) * (b/g) * g;  // オーバーフローを避ける
}


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    string s,t;
    char ch;
    i32 n,m,p,q,r;
    cin >> n;

    i32 ans = 0;
    rep1(i,n)rep1(j,n)rep1(k,n) {
        ans += GCD(GCD(i, j), k);
    }
    cout << ans << '\n';

   
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N = 60;
const int INF = 1e9;
int n;
int a[N], b[N];

inline int cal(int x, int y)
{
	if (x < y) swap(x, y);
	int d = x-y;
	return min(d, 24-d);
}

inline bool check(int x)
{
	int mi = INF;
	b[0] = 0;
	for (int i = 1; i <= n; i ++){
		b[i] = a[i];
		for (int j = 0; j < i; j ++){
			if (cal(a[i], b[j]) < x){
				b[i] = 24-a[i];
				break;
			}
		}
	}
	sort(b, b+1+n);
	for (int i = 1; i <= n; i ++)
		for (int j = 0; j < i; j ++){
			mi = min(mi, cal(b[i], b[j]));
		}
	if (mi >= x) return true;
	
	mi = INF;
	b[0] = 24;
	for (int i = 1; i <= n; i ++){
		b[i] = a[i];
		for (int j = 0; j < i; j ++){
			if (cal(a[i], b[j]) < x){
				b[i] = 24-a[i];
				break;
			}
		}
	}
	sort(b, b+1+n);
	for (int i = 1; i <= n; i ++)
		for (int j = 0; j < i; j ++){
			mi = min(mi, cal(b[i], b[j]));
		}
	return mi >= x;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++){
		scanf("%d", &a[i]);
	}
	sort(a, a+1+n);
	for (int i = 12; i >= 0; i --){
		if (check(i)){
			printf("%d\n", i);
			return 0;
		}
	}
}

Measured memory_bytes: 384
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
used=[0]*n
ans=[]
for _ in range(n):
    for i in range(len(A)-1,-1,-1):
        if A[i]==i+1:
            ans.append(i+1); count += 1
            # print(A,i+1)
            del A[i]
            break
ans.reverse()
# print(ans)
print(*ans if count == n else [-1],sep="\n")


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

int main(){
	int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int v;
	cin >> v;
  		cout << a[v-1] << endl;
		return 0;
}


Measured memory_bytes: 256
import java.util.*;

/**
 * Created by mizuk on 2017/07/26.
 */
public class Main {

    private static int N;
    private static ArrayList<Integer> arrayList = new ArrayList<>();

    public static void input(){
        Scanner scan = new Scanner(System.in);
        N = scan.nextInt();

        for(int i=0;i<N;i++) {
            arrayList.add(scan.nextInt());
        }
    }

    public static void main(String args[]){
        //入力
        input();

        ArrayList<Integer> b = new ArrayList<>();

        if(N % 2 == 0){
            for (int i=N-1;i>=0;i-=2) b.add(arrayList.get(i));
            for (int i=0;i<N;i+=2) b.add(arrayList.get(i));
        } else {
            for (int i=N-1;i>=0;i-=2) b.add(arrayList.get(i));
            for (int i=1;i<N;i+=2) b.add(arrayList.get(i));
        }

        // 出力
        for (int i=0;i<N;i++){
            System.out.print(b.get(i) + " ");
        }
    }
}


Measured memory_bytes: 97220
#include<bits/stdc++.h>
#define INP (a<<50)
using namespace std;
int main()
{
    long long int a,b,c=0,i,j,su=0;
    cin>>a>>b;
    long long int s[a+5],ss[a+5];
    for(i=1; i<=a; i++)
    {
        cin>>s[i]>>ss[i];
        su+=ss[i];
    }
    long long int sss[a+5][su+5];
    for(i=0; i<=a; i++)
    {
        for(j=0; j<=su; j++)
        {
            sss[i][j]=INP;
        }
    }
    for(i=0; i<=a; i++)
        sss[i][0]=0;
    for(i=1; i<=a; i++)
    {
        for(j=1; j<=su; j++)
        {
            if(ss[i]<=j)
            {
                sss[i][j]=min(sss[i-1][j],sss[i-1][j-ss[i]]+s[i]);
            }
            else
                sss[i][j]=sss[i-1][j];
        }
    }
    for(i=1; i<=su; i++)
    {
        if(sss[a][i]<=b)
            c=i;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 80768
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()

{
	ll n,re=0,bl=0,gr=0,res,wr,i,j,k;
	string s;
	scanf("%lld",&n);
	getchar();
	getline(cin,s);
	for(i=0;i<n;i++)
	{
		if(s[i]=='R')re++;
		if(s[i]=='G')gr++;
		if(s[i]=='B')bl++;
	}
res=re*gr*bl;
wr=0;
for(i=1;i<=n-2;i++)
{
	for(j=i+1;j<=n-1;j++)
	{
		//j-i=k-j
		k=2*j-i;
	  if( k<= n){
                if(s[i-1] != s[j-1] && s[k-1] != s[j-1] && s[i-1] != s[k-1]){
                	wr++;
			}
	}
}
}
	printf("%lld\n",res-wr);
}

Measured memory_bytes: 3788
#include <stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d ",&W,&H,&x,&y,&r);
  if(x-r >= 0 && x+r <= W && y-r >= 0 && y+r <= H){printf("Yes\n");}
  else {printf("No\n");}
  return 0;
}

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

using pi = pair<int, int>;
using frac = pair<lint, lint>;
const int MAXN = 1000005;

string s;
int r[MAXN];

int main(){
	cin >> s;
	int n= s.size();
	for(int i=0; i<n; i++){
		if(s[i] == '<'){
			r[i + 1] = max(r[i + 1], r[i] + 1);
		}
	}
	for(int i=n-1; i>=0; i--){
		if(s[i] == '>'){
			r[i] = max(r[i], r[i + 1] + 1);
		}
	}
	cout << accumulate(r, r + n + 1, 0ll) << endl;
}


Measured memory_bytes: 2820
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    forn(i, n + 1) {
        string u = string(s.begin(), s.begin() + i) + t;
        if (string(u.begin(), u.begin() + n) == s) {
            cout << u.size() << '\n';
            break;
        }
    }

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
eval"N,K,*A="+`dd`.split*?,
s=eval A*?+
1.upto(3e4){|j|s%j<1&&$*<<j<<s/j}
p$*.reject{|h|t=0
A.map{|x|x%h}.sort.map{|x|K<t+=x}[~t/h]}.max

Measured memory_bytes: 16384
require 'pp'

MOD = 10 ** 9 + 7
n = gets.to_i

if n == 1
    puts 0
    exit 0
elsif n == 2
    puts 2
    exit 0
end


n10 = 1
n9 = 1
n8 = 1
n.times do |i|
    n10 = (n10 * 10) % MOD
    n9 = (n9 * 9) % MOD
    n8 = (n8 * 8) % MOD
end

puts (n10 - (((2 * n9) % MOD - n8) % MOD)) % MOD


Measured memory_bytes: 14528
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
vector<vector<int> >vvi(10);
int n,m;
int ans=0;
void dfs(int now,int bit,int depth){
  if(depth==n){
    ans++;
    return;
  }
  for(int i=0;i<vvi[now].size();i++){
    if((bit&(1<<vvi[now][i]))==0){
      dfs(vvi[now][i],bit+(1<<vvi[now][i]),depth+1);
    }
  }
}
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int a,b;cin>>a>>b;
    vvi[a].pb(b);
    vvi[b].pb(a);
  }
  dfs(1,2,1);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N = input()
i = 1
total = 0
digits = [i for i in range(len(N)) if i != 0 and i % 2 != 0]

if len(N) % 2 != 0:
    total = int(N) - int(str(1) + (len(N)-1)*"0") + 1
    for digit in digits:
        total += int("9"*digit) - int("1"+"0"*(digit-1)) + 1
else:
    for digit in digits:
        total += int("9"*digit) - int("1"+"0"*(digit-1)) + 1

print(total)


Measured memory_bytes: 3060
N, K = map(int, input().split())
MOD = 10**9+7
dp = [0] * (K+5)
ans = 0
for k in range(K, 0, -1):
    dp[k] = pow(K//k, N, MOD)

    i = 2
    while k * i <= K:
        dp[k] -= dp[k*i]
        i += 1
    # print(k, dp)
    ans += k * dp[k]
    ans %= MOD
# print(dp)
print(ans)


Measured memory_bytes: 69260
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<string.h>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<functional>
#include<algorithm>
//#include<memory.h>
#include<assert.h>
#include<numeric>
#include<limits.h>
using namespace std;
int n;
int a[2005];
bool e[2005][2005];
bool vis[2005];
vector<int>t,res,g[2005],ans[2005];
int gcd(int x,int y){if(x%y)return gcd(y,x%y);else return y;}
void dfs(int x)
{
	if(x==n)
	{
		for(int i=0;i<n;i++)
		{
			if(vis[i])continue;
			g[n].push_back(i);
			t.push_back(i);
			dfs(i);
		}
	}
	vis[x]=1;
	for(int i=0;i<n;i++)if(e[x][i]&&!vis[i])
	{
		g[x].push_back(i);
		t.push_back(i);
		dfs(i);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	sort(a,a+n);
	for(int i=0;i<n;i++)vis[i]=false;
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(gcd(a[i],a[j])!=1)e[i][j]=1;else e[i][j]=0;
	t.push_back(n);
	dfs(n);
	for(int i=n;i>=0;i--)
	{
		int x=t[i];
		for(int j=0;j<g[x].size();j++)
		{
			int y=g[x][j];
			res.clear();
			for(int k1=0,k2=0;k1<ans[x].size()||k2<ans[y].size();)if(k2==ans[y].size()||(k1<ans[x].size()&&ans[x][k1]>ans[y][k2]))res.push_back(ans[x][k1++]);else res.push_back(ans[y][k2++]);
			ans[x]=res;
		}
		ans[x].insert(ans[x].begin(),x);
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d",a[ans[n][i]]);
		if(i==n)puts("");else printf(" ");
	}
	return 0;
}

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

using namespace std;
int main(){
    int n,i;
    cin >> n;
    double sum = 0,a;
    for(i=0; i<n; i++){
       cin >> a;
       sum+=(1.0/a);
    }
    sum=(1.0)/sum;
    cout << fixed << setprecision(10) << sum << endl;
    return 0;
}

Measured memory_bytes: 3756
# -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
X=sys.stdin.readline().strip()

cnt_of_one=0
for x in X:
    if x=="1": cnt_of_one+=1

cnt_of_one_plus_one=cnt_of_one+1    #2進数Xのどこかの桁のbitが0→1になった数のpopconut
cnt_of_one_minus_one=cnt_of_one-1   #2進数Xのどこかの桁のbitが1→0になった数のpopconut

amari_cnt_of_one_plus_one=0     #2進数Xのどこかの桁のbitが0→1になった数に対して、popconutで割ったあまり
amari_cnt_of_one_minus_one=0    #2進数Xのどこかの桁のbitが1→0になった数に対して、popconutで割ったあまり
for i,x in enumerate(X[::-1]):
    if x=="1":    #その桁の値が1の時だけ数を足す
        amari_cnt_of_one_plus_one+=pow(2,i,cnt_of_one_plus_one)
        amari_cnt_of_one_plus_one%=cnt_of_one_plus_one
        if cnt_of_one_minus_one==0: #2進数の全ての桁が0の場合は、0で除算はできないので場合分けする
            amari_cnt_of_one_minus_one=0
        else:
            amari_cnt_of_one_minus_one+=pow(2,i,cnt_of_one_minus_one)
            amari_cnt_of_one_minus_one%=cnt_of_one_minus_one

def popcount(n):
    ret=0
    while 0<n:
        ret+=n%2
        n/=2
    return ret

def f(n):
    ret=0   #余りが0になるまで割った回数
    while 0<n:
        n%=popcount(n)
        ret+=1
    return ret

for i,x in enumerate(X):
    keta=N-i-1
    if x=="0":
        syoki_amari=(amari_cnt_of_one_plus_one+pow(2,keta,cnt_of_one_plus_one))%cnt_of_one_plus_one
        if syoki_amari==0:
            print 1
        else:
            print 1+f(syoki_amari)
    elif x=="1":
        if cnt_of_one_minus_one==0: #2進数の全ての桁が0という意味だから
            print 0 #値が0になるまでの操作回数は0回
        else:
            syoki_amari=(amari_cnt_of_one_minus_one-pow(2,keta,cnt_of_one_minus_one))%cnt_of_one_minus_one
            if syoki_amari==0:
                print 1
            else:
                print 1+f(syoki_amari)
            

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

int main() {
  int K;
  string S;
  cin >> K >> S;
  if (K < S.size()){
    for (int i = 0; i < K; i++){
      cout << S[i];
    }
    cout << "..." <<endl;
  }
  else {
    cout << S << endl;
  }
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
#include <cmath>
using namespace std;

int main() {
    int N; cin >> N;
    vector<long double> V(N);
    for (int i = 0; i < N; i++) {
        cin >> V.at(i);
    }
    sort(V.begin(), V.end());
    for (int i = 1; i < N; i++) {
        V.at(i) = (V.at(i - 1) + V.at(i)) / 2;
    }
    
    cout << V.at(N - 1) << endl;
}

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

#define int long long

int gcd(int a, int b) {
  if (b == 0) return a;
  else if (a < b) return gcd(b, a);
  else return gcd(b, a % b);
}


signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  num = numeric_limits<int>::max(); // min
  int N;
  // int M;
  // array<int, 100000> A;
  // string S;
  // string T;
  int A, B, K;

  cin >> A >> B >> K;

  for (int i = 0; i < K; i++) {
    if (i % 2 == 0) {
      if (A % 2 == 1) --A;
      A /= 2;
      B += A;
    } else {
      if (B % 2 == 1) --B;
      B /= 2;
      A += B;
    }
  }

  cout << A << " " << B << endl;
  



  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    int n; cin >> n;
    vector<int> p(n);
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];   
        p[i] = a[i];
    }

    sort(p.begin(), p.end());

    vector<bool> cor(n, false);
    int acc = 0;
    for(int i = 0; i < n; i++){
        cor[i] = (a[i] == p[i]);
        acc += cor[i];
    }
    
    int Q; cin >> Q;
    for(int i = 0; i < Q; i++){
        if(acc == n){
            cout << i << endl;
            return 0;
        }

        int x, y; cin >> x >> y;
        x--;
        y--;
        swap(a[x], a[y]);
        if(a[x] == p[x]){
            if(!cor[x]) acc++;
            cor[x] = true;
        }else{
            if(cor[x]) acc--;
            cor[x] = false;
        }

        if(a[y] == p[y]){
            if(!cor[y]) acc++;
            cor[y] = true;
        }else{
            if(cor[y]) acc--;
            cor[y] = false;
        }
    }

    if(acc == n) cout << Q << endl;
    else cout << -1 << endl;


    return 0;
}



Measured memory_bytes: 7588
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long money = 100;
        long x = sc.nextLong();
        long n = 0;
        while(x>money){
            n++;
            money *= 1.01;
        }
        System.out.println(n);
    }
}


Measured memory_bytes: 27012
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()

typedef long long LL;
typedef long double LD;

bool compare_by_a(pair<int, int> a, pair<int, int> b)
{
    if (a.first != b.first) {
        return a.first < b.first;
    } else {
        return a.second < a.second;
    }
}

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int N, K;
    cin >> N >> K;

    LD ans = 0.0l;

    if (N >= K) {
        int m = 0;
        for (int k = K-1; k >= 1; k--) {
            for (; k*pow(2, m) < K; m++) {
                ;
            }
            ans += (LD)pow(0.5l, m)/N;
        }
        ans += (LD)(N-K+1)/N;
    } else {
        int m = 0;
        for (int k = N; k >= 1; k--) {
            for (; k*pow(2, m) < K; m++) {
                ;
            }
            ans += (LD)pow(0.5l, m)/N;
        }
    }

    printf("%.12Lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function () { return this.index < this.max },
        "next": function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { return this.list[this.index++]; } }
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    let p = nextIntArray()
    let cnt = 0
    for (let i = 0; i < p.length; i++) {
        if(i+1 !== p[i]) cnt++
    }
    if(cnt == 0 || cnt == 2){
        console.log("YES")
    }else {
        console.log("NO")
    }
}
Main()


Measured memory_bytes: 29588
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
struct activity
{
    int A,B,C;
};
int solve(vector<activity> a,int n)
{
    int dp[n+1][3];
    dp[1][0]=a[1].A;
    dp[1][1]=a[1].B;
    dp[1][2]=a[1].C;
    for(int i=2;i<=n;i++)
    {
        dp[i][0]=a[i].A+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i].B+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i].C+max(dp[i-1][0],dp[i-1][1]);
    }
    return max({dp[n][0],dp[n][1],dp[n][2]});
}
signed main()
{
    int n;
    cin>>n;
    vector<activity> a(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].A;
        cin>>a[i].B;
        cin>>a[i].C;
    }
    cout<<solve(a,n)<<endl;
}

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

namespace ProblemA
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            Console.WriteLine(Math.Pow(N, 3));
        }
    }
}


Measured memory_bytes: 11220
#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 n,m;
   cin >> n >> m;
   vector<int> a(n);
   rep(i,n) cin >> a[i];
   int s = 0;
   rep(i,n) s += a[i];
   int cnt = 0;
   rep(i,n) {
       if(s <= a[i]*(4*m)) cnt++;
   }
   if(cnt >= m){
       cout << "Yes" << endl;
   }
   else {
       cout << "No" << endl;
   }
}


Measured memory_bytes: 3608
import math
n,d=map(int,input().split())
x = []
num = 0
z = 1
for m in range(n):
  x += [list(map(int,input().split()))]

for i in range(n):
  for j in range(z,n):
    seki = 0
    for a in range(d):
      seki += (x[i][a]-x[j][a]) ** 2
    if math.sqrt(seki).is_integer():
      num += 1  
  z+=1
print(num)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
vector<int> h;
vector<vector<int> > v;
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    h.resize(n);
    v.resize(n);
    for(int i=0;i<n;i++){
    	cin >> h[i];
    }
    int a, b;
    for(int i=0;i<m;i++){
    	cin >> a >> b;
    	a--;b--;
    	v[a].pb(b);
    	v[b].pb(a);
    }
    int ans = 0;
    for(int i=0;i<n;i++){
    	bool ok = true;
    	for(auto& to:v[i]){
    		if(h[i] <= h[to]) ok = false;
    	}
    	if(ok) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> n_num(*max_element(a.begin(), a.end()), 0);
    int n_even = 0, n_odd = 0;
    for (int i = 0; i < n; i++) {
        n_num[a[i] - 1]++;
    }
    for (int i = 0; i < n_num.size(); i++) {
        if (n_num[i] % 2 == 0) {
            if (n_num[i] != 0) n_even++;
        } else
            n_odd++;
    }
    cout << n_odd + n_even - (n_even % 2) << endl;
    return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
#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 OUT(s) cout << s << "\n";
using namespace std;

int K;
string S;
// https://atcoder.jp/contests/abc168
void Main()
{
    if (K >= S.length()) {
        OUT(S);
    } else {
        OUT((S.substr(0, K) + "..."));
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    cin >> K >> S;
    Main();
    return 0;
}

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

int main() {
  int L, R;
  cin >> L >> R;

  if (R - L + 1 >= 673) {
    cout << 0 << endl;
  } else {
    long long ans = 2018;
    for (long long i = L; i < R; i++) {
      for (long long j = i + 1; j <= R; j++) {
        ans = min((i * j) % 2019, ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

int n;
const int x = 1000000;
bool prm[x+1];

void eratos(){
	for(int i=2; i<=x; i++)
		prm[i] = true;
	for(int i=2; i*i<x; i++){
		if(prm[i])
			for(int k=i*i; k<=x; k+=i)
				prm[k] = false;
	}
}

int main(){
	int p,q,cnt;
	eratos();
	while(true){
		std::cin >> n;
		if(!n)
			return 0;
		p = 2;
		q = n-p;
		cnt = 0;
		if(prm[p] && prm[q])
			cnt++;
		p++;
		q--;
		for(;p<=q;){
			if(prm[p] && prm[q])
				cnt++;
			p+=2;
			q-=2;
		}
		std::cout << cnt << std::endl;
	}
}

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

int main(void) {
    bool flag = true;
    int a, b;
    string s;
    cin >> a >> b >> s;
    for (int i = 0; i < a + b + 1; i++) {
        if (i == a && s[i] != '-') flag = false;
        if (i != a && ('9' < s[i] || s[i] < '0')) flag = false; 
    }
    cout << (flag ? "Yes" : "No") << endl;
}


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

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

  //B以下で最大のKの倍数の求めかた
  int max = b / k * k;

  if (a <= max) cout << "OK" << endl;
  else cout << "NG" << endl;

}

Measured memory_bytes: 3624