akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>
#include <regex>
#include <functional>
#include <algorithm>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int MAX_N = 100000;

typedef signed long long ll;


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

    ll A, B, C, K;
    ll result;
    cin >> A >> B >> C >> K;
    if (K <= A) {
        result = K;
    }
    else if (K <= A + B) {
        result = A*1 + (K-A)*0;
    }
    else {
        result = A*1 + B*0 + -1* (K - (A + B));
    }
    cout << result << endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   int x,y;
   cin>>x>>y;
   if(y%2==0&&x*4>=y&&x*2<=y){
      if((y-2*x)%2==0)cout<<"Yes\n";
      else cout<<"No\n";
   }
   else cout<<"No\n";
   return 0;
}

Measured memory_bytes: 3628
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd
readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]



def main():
    a, b, c = readIntN()
    result = a * b // 2
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5140
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+100;
int n,c1,c2;
char ch[N];
int main()
{
	scanf("%d%s",&n,ch+1);
	for(int i = 1;i <= n;i++)
	{
		c1 += ch[i] == 'W';
		c2 += ch[i] == 'R';
	}
	int Ans = 0;
	for(int i = c2+1;i <= n;i++)
	{
		Ans += ch[i] == 'R';
	}
	cout<<Ans<<endl;
}

Measured memory_bytes: 3900
#include<stdio.h>
int a[1000001];
int main(void){
    int i,j,k,input,count=0,Count;
    for(i=2;i<1000001;i++){
        if(a[i]==0){
            count=count+i;
            a[i]=count;
            for(j=2;i*j<1000001;j++){
                a[i*j]=-1;
            }
        }
    }
    while(1){
        scanf("%d",&input);
        if(input==0)break;
        Count=0;
        for(i=2;i<1000001;i++){
            if(a[i]!=-1)Count++;
            if(Count==input){
                printf("%d\n",a[i]);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4500
#include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()


int main(void){
  double buf;
  while(cin>>buf,buf>0){
    double x = buf / 2;
    while(1){
      x = x - (x*x*x-buf)/(3*x*x);
      if(abs(x*x*x-buf) < 0.00001*buf)break;
    }
    printf("%6f\n",x);
  }
}

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

int main() {
    int64_t N, ans = 0, div = 10;
    cin >> N;
    if (N % 2 == 0) {
        while (div <= N) {
            ans += N / div;
            div *= 5;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    string S;
    cin >> S;
    ll s = S.size();
    for(ll i = s - 1;i >= 0;i--){
        if(i % 2 == 0){
            //cout << i << endl;
            //cout << S.substr(0,i / 2) << " " << S.substr(i / 2,i / 2);
            if(S.substr(0,i / 2) == S.substr(i/2,i/2)){
                cout << i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 256
import fractions
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
mx = a[-1]
if mx < k:
    ans = 'IMPOSSIBLE'
elif n == 1:
    if a[0] == k:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
else:
    gcd = fractions.gcd(a[0],a[1])
    for i in range(0,n):
        gcd = fractions.gcd(gcd,a[i])
    if k % gcd == 0:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
print(ans)

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

int h,w;
string field[25];
int memo[25][25][25][25];

int calc(int x1,int x2,int y1,int y2){
	if(x1 == x2 || y1 == y2) return 0;
	if(memo[x1][x2][y1][y2] != -1) return memo[x1][x2][y1][y2];
	set<int> st;
	for(int i = x1;i < x2;i++){
		for(int j = y1;j < y2;j++){
			if(field[i][j] == 'X') continue;
			int g = calc(x1,i,y1,j) ^ calc(i+1,x2,y1,j) ^ calc(x1,i,j+1,y2) ^ calc(i+1,x2,j+1,y2);
			st.insert(g);
		}
	}
	for(int i = 0;;i++){
		if(!st.count(i)) return memo[x1][x2][y1][y2] = i;
	}
}

signed main(){
	cin >> h >> w;
	for(int i = 0;i < h;i++) cin >> field[i];
	for(int i = 0;i <= h;i++){
		for(int j = 0;j <= h;j++){
			for(int k = 0;k <= w;k++){
				for(int l = 0;l <= w;l++) memo[i][j][k][l] = -1;
			}
		}
	}
	if(calc(0,h,0,w)) cout << "First" << endl;
	else cout << "Second" << endl;
}


Measured memory_bytes: 4392
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
long long a[100000];
long long gcd(long long m, long long n){
  if(n > m){
    return gcd(n, m);
  } else if(n == 0){
    return m;
  }
  return gcd(n, m % n);
}

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

  int min_2_power = INT_MAX;
  int max_2_power = 0;
  for(int i = 0; i < N; i++){
    long long tmp = a[i];
    int tmp_2_power = 0;
    while(tmp % 2 == 0){
      tmp /= 2;
      tmp_2_power ++;
    }
    min_2_power = min(min_2_power, tmp_2_power);
    max_2_power = max(max_2_power, tmp_2_power);
  }
  if(min_2_power != max_2_power){
    cout << 0 << endl;
    return 0;
  }

  for(int i = 0; i < N; i++){
    a[i] /= 2;
  }
  long long lcm_a = a[0];
  set <long long> done;
  for(int i = 1; i < N; i++){
    if(done.find(a[i]) == done.end()){
      done.insert(a[i]);
      lcm_a = (a[i] * lcm_a) / (gcd(a[i], lcm_a));
      if(lcm_a > M){
        cout << 0 << endl;
        return 0;
      }
    }
  }
  cout << (M / lcm_a + 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 1024
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

asum=sum(a)
bsum=sum(b)
if bsum<asum:
    print("No")
    exit()

ab=0
ba=0

for i in range(N):
    if a[i]<b[i]:
        ab+=(b[i]-a[i])//2
    else:
        ba+=a[i]-b[i]

if ab>=ba:
    print("Yes")
else:
    print("No")

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

int N, leak[100];
bool memberInf[101][101];

void init(int N){
  for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++)
    memberInf[i][j] = false;
}

int main(void){
  while(cin >> N && N != 0){
    init(N);
    for(int i = 1; i <= N; i++){
      int M; cin >> M;
      for(int j = 0; j < M; j++){
        int p; cin >> p;
        memberInf[i][p] = true;
      }
    }
    int K; cin >> K;
    for(int i = 0; i < K; i++) cin >> leak[i];
    
    int ans = -1, cnt = 0;
    for(int i = 1; i <= N; i++){
      bool judge = true;
      for(int j = 0; j < K; j++){
        if(!memberInf[i][leak[j]]) { judge = false; break; }
      }
      if(judge){ ans = i; cnt++; }
      if(cnt >= 2){ ans = -1; break; }
    }
    cout << ans << endl;
  }
  return 0;
}

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


using ll = long long int;

using namespace std;


int get_first(int a)
{
    int ret;
    while (a)
    {
        ret = a % 10;
        a /= 10;
    }
    return ret; 
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int i, j, n;
    
    ll ans;
    
    ans = 0;
    
    int cnt[10][10] = {};
    
    
    cin >> n;
    
    int first, last;
    
    for(i = 1; i <= n; ++i)
    {
        last = i % 10;
        first = get_first(i);
        cnt[first][last]++;
    }
    
    for(i = 1; i <= 9; ++i)
    {
        for(j = 1; j <= 9; ++j)
        {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
import math
ans=0
N,K=map(int,input().split())
if(N<K):
  for i in range(1,N+1):
    p=1/N
    n=math.ceil(math.log2(K/i))
    p*=2**(-n)
    ans+=p
else:
  for i in range(1,K):
    p=1/N
    n=math.ceil(math.log2(K/i))
    p*=2**(-n)
    ans+=p
  ans+=(N-K+1)/N
print(ans)

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

int n, m;
int memo[2][1505] = {0};
vector<int> ls[2];

long long solve();

int main() {
  int i;
  while(1) {
    cin >> n >> m;
    if(n + m == 0) break;
    for(i = 1; i <= n; ++i) {
      cin >> memo[0][i];
      memo[0][i] += memo[0][i - 1];
    }
    for(i = 1; i <= m; ++i) {
      cin >> memo[1][i];
      memo[1][i] += memo[1][i - 1];
    }
    cout << solve() << endl;
    for(i = 0; i < 2; ++i)
      ls[i].erase(ls[i].begin(), ls[i].end());
    for(i = 1; i <= n; ++i) memo[0][i] = 0;
    for(i = 1; i <= m; ++i) memo[1][i] = 0;
  }
  return 0;
}

long long solve() {
  int i, j, k, now;
  long long ans = 0;
  for(i = 0; i < n; ++i)
    for(j = i + 1; j <= n; ++j)
      ls[0].push_back(memo[0][j] - memo[0][i]);
  for(i = 0; i < m; ++i)
    for(j = i + 1; j <= m; ++j)
      ls[1].push_back(memo[1][j] - memo[1][i]);
  for(k = 0; k < 2; ++k) sort(ls[k].begin(), ls[k].end());
  for(i = 0; i < ls[0].size(); ++i) {
    now = ls[0][i];
    auto it = lower_bound(ls[1].begin(), ls[1].end(), now);
    auto it2 = upper_bound(ls[1].begin(), ls[1].end(), now);
    if(it != ls[1].end()) ans += (it2 - it);
  }
  return ans;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)


string s;


int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  cin >> s;
  ll n=s.length();
  
  ll res=0,c=0;
  string t="";
  rep(i,0,n-1){
    if(s[i]=='A') c++;
    else if(s[i]=='B'&&s[i+1]=='C') res+=c,i++;
    else c=0;
  }
  
  cout << res << endl;
 
 
}

Measured memory_bytes: 720
n,k=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
ans=[]
for i in range(0,n-k+1):
  l=x[i]
  r=x[i+k-1]
  ans.append(min(abs(l)+abs(l-r),abs(r)+abs(l-r)))
print(min(ans))


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

using namespace std;
int main() {
  string s;
  cin >> s;
  int minNum = 1000;
  for (int i = 0; i < s.length() - 2; i++) {
    int num = stoi(s.substr(i, 3));
    minNum = min(minNum, abs(num - 753));
  }
  cout << minNum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int a[114];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	cout << a[n - 1] - a[0] << endl;
}

Measured memory_bytes: 256
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
 
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
 
int main(void){
    long long n,k,a[131072],i,r=inf;
    scanf("%lld%lld",&n,&k);
    if(n%3 == 0 || k%3 == 0){printf("0\n");return 0;}
    r = llmin(n,k);
    for(i=0;i<=n;i++){
        r=llmin(r,llmax(i*k,(n-i)*llceil(k,2))-llmin(i*k,(n-i)*(k/2)));
    }
    for(i=0;i<=k;i++){
        r=llmin(r,llmax(i*n,(k-i)*llceil(n,2))-llmin(i*n,(k-i)*(n/2)));
    }
    printf("%lld\n",r);
    return 0;
}

Measured memory_bytes: 128
'use strict';
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim();
  var expressions = inputs.split('\n');
  
  for (var i = 0; i < expressions.length; i++) {
    if (expressions[i] === '0 ? 0') {
      break;
    }
    var expression = expressions[i].split(' ');
    var left = parseFloat(expression[0]);
    var right = parseFloat(expression[2]);
    var op = expression[1];
  
    if (op === '+') {
      console.log(left + right);
    } else if (op === '-') {
      console.log(left - right);
    } else if (op === '*') {
      console.log(left * right);
    } else if (op === '/') {
      console.log(Math.floor(left / right));
    }
  }
  
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15960
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace codeTester.contest190804
{
    class ProblemB
    {
        static int n = 0;
        static string answer = "";

        public static void Main(string[] args)
        {
            Input();
            Logic();
            Output();
        }

        static void Input()
        {
            n = int.Parse(Console.ReadLine());
        }

        static void Logic()
        {
            int inputDigitNum = n.ToString().Length;
            switch (inputDigitNum)
            {
                case 6:
                    answer = 90909.ToString();
                    break;
                case 5:
                    answer = (n - 9999 + 909).ToString();
                    break;
                case 4:
                    answer = 909.ToString();
                    break;
                case 3:
                    answer = (n - 99 + 9).ToString();
                    break;
                case 2:
                    answer = 9.ToString();
                    break;
                case 1:
                    answer = n.ToString();
                    break;
            }
        }

        static void Output()
        {
            Console.WriteLine(answer);
        }

        static void DebugPrint(string msg)
        {
            // 提出時に消す
            // Console.WriteLine(msg);
        }
    }
}


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

namespace perse {

char nxt(char c){
	return c == 'Z' ? 'A' : c + 1;
}

char prv(char c){
	return c == 'A' ? 'Z' : c - 1;
}

typedef std::string::const_iterator Iterator;

std::string cipher(Iterator&);
std::string string(Iterator&);
char letter(Iterator&);

std::string eval(const std::string &s)
{
	Iterator it = std::begin(s);
	return cipher(it);
}

std::string cipher(Iterator &it){
	std::string res;
	while (*it != '\0' && *it != ']'){
		res += string(it);
	}
	return res;
}

std::string string(Iterator &it){
	if (*it == '['){
		++it;
		std::string res = cipher(it);
		++it;
		std::reverse(std::begin(res), std::end(res));
		return res;
	}
	return std::string(1, letter(it));
}

char letter(Iterator &it){
	if (*it == '+'){
		++it;
		return nxt(letter(it));
	}
	else if (*it == '-'){
		++it;
		return prv(letter(it));
	}
	else if (isalpha(*it)){
		char c = *it;
		++it;
		return c;
	}
	else assert(false);
}

} 

using namespace std;

int main()
{
	string s;
	while (cin >> s, s != "."){
		vector<string::iterator> v;
		char c[3];
		for (auto it = begin(s); it != end(s); ++it){
			if (*it == '?') v.push_back(it);
		}
		string res(100, 'Z');
		for (c[0] = 'A'; c[0] <= 'Z'; c[0]++){
			for (c[1] = 'A'; c[1] <= 'Z'; c[1]++){
				for (c[2] = 'A'; c[2] <= 'Z'; c[2]++){
					for (int i = 0; i < v.size(); i++){
						*v[i] = c[i];
					}
					res = min(res, perse::eval(s));
				}
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 3228
#include<iostream>
using namespace std;
int main(){
	int a,b,d=0,c,e;
	while(cin>>a>>b){
		c=a;
		e=b;
		if(a<b){
			d++;
		}
		while(a!=0&&b!=0){
			if(d%2==0){
				a%=b;
			}else{
				b%=a;
			}
			d++;
		}
		cout<<a+b<< " " <<c*(e/(a+b))<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define pb push_back
#define popb pop_back
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
 
#define forz(i, n) for (int i = 0; i < n; i++)
#define bui(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define mui(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
 lli power(lli x,lli y,lli p)
{
  lli res=1;
  x=x%p;
  while(y>0)
  {
    if(y&1)
      res=(res*x)%p;
    //y must be even now
    y=y>>1; //y=y/2
    x=(x*x)%p;
  }
  return res;
}
 
lli gcd(lli a, lli b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{ return a * b / gcd(a, b); }
lli max(lli a, lli b)
{
  if (a > b)
    return a;
  return b;
}
lli min(lli a, lli b)
{
  if (a < b)
    return a;
  return b;
}
using namespace std;

int main()
{  
    kira;
    //freopen("input.txt","r",stdin);
    lli n,d=0;
    cin>>n;
    lli a[n];
    forz(i,n)
    cin>>a[i];
    lli p=a[0]-1;
    for(lli i=1;i<n;i++)
    {
      if(a[i]<p)
      {
        d=1;
        break;
      }
      p=max(p,a[i]-1);
    }
    if(d==1)
      cout<<"No"<<endl;
    else
      cout<<"Yes"<<endl;
}

Measured memory_bytes: 1024
n = int(input())
dic = {"AC":0, "WA":0, "TLE":0,"RE":0}
for i in range(n):
    n = input()
    dic[n] += 1

print("AC x " + str(dic["AC"]))
print("WA x " + str(dic["WA"]))
print("TLE x " + str(dic["TLE"]))
print("RE x " + str(dic["RE"]))

Measured memory_bytes: 9200
#include <stdio.h>

int calc(int n, int a, int b)
{
    int train = n * a;
    int taxi = b;

    if (train >= taxi)
    {
        return taxi;
    }
    else
    {
        return train;
    }
}

int main()
{

    int N;
    int A;
    int B;
    /*
    char buf[256];
    fgets(buf, 256, stdin); /授業で使われたやつだけど開業をしなければ行けないみたいで
    sscanf(buf, "%d", &N);  /使いづらいしやめました。
    fgets(buf, 256, stdin); /でもscanfには初めに指定したサイズを超えると正しく取れない
    sscanf(buf, "%d", &A);  /と言うbugがあるらしいので、ちゃんと勉強をして
    fgets(buf, 256, stdin); /scanf_sとかを使えるようにしたい。
    sscanf(buf, "%d", &B);
*/

    scanf("%d %d %d", &N, &A, &B);

    if (20 - N < 0 && N - 1 < 0)
    {
        printf("Tish number is uncorrect : N %d", N);
        return -1;
    }
    if (50 - A < 0 && A - 1 < 0)
    {
        printf("Tish number is uncorrect : A %d", A);
        return -1;
    }
    if (50 - B < 0 && B - 1 < 0)
    {
        printf("Tish number is uncorrect : B %d", B);
        return -1;
    }

    int R = calc(N, A, B);
    printf("%d", R);

    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

vi g[MAXN];

int per[MAXN];
int used[MAXN];

deque<int> dd;

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 1, n) {
		int a, b;
		scanf("%d%d", &a, &b);
		g[a].pb(b);
		g[b].pb(a);
	}
	if (n <= 3) {
		REPN(i, 1, n) {
			printf("%d ", i);
		}
		return;
	}
	int s[2], top;
	top = 0;
	REPN(i, 1, n) {
		if (SZ(g[i]) > 1) {
			int cnt = 0;
			REP(j, 0, SZ(g[i])) {
				int to = g[i][j];
				if (SZ(g[to]) > 1) {
					cnt++;
				}
			}
			if (cnt > 2) {
				printf("-1\n");
				return;
			}
			if (cnt <= 1) {
				if (top == 2) {
					printf("-1\n");
					return;
				}
				s[top++] = i;
			}
		}
	}
	if (top == 1) {
		s[1] = s[0];
	}
	
	for(int cur = s[0]; ; ) {
		dd.pb(cur);
		used[cur] = 1;
		int nxt = -1;
		REP(i, 0, SZ(g[cur])) {
			int to = g[cur][i];
			if (!used[to]) {
				if (SZ(g[to]) > 1) {
					nxt = to;
				}
			}
		}
		if (cur == s[1]) {
			break;
		}
		cur = nxt;
	}
	
	int fl = 0;
	REP(i, 0, SZ(dd)) {
		int sz1 = SZ(g[dd[i]]);
		int sz2 = SZ(g[dd[SZ(dd) - 1 - i]]);
		if (sz1 != sz2) {
			if (sz1 > sz2) {
				fl = 1;
			}
			break;
		}
	}
	if (fl) {
		reverse(BE(dd));
	}
	
	REP(i, 0, SZ(g[dd[0]])) {
		int to = g[dd[0]][i];
		if (SZ(g[to]) == 1) {
			dd.push_front(to);
			used[to] = 1;
			break;
		}
	}
	
	REP(i, 0, SZ(g[dd[SZ(dd) - 1]])) {
		int to = g[dd[SZ(dd) - 1]][i];
		if (SZ(g[to]) == 1 && !used[to]) {
			dd.push_back(to);
			used[to] = 1;
			break;
		}
	}
	
	int top_per = 0;
	REP(i, 0, SZ(dd)) {
		int cnt = SZ(g[dd[i]]) - 2;
		if (SZ(g[dd[i]]) == 1) {
			cnt = 0;
		}
		int val = top_per;
		REP(i, 0, cnt) {
			per[top_per] = top_per + 1;
			top_per++;
		}
		per[top_per++] = val;
	}
	
	REP(i, 0, n) {
		printf("%d ", per[i] + 1);
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 9856
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n, ma, mb = list(map(int, input().split()))
abc = [None]*n
for i in range(n):
    a,b,c = tuple(map(int, input().split()))
    abc[i] = (a*mb - b*ma, c)
abc.sort()
def halfcomb(l):
    n = len(l)
    n1 = n//2
    n2 = (n+1)//2
    l1 = []
    l2 = []
    
    for b in range(1, 1<<n2):
        v11, v12 = 0, 0
        v21, v22 = 0, 0
        for i in range(n2):
            if b&1<<i:
                item = l[n1+i]
                v21+=item[0]
                v22+=item[1]
                if b<(1<<n1) and i<n1:
                    item = l[i]
                    v11+=item[0]
                    v12+=item[1]
        if b<(1<<n1):
            l1.append((v11,v12))
        l2.append((v21,v22))
    return l1, l2
l1, l2 = halfcomb(abc)
d2 = {}
for v,c in l2:
    if v in d2:
        d2[v] = min(d2[v], c)
    else:
        d2[v] = c
ans = float("inf")
for v,c in l1:
    if v==0:
        ans = min(ans, c)
for v,c in l2:
    if v==0:
        ans = min(ans, c)
        
for v,c in l1:
    if -v in d2:
        ans = min(ans, c+d2[-v])
if ans == float("inf"):
    ans = -1
print(ans)

Measured memory_bytes: 227104
#include <stdio.h>
int main(){

  int i,j,k,x,n,a[10000];
  long long sum;

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

  }

  for (j = 0; j < (n-1)*2; j++){

    for (i = 0; i < n-1; i++){

      if (a[i] >= a[i+1]){

        x=a[i];
        a[i]=a[i+1];
        a[i+1]=x;

      }

    }

  }

  sum=0;

  for (k = 0; k < n; k++){

    sum=a[k]+sum;

  } 

  printf("%d %d %lld\n",a[0],a[n-1],sum);

    return 0;

}

Measured memory_bytes: 640
N,M=list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(M)]
seen = [-1 for i in range(N)]
count = 0
def dfs(x):
    global count
    if sum(seen) == N:
        count += 1
        return
    
    for i in range(M):
        if a[i][0] == x and seen[a[i][1]-1] == -1:
            seen[a[i][1]-1] = 1
            dfs(a[i][1])
            seen[a[i][1]-1] = -1
        if a[i][1] == x and seen[a[i][0]-1] == -1:
            seen[a[i][0]-1] = 1
            dfs(a[i][0])
            seen[a[i][0]-1] = -1
seen[0] = 1
dfs(1)
print(count)


Measured memory_bytes: 42972
#include <iostream>

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

  if (a >= k)
  {
    std::cout << k << std::endl;
  }
  else if (k - a < b)
  {
    std::cout << a << std::endl;
  }
  else
  {
    std::cout << a - (k - a - b) << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3192
n,m = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a,reverse=True)
ans = 0
for i in range(m):
    if a[i] >= sum(a)/(4*m):
        ans+=1
if ans == m:
    print('Yes')
else:
    print('No') 

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	priority_queue<ll>q;
	for(ll i=0;i<k;i++){
		ll now;
		cin>>now;
		q.push(now);
	}
	ll ans=0;
	while(q.size()>1){
		ll next=q.top();
		next--;
		q.pop();
		ll nnext=q.top();
		nnext--;
		q.pop();
		if(nnext!=0){
			q.push(nnext);
		}
		if(next!=0){
			q.push(next);
		}
	}
	cout << q.top()-1;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int n,a[500000],cnt;

void mg(int l,int m,int r){
  int n1=m-l,n2=r-m;
  int L[n1+1],R[n2+1];
  for(int i=0;i<n1;i++)L[i]=a[l+i];
  for(int i=0;i<n2;i++)R[i]=a[m+i];
  L[n1]=1000000001,R[n2]=1000000001;
  int i=0,j=0;
  for(int k=l;k<r;k++)cnt++,L[i]<=R[j]?a[k]=L[i++]:a[k]=R[j++];
}

void mgs(int l=0,int r=n){
  if(l+1<r){
    int m=(l+r)/2;
    mgs(l,m);
    mgs(m,r);
    mg(l,m,r);
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)scanf("%d",&a[i]);
  mgs();
  for(int i=0;i<n;i++){
    if(i)printf(" ");
    printf("%d",a[i]);
  }printf("\n");
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 7092
#include<iostream>
using namespace std;
#define ll long long
int main(){
  
  int n,flag=0;
  cin >> n;
  long double a[n+1],ans=1;
  for(int i=0;i<n;i++){
    cin>> a[i];
    
  
  }
  sort(a,a+n);
  if(a[0]==0)cout << 0;
  else{
   for(int i=n-1;i>=0;i--){
     if(ans*a[i]>pow(10,18)){
       cout << -1;
       flag=1;
       break;
     }
     ans*=a[i];
   }  
  if(!flag)
   cout << (ll)ans;
  }  
  return 0;
}

Measured memory_bytes: 4708
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<climits>

#define MAX_V 101
#define INF 10000000

using namespace std;


struct edge{int to, cost; };
typedef pair<int, int> P;

int V,mincost[MAX_V];
vector<edge>G[MAX_V];

int Prim(int s){
  priority_queue<P, vector<P>, greater<P> >que;
  fill(mincost, mincost+V, INF);

  vector<bool> visited(V);
  fill(visited.begin(),visited.end(),false);

  mincost[s]=0;
  que.push(P(0,s));
  int res=0;

  while(!que.empty()){
    P p = que.top();
    que.pop();
    
    int v = p.second;
    if(mincost[v]<p.first || visited[v])continue;
    visited[v]=true;
    res+=mincost[v];

    for(int i=0; i < G[v].size(); i++){
      edge e = G[v][i];
      if(mincost[e.to] > e.cost && !visited[e.to]){
	mincost[e.to] = e.cost;
	que.push(P(mincost[e.to], e.to));
      }
    }
  }
 
  return res;
}


int main(void){
  int m,a,b,c;
  char ch1,ch2;
  edge e;

  while(cin >> V,V){
    for(int i=0;i<V;i++)G[i].clear();
    cin >> m;
    for(int i=0;i<m;i++){
      cin >> a >> ch1 >> b >> ch2 >> c;
      e.to=b,e.cost=c/100-1;
      G[a].push_back(e);
      e.to=a;
      G[b].push_back(e);
    }
      cout << Prim(0) << endl;
  }

  return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, ans = 0; cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
        ans ^= a[i];
    }
    
    rep(i, n) {
        cout << ll(ans^a[i]) << ' ';
    }
    cout << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


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

int main(){
  ll n,k,m=1000;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++) cin >> a.at(i);
  
  for(ll i=0;i<n-1;i++){
    if(a.at(i) < a.at(i+1)){
      k = m/a.at(i);
      m += k*(a.at(i+1) - a.at(i));
    }
  }
  
  cout << m << endl;
  
  return 0;
}


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

using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/

#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second

#define what_is(x)     cerr << #x << " is " << x << endl;

///*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
int ini(){
    int x;
    scanf("%d",&x);
    return x;
}
long long inl(){
    long long x;
    scanf("%lld",&x);
    return x;
}

const int N = (int) 2e5 + 5;
const int inf = (int) 1e9 + 7;
const double pi=2* acos(0.0);
int res[N],a[N];

int main()
{

    int n,i,j,k;
    n=ini();

    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    res[1]=0;
    res[2]=abs(a[2]-a[1]);

    for(int i=3;i<=n;i++){
        res[i]=min(res[i-2]+abs(a[i]-a[i-2]),res[i-1]+abs(a[i]-a[i-1]));
    }
    cout<<res[n]<<endl;

    return 0;
}





Measured memory_bytes: 1024
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template <class T>
class CuSum {
private:
	vector<T> cusum;

public:
	CuSum(vector<T> const &vec) : cusum(vec.size() + 1) {
		for (int i = 0; i < (int)vec.size(); i++) cusum[i + 1] = cusum[i] + vec[i];
	}
	CuSum(const int N) : cusum(N + 1) {}
	void add(const int i, const T &x) { cusum[i + 1] += x; }
	void build() { for (int i = 0; i < (int)cusum.size() - 1; i++) cusum[i + 1] += cusum[i]; }

	// partial sum of 0-indexed [l, r)
	T operator()(int l, int r) {
		if (r < l || r < 0) {
			assert(0);
			return T(0);
		}
		else return cusum[r] - cusum[l];
	}
	// 0-indexed
	const T &operator[](int i) { return cusum[i + 1]; }
	T back() { return cusum.back(); }
};

template<class T>
inline bool chmin(T &a, const T b) { return a > b && (a = b, true); }

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<lint> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	CuSum<lint> cuA(A);
	lint ans = LINF;
	for (int i = 0; i < N; i++) chmin(ans, abs(cuA(0, i) - cuA(i, N)));

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;
import java.util.Map.Entry;

public class Main {

	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		char[] a = in.next().toCharArray();
		StringBuilder ret = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (a[i] == '9') {
				ret.append(1);
			} else if (a[i] == '1') {
				ret.append(9);
			}
		}
		out.println(ret);
		out.flush();
		out.close();

	}

	static class FastReader {
		StringTokenizer st;
		BufferedReader br;

		public FastReader(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastReader(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

Measured memory_bytes: 23120
#include <stdio.h>
int main()
{
  int n,i,j=0,k=0;
  scanf("%d",&n);
  int ar[n];
  for(i=0;i<n;i++)
  {
    scanf("%d",&ar[i]);
  }
  for(i=0;i<n;i++)
  {
   if((ar[i])==(i+1))
   {
     j++;
   } 
   else if((ar[i])!=(i+1))
   {
     k++;
   }
  }
  if(j==n)
  {
    printf("YES\n");
   }
  else if(k<=2)
  {
    printf("YES\n");
  }
  else
  {
    printf("NO\n");
  }
  return 0;
}

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

int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,m;
	cin >> n >> m;
	int a[n],b[n]={0};
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]/=2;
	}
	int l=a[0];
	for(int i=1;i<n;i++){
		l=(l*a[i])/__gcd(l,a[i]);
	}
	int flag=1;
	for(int i=0;i<n;i++){
		if(!(l/a[i]%2))flag=0;
	}
	if(!flag){
		cout << 0;
		return 0;
	}
	cout << (m/l)-(m/(2*l));
}


Measured memory_bytes: 1792
N, M = map(int,input().split())
K = []
S = []
for _ in range(M):
    KS = list(map(int,input().split()))
    k = KS.pop(0)
    K.append(k)
    S.append(KS)
P = list(map(int,input().split()))

cnt = 2 ** N
ans = 0

for i in range(cnt):
    flg = 1
    for j in range(M):
        s = S[j]
        sum_s = 0
        for x in s:
            sum_s += 2 ** (x - 1)
        calc = sum_s & i
        sum_str = bin(calc)
        div = sum_str.count('1') % 2
        if P[j] == div:
            continue
        else:
            flg = 0
            break
    if flg == 1:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;


signed main(){
    cin >> n;
    int l=0,r=0;
    REP(i,n){
        string s,t;
        cin >> s >> t;
        if(s>t){
            l += 3;
        }
        else if(s==t){
            l++;
            r++;
        }
        else{
            r += 3;
        }
    }
    cout << l << " " << r << endl;
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}





Measured memory_bytes: 3184
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
// 整数aと、英小文字からなる文字列sが入力されます。aが3200以上ならsと出力し、aが3200未満なら red と出力するプログラムを書いてください。

int main () {
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200) cout << s;
  else cout << "red";
}


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


void solve();

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

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

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


void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  cin >> a;

  rep(i, n) a[i]--;
  vector<ll> acc(n + 1);
  rep3(i, 1, n + 1) acc[i] = acc[i - 1] + a[i - 1];
  // cout << acc << endl;
  rep(i, n + 1) acc[i] %= k;
  // 長さじゃなくて 0 でいい !
  rep(i, n + 1) (acc[i] += -1 + k) %= k; // 1 引いて mod とる
  // cout << acc << endl;

  ll ans = 0;
  // 手前で, あまりが同じの何個?
  map<int, int> mp;
  // 重要    長さ k 未満
  queue<int> q;
  rep(i, n + 1) {
    ans += mp[acc[i]];
    mp[acc[i]]++;
    q.push(acc[i]);
    while (sz(q) >= k) {
      --mp[q.front()];
      q.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 12800
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
 
const int maxn = 105, inf = 0x3f3f3f3f;
int M, N;
int X1[maxn], Y1[maxn], X2[maxn], Z2[maxn];
 
//计算按x值对多边形切片得到的宽度
double width(int * X, int * Y, int n, double x)
{
    double lb = inf, ub = -inf;
    for (int i=0; i<n; ++i)
    {
        double x1 = X[i], y1 = Y[i], x2 = X[(i + 1) % n], y2 = Y[(i + 1) % n];
        //检查与第i条边是否相交
        if ((x1 - x) * (x2 - x) <= 0 && x1 != x2)
        {
            //计算交点坐标
            double y = y1 + (y2 - y1) * (x - x1) / (x2 - x1);
            lb = min(lb, y);
            ub = max(ub, y);
        }
    }
    return max(0.0, ub - lb);
}
 
void solve()
{
    //枚举区间的端点
    int min1 = *min_element(X1, X1 + M), max1 = *max_element(X1, X1 + M);
    int min2 = *min_element(X2, X2 + N), max2 = *max_element(X2, X2 + N);
    vector<int> xs;
    for (int i=0; i<M; ++i) xs.push_back(X1[i]);
    for (int i=0; i<N; ++i) xs.push_back(X2[i]);
    sort(xs.begin(), xs.end());
     
    double res = 0;
    for (int i=0; i+1<xs.size(); ++i)
    {
        double a = xs[i], b = xs[i+1], c = (a + b) / 2;
        if (min1 <= c && c <= max1 && min2 <= c && c <= max2)
        {
            //利用Simpson公式求积分
            double fa = width(X1, Y1, M, a) * width(X2, Z2, N, a);
            double fb = width(X1, Y1, M, b) * width(X2, Z2, N, b);
            double fc = width(X1, Y1, M, c) * width(X2, Z2, N, c);
            res += (b - a) / 6 * (fa + 4 * fc + fb);
        }
    }
    printf("%.10f\n", res);
    return;
}
 
int main()
{
    while (~scanf("%d %d", &M, &N) && (M + N))
    {
        for (int i=0; i<M; ++i) scanf("%d %d", &X1[i], &Y1[i]);
        for (int i=0; i<N; ++i) scanf("%d %d", &X2[i], &Z2[i]);
        solve();
    }
    return 0;
}


Measured memory_bytes: 3268
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)
#include <deque>

using namespace std;
#define ll long long

void dfs(vector<int>& color,
	 vector<vector<pair<int, ll> > > connection,
	 int x) {
  deque<int> D;
  color[x] = 0;
  D.push_back(x);
  while(D.size() > 0) {
    int xtmp = D.back();
    D.pop_back();
    for(int i=0; i<connection[xtmp].size(); i++) {
      int nx = connection[xtmp][i].first;
      int w = connection[xtmp][i].second;
      if(color[nx] == -1) {
	color[nx] = w % 2 == 0 ? color[xtmp] : 1 - color[xtmp];
	D.push_back(nx);
      }
    }
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> color(N, -1);
  vector<vector<pair<int, ll> > > connection(N);
  for(int i=0; i<N-1; i++) {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    u--; v--;
    connection[u].push_back(make_pair(v, w));
    connection[v].push_back(make_pair(u, w));
  }
  dfs(color, connection, 0);
  for(int i=0; i<N; i++)
    cout << color[i] << endl;
  return 0;
}


Measured memory_bytes: 15104