akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
  
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
  
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
  
typedef long long int ll;
  
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =5*100001;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}

const ll MAX = 100000; 

int main()
{

  IOS
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
cin>>a[i];
ll ans=0;
for(ll i=0;i<n;i++)
{
  for(ll j=i+1;j<n;j++)
  {
    ans+=(a[i]*a[j]);
  }
}  
cout<<ans;
}
    
  

  
  
	




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

int main() {
  long long N,ans=0;
  cin >> N;
  vector<int> D(N);
  for(int i=0;i<N;i++) cin >> D[i];
  
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      ans += D[i] * D[j];
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace kyopro
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            int[] d = Array.ConvertAll(str, int.Parse);
            int kotae = 0;
            if (n % 2 == 0)
            {
                Array.Sort(d);
                kotae = d[(d.Length / 2)] - d[(d.Length / 2) - 1];
            }
            else
            {
            }
            Console.WriteLine(kotae);
        }
    }
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[11],B[11];
int dfs(int n){
    if(n==N)return 0;
    if(A[n]==B[n])return dfs(n+1);

    int t=B[n]-A[n];
    if(t<0)t+=10;
    int ret=1001001001;
    for(int i=n+1;i<=N;i++){
        for(int j=n;j<i;j++)A[j]=(A[j]+t)%10;
        chmin(ret,dfs(n+1)+1);
        for(int j=n;j<i;j++)A[j]=(A[j]-t+10)%10;
    }
    return ret;
}

signed main(){
    while(cin>>N,N){
        string S,T;
        cin>>S>>T;
        rep(i,N){
            A[i]=S[i]-'0';
            B[i]=T[i]-'0';
        }
        cout<<dfs(0)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string str;
	int n,t;
	vector< pair<pair<string,int>, int> > v;
	cin>>n;
	for(int i=0; i<n; i++)
	{	cin>>str>>t;
		v.push_back( make_pair(make_pair(str, -t) , i) );
	}
	sort(v.begin(), v.end());

	for(int i=0; i<n; i++)
	{
		cout<<v[i].second+1<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  ll ans=LLONG_MAXs;
  // ll ans=0;
  string S;
  cin >> S;



  FOR(i,'a','z'){
    ll flag=1;
    ll A[S.size()];
    ll tmp=0;

      FOR(j,0,S.size()-1){
        if(S[j]!=i){
          A[j]=0;
        }else{
          A[j]=1;
        }
      }
      FOR(j,0,S.size()-1){
        if(A[j]!=1)flag=0;
      }
      if(S.size()==1){
  cout<<"0"<<endl;
return 0;
      }

    while(flag==0){
       flag=1;
       tmp++;
      
       FOR(j,0,S.size()-1-tmp){
         if(A[j]==1 || A[j+1]==1){
           A[j]=1;
         }else{
           A[j]=0;
         }
       }
      ll flag2=0;
       FOR(j,0,S.size()-1-tmp){
         if(A[j]!=1)flag=0;
        flag2=flag2+A[j];
       }
       if(flag2==0){
         flag=1;
         tmp=999999999999;
       }



    }
    
  ans=min(ans,tmp);

  }
  cout<<ans<<endl;
return 0;

}
 


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

using namespace std;

int main() {
	string S;

	cin >> S;

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

	string::iterator itr = S.begin() + 1;
	bool flag = false;
	while (itr != S.end()) {
		if (*itr == *(itr - 1)) {
			cout << "no" << endl;
			flag = true;
		}
		if (flag) { break; }
		itr++;
	}

	if (!flag) { cout << "yes" << endl; }

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
typedef long long ll;
using namespace std;
int n,m,a[109],sum;
int main(){
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++){scanf("%d",&a[i]),sum += a[i];}
    sort(a+1,a+n+1);
    for(int i = n; i >= n-m+1; i--)if(a[i] * 4 * m < sum){printf("No\n"); return 0;}
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    ll d, t, s;
    cin >> d >> t >> s;
    if(s * t >= d)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
n = int(input())
a = input().split()

a = list(map(lambda x:int(x), a))

counter = [0] * 200005
choice = [0] * 200005
choice_minus1 = [0] * 200005
table = [-1] * 2000005
sum = 0

for i in range(0, len(a)):
    counter[a[i]] = counter[a[i]] + 1

for i in range(0, len(counter)):
    tmp_choice = int(counter[i] * (counter[i]-1) / 2)
    if tmp_choice <= 0:
        choice[i] = 0
    else:
        choice[i] = tmp_choice
        sum = sum + tmp_choice
    
    tmp_choice = int((counter[i]-1) * (counter[i]-2) / 2)
    if tmp_choice <= 0:
        choice_minus1[i] = 0
    else:
        choice_minus1[i] = tmp_choice

for i in range(0, len(a)):
    if table[a[i]] == -1:
        print(sum-choice[a[i]]+choice_minus1[a[i]])
        table[a[i]] = sum-choice[a[i]]+choice_minus1[a[i]]
    else:
        print(table[a[i]])


Measured memory_bytes: 37012
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pairSS
int main(){
  int n;
  cin >> n;
  int p[n];
  int count =0;
  for(int i=0;i<n;i++){
    cin >> p[i];
    if(i+1!=p[i]){
      count++;
    }
  }
  if(count<=2){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

int main(){
  string s;
  cin >> s;
  
  //初期値は大きい値
  int ans = s.length();
  
  //iは最初に使う色(0or1)
  for (int i=0;i<2;++i){
    //iを最初に使ったときに変えなければならないタイルの数
    int cnt = 0;
    
    for (int j=0;j<s.length();++j){
      //文字を数字に変換する方法((char)(0+'0')→'0',(char)(1+'0')→'1')
      if (j%2==0&&s[j]!=(char)(i+'0')) cnt++;//18,19行目がわからない
      if (j%2==1&&s[j]==(char)(i+'0')) cnt++;
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  map<string, int> shina;
  
  string s;
  
  for (int i = 0; i < N; i++) {
    cin >> s;
    //cout << s << endl;
    shina[s] = 1;
  }
  
  cout << shina.size() << endl;
  
}

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)

    divisors.sort()
    return divisors


def check(x, y):
    return x ** 4 + x ** 3 * y + x ** 2 * y ** 2 + x * y ** 3 + y ** 4


X = readint()
l = make_divisors(X)

ans_A = 0
ans_B = 0
for n in l:
    # n = A - B
    A = n // 2
    B = A - n
    while A ** 5 - B ** 5 <= X:
        if check(A, B) == (X // n):
            ans_A = A
            ans_B = B
            break
        else:
            A -= 1
            B -= 1

    if ans_A:
        break


print(ans_A, ans_B)


Measured memory_bytes: 9248
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long long ll;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 2000000009
#define MOD 1000000007

vector<ll> fac, facInv, inv;
void facInit(int nmax)
{
    fac = facInv = inv = vector<ll>(nmax + 1, 1);
    for (int i = 2; i <= nmax; i++)
    {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        facInv[i] = facInv[i-1] * inv[i] % MOD;
    }
}
ll nCr(int n, int r)
{
    if (n < 0 or n<r or r<0) return 0;
    if (n >= (int)fac.size()) facInit(n);
    return (fac[n] * facInv[r] % MOD) * facInv[n-r] % MOD;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll n,k,i;cin>>n>>k;
  //caricurate
  for(i=1;i<k+1;i++){
    cout<<nCr(n-k+1,i)*nCr(k-1,i-1)%MOD<<endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long n = scan.nextLong();
    long [] b = new long[241];
    long [] c = new long[241];

    for (int j=-120;j<121;j++){
      long gg = fast(j,5);
      b[j+120] = gg;
      c[j+120] = gg;
    }

    for(int i=240;i>=0;i--){
      for (int j = i-1; j>=0;j--){
        if (b[i] - c[j] == n){
          int a1 = i-120;
          int a2 = j-120;
          System.out.println(a1 + " " + a2);
          return;
        }
      }
    }

  }

  static long fast(int a, int b){
    long ans = 1;
    long base = a;
    while (b !=  0){
      if ((b & 1) == 1){
        ans *= base;
      }
      base = base*base;
      b >>= 1;
    }
    return ans;
  }
}


Measured memory_bytes: 38700
import copy as cp
s = input()
t = input()
u = list(s)
v = list(t)
w = cp.deepcopy(u)
p = 0
q = 0
for h in range(len(u) - 1, -1, -1):
    if q == 1:
        break
    if v[-1] == u[h]:
        #w[i] = v[0]
        for j in range(len(v)):
            if (v[-1 - j] == u[h - j]) and h - j >= 0:
                pass
                if j == len(v) - 1:
                    #for k in range(len(v)):
                        #w[h - k] = v[-1 - k]
                    q = 1
                    p = 1
            else:
                break
if q == 0:
    for i in range(len(u) - 1, -1, -1):
        if p == 1:
            break
        if v[-1] == u[i] or "?" == u[i]:
            #w[i] = v[0]
            for j in range(len(v)):
                if (v[-1 - j] == u[i - j] or "?" == u[i - j]) and i - j >= 0:
                    pass
                    if j == len(v) - 1:
                        for k in range(len(v)):
                            w[i - k] = v[-1 - k]
                        p = 1
                else:
                    break

if p == 1:
    for m in range(len(u)):
        if w[m] == "?":
            w[m] = "a"
    print("".join(w))
if p == 0:
    print("UNRESTORABLE")

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] bw = scan.nextLine().split("");
        String tmp = bw[0];
        int count = 0;
        for (int i = 1; i < bw.length; i++) {
            if(!bw[i].equals(tmp)){
                tmp = bw[i];
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 20156
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7; 
const int MINF = -1050000000;


int main() {
	string s;
	cin >> s;
	if (s == "SUN") cout << 7 << endl;
	if (s == "MON") cout << 6 << endl;
	if (s == "TUE") cout << 5 << endl;
	if (s == "WED") cout << 4 << endl;
	if (s == "THU") cout << 3 << endl;
	if (s == "FRI") cout << 2 << endl;
	if (s == "SAT") cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 256
N,M,X,Y=map(int,input().split())
# N:Aの入力される座標数
# M:Bの入力される座標数
# X:Aの座標
# Y:Bの座標
x=list(map(int,input().split()))
y=list(map(int,input().split()))

if max(x)<min(y):
 for Z in range(max(x)+1,min(y)+1):
     if X<Z<=Y:
         print("No War")
         break
     else:
         print("War")
         break
else:
  print("War")

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
 char S[4];
 int N;

 for(int i=0; i < 3; i++){
  scanf("%c",&S[i]);
 }

 if(S[0] == 'S'){
   if(S[1] == 'A') N = 1;
   else N = 7;
 }
 if(S[0] == 'F') N = 2;
 if(S[0] == 'T'){
   if (S[1] == 'H')  N = 3;
   else N = 5;
 }
 if(S[0] == 'W') N = 4;
 if(S[0] == 'M') N = 6;


 printf("%d",N);

    return 0;
}


Measured memory_bytes: 128
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const ull Max = 1e18 ;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}


int main()
{

    fastread();

    ll j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

    bool flag=false;

    long double bb;

    cin>>a>>bb;

   // aa=(aa*bb);

     long long int ans=(long double)a*bb;

     double bc=bb;

     long long ac=a;

      l=(double) (ac*bb);

      ans=min(l,ans);



   cout<<ans<<endl;

}



Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(N)
*/
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(n / i);
        }
    }
    return ret;
}

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n+1);
  long long ans=0;
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j+=i){
      a[j]++;
    }
  }
  for(long long i=1;i<=n;i++){
    ans+=i*a[i];
  }
    cout << ans << endl;
}
  


Measured memory_bytes: 42344
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

int main(){
	const char oct[] = {'0','1','2','3','5','7','8','9'};
	ll n;
	while(~scanf("%lld",&n)){
		if(n==0) break;
		char buf[11];
		sprintf(buf,"%llo",n);

		for(int i=10;i>=0;i--){
			if(buf[i]-'0' < 0 || buf[i]-'0' >= 8) continue;
			buf[i] = oct[buf[i]-'0'];
		}
		printf("%s\n",buf);
	}
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b)
    {
        swap(a, b);
    }
    for (int i = 0; i < b; i++)
    {
        cout << a;
    }
    cout << endl;
}


Measured memory_bytes: 256
def main():
    [A, B] = [int(number) for number in input().split()]

    raw = (B - 1) / (A - 1)
    ans = int((B - 1) / (A - 1))
    if raw == ans:
        print(ans)
    else:
        print(ans + 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <queue>
#define int long long
using namespace std;
const int N = 105;
queue<int> q;
pair<int, int> res;
int n, head[N], tot, dep[N], mx[N], deg[N];
struct node{int to, nex;}a[N << 1];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
void add(int x, int y) {a[++ tot].to = y; a[tot].nex = head[x]; head[x] = tot;}
int dfs(int x, int fa)
{
	int rt = 0;
	for(int i = 1; i <= n; i ++) dep[i] = 0;
	q.push(x); dep[x] = 1;
	if(fa) q.push(fa), dep[fa] = 1;
	while(!q.empty())
	{
		int x = q.front(); q.pop(); mx[dep[x]] = max(mx[dep[x]], deg[x]); rt = max(rt, dep[x]);
		for(int i = head[x]; i; i = a[i].nex)
		{
			int y = a[i].to; if(dep[y]) continue;
			dep[y] = dep[x] + 1; q.push(y);
		}
	}
	return rt;
}
void work(int x, int fa)
{
	pair<int, int> rt;
	for(int i = 1; i <= n; i ++) mx[i] = 0;
	int em = dfs(x, fa); rt = make_pair(em, mx[1] - (fa != 0));
	for(int i = 2; i <= n; i ++)
	{
		if(mx[i] == 1) break;
		rt.second *= (mx[i] - 1);
	}
	if(fa) rt.second *= 2; if(rt < res) res = rt;
}
signed main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read();
	for(int i = 1, x, y; i <= n - 1; i ++) {x = read(); y = read(); add(x, y); add(y, x); deg[x] ++; deg[y] ++;}
	if(n == 2) {printf("%d %d\n", 1, 2); return 0;}
	res.first = N;
	for(int i = 1; i <= n; i ++) 
	{
		work(i, 0);
		for(int j = head[i]; j; j = a[j].nex) work(i, a[j].to);
	}
	printf("%lld %lld\n", res.first, res.second);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut a: Vec<i64> = sc.vec(n + 1);
    let mut b: Vec<i64> = sc.vec(n);
    let mut ans: i64 = 0;
    for i in 0..n {
        let d = min!(a[i], b[i]);
        a[i] -= d;
        b[i] -= d;
        ans += d;
        let d = min!(a[i + 1], b[i]);
        a[i + 1] -= d;
        b[i] -= d;
        ans += d;
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 12272
/* Atcoder abc147b
 * See tasks at: https://atcoder.jp/contests/abc147/tasks/abc147_b
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
int main()
{
    string s;
    cin >> s;
    size_t n = s.size() / 2;    

    auto r = s;
    reverse(r.begin(), r.end());

    size_t c = 0;
    for (int i=0; i < n; i++)
    {
        if (s[i] != r[i])
            c++;
    }

    cout << c;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc136_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<ll> c(N);
  vector<bool> b(N, false);
  rep(i, N) { cin >> c[i]; }

  if (c.size() == 1) {
    cout << "Yes" << endl;
    return 0;
  }

  bool ok = true;
  int min = c[0] - 1;
  rep(i, N - 1) {
    if (c[i] > c[i + 1]) {
      if (c[i] - c[i + 1] > 1 || c[i + 1] < min) {
        ok = false;
        break;
      } else {
        min = c[i + 1];
      }
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3968
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:https://www.ioi-jp.org/joi/2007/2008-yo-prob_and_sol/2008-yo-t5/2008-yo-t5.html>
 問題文============================================================
 縦 R (1<=R<=10), 横 C(1<=C<=10000)の1or0の盤面が与えられる
 最初に縦の行をいくつか選択し、その行の0,1を反転させる。
 そののち、縦の列をいくつか選択し、その列の0,1を反転させる
 
 操作終了時の1の最大数を求める
 =================================================================
 解説=============================================================
 
 どの行をひっくり返すかに関しては制約が10と小さいので2^10=1024の全通りが試せる
 列についてはその各列に1が過半数あれば裏返さなくてよく、なければ裏返せばいいのでO(RC)
 で求まる
 よって O(2^R * RC) := O(10^8)
 ================================================================
 */
vector<vector<int>> masu;
vector<int> Inv;
int R,C;
int dfs(int r){
    int res = 0;
    if(r == R){
        for(int i = 0; i < C;i++){
            int tmp = 0;
            for(int j = 0; j < R;j++){
                if(masu[j][i] == 1 && Inv[j] == 0){
                    tmp++;
                    continue;
                }
                if(masu[j][i] == 0 && Inv[j] == 1){
                    tmp++;
                    continue;
                }
            }
            res += max(tmp,R-tmp);
        }
        return res;
    }
    Inv[r] = 0;
    res = max(res,dfs(r+1));
    Inv[r] = 1;
    res = max(res,dfs(r+1));
    
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    while(cin >> R >> C,R){
    masu.assign(R,vector<int>(C,0));
    Inv.assign(R,0);
    for(int i = 0; i < R;i++){
        for(int j = 0; j < C;j++){
            cin >> masu[i][j];
        }
    }
    cout << dfs(0) << endl;
    }
    return 0;
}



Measured memory_bytes: 3432
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int happy = 0;
        
        while(X>0){
            if(X>=500){
                happy+=1000;
                X-=500;
            }else{
                break;
            }
        }
        
        happy+=(X/5)*5;
        
        System.out.println(happy);
    }
}


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

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

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


int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> a(N);
    ll g = 1;
    rep(i, N) {
        cin >> a[i];
        g = lcm(g, a[i]/2);
    }

    bool ok = true;
    rep(i, N) {
        ll tmp = g/(a[i]/2);
        if (tmp%2 == 0) ok = false;
    }

    if (ok) cout << (M/g) - (M/g/2) << endl;
    else cout << 0 << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
  bool judge = true;
  for (int i = 0; i < N; i++) {
    if (A.at(i) % 2 == 0) {
      if (A.at(i) % 3 != 0 && A.at(i) % 5 != 0) judge = false;
    }
  }
  
  if (judge) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
cnt = 0
if N == 1 and M == 1:
    cnt = 0
elif N >= 2 and M <= 1:
    cnt = int((N*(N-1))/2)
elif N <= 1 and M >= 2:
    cnt = int((M*(M-1))/2)
else:
    cnt = int((N*(N-1))/2) + int((M*(M-1))/2)
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
#define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
#define inf 3e15
    
const int N=1e3+1;
const int M=1e9+7;

void solve()
{
	int x;
	cin>>x;
	vector<int> v;
	for(int i=0;i<N;i++)
	{
		int xx=(i*i);
		xx=xx*xx;
		xx=xx*i;
		v.pb(xx);
	}
	int n=v.size();
	for(int i=0;i<n;i++)
	{
		// cout<<v[i]<<" ";
		int pp=v[i];
		int tt=pp-x;
		// cout<<tt<<" ";
		if(tt>=0)
		{
			int yy=lower_bound(all(v),tt)-v.begin();
			if(yy!=n && v[yy]==tt)
			{
				cout<<i<<" "<<yy<<endl;
				return;
			}
			
		}
		else
		{
			tt=tt*(-1);
			int yy=lower_bound(all(v),tt)-v.begin();
			// cout<<i<<" "<<yy<<endl;
			if(yy!=n && v[yy]==tt)
			{
				cout<<i<<" "<<(yy*(-1))<<endl;
				return;
			}
		}
	}
}
signed main()  
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}


Measured memory_bytes: 3664
#https://atcoder.jp/contests/abc093/tasks/arc094_a

import numpy
data = list(map(int, input().split()))
cost = 0

max_index = numpy.argmax(data)
m = data.pop(max_index)
if abs(data[0]-data[1])%2 == 1:
    cost += 2
cost += (abs(data[0]-data[1])//2 + m - max(data))
print(cost)


Measured memory_bytes: 12488
#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
#define ll long long
int b[maxn],n;
int K;
int bt[maxn][33];
int num[33];
ll ans;
int jd[33];
void cal(int p)
{
    ll ret=0;
    for(int i=1;i<=n;++i)
    {
        bool ok=true;
        for(int j=0;j<=p;++j)
            if(jd[j]<bt[i][j])
            {
                ok=false;
                break;
            }
        if(ok) ret+=b[i];
    }
    ans=max(ans,ret);
}
int main()
{
    scanf("%d%d",&n,&K);
    for(int i=0;i<30;++i)
    {
        num[29-i]=jd[29-i]=K&1;
        K>>=1;
    }
    for(int i=1;i<=n;++i)
    {
        scanf("%d%d",&K,&b[i]);
        for(int j=0;j<30;++j)
        {
            bt[i][29-j]=K&1;
            K>>=1;
        }
    }
    cal(29);
    for(int i=0;i<29;++i)
    {
        if(num[i])
        {
            jd[i]=0;
            cal(i);
            jd[i]=1;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 13568
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        q: usize,
        edges: [(usize, usize); n - 1],
        addition: [(usize, usize); q],
    }
    let mut parents: Vec<Option<usize>> = vec!(None; n);
    for edge in edges {
        parents[edge.1 - 1] = Some(edge.0 - 1);
    }
    let mut additions: Vec<usize> = vec!(0; n);
    for add in addition {
        additions[add.0 - 1] += add.1;
    }
    let mut memo: Vec<Option<usize>> = vec!(None; n);

    for i in 0..n {
        let mut ans = 0;
        let mut cursor = i;
        loop {
            if let Some(memo) = memo[cursor] {
                ans += memo;
                break;
            }
            ans += additions[cursor];
            cursor = match parents[cursor] {
                Some(cursor) => cursor,
                None => {
                    break;
                }
            }
        }
        memo[i] = Some(ans);
        println!("{} ", ans);
    }
}


Measured memory_bytes: 16804
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, D;
    cin >> N >> D;
    int X[N][D];
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin >> X[i][j];
        }
    }
    
    double d = 0.; 
    int tmp, count = 0;
    for(int i=0;i<N;i++){
        for(int j=0;j<i;j++){
            for(int k=0;k<D;k++){
               tmp = X[i][k] - X[j][k];
               d += tmp * tmp;
            }
            d = sqrt(d);
            if(d == floor(d)) count++;
            d = 0.;
        }
    }

    cout << count << "\n";
}


Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){

	int N,tmp;
	cin>>N;
	int ret=0;
	vector<int> A;
	map<int, bool> mp;
	for(int i=0;i<N;i++){
		cin>>tmp;
		A.push_back(tmp);
		if(i%2==0){
			mp[A[i]]=true;
		}else{
			mp[A[i]]=false;
		}
	}
	sort(A.begin(),A.end());
	for(int i=0;i<N;i++){
		if(i%2==0 && mp[A[i]]==false){
			ret++;
		}
	}
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    if(s[0]!=s[1]&&s[1]!=s[2]&&s[2]!=s[0]){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    T = input()

    for _ in range(len(S)):
        S = S[-1] + S[:-1]
        if S == T:
            print('Yes')
            exit()
    print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import sys
def input(): return sys.stdin.readline().rstrip()
def multi_mat(M1,M2,n,mod=10**9+7):
    ans=[[0]*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                ans[i][j]=(ans[i][j]+M1[i][k]*M2[k][j])%mod
    return ans
def pow_mat(M,k,n,mod=10**9+7):
    ans=[[0]*n for _ in range(n)]
    for i in range(n):ans[i][i]=1
    while k:
        if k%2:ans=multi_mat(ans,M,n,mod)
        M=multi_mat(M,M,n,mod)
        k//=2
    return ans

def main():
    n,k=map(int,input().split())
    A=[[int(_) for _ in input().split()] for i in range(n)]
    mod=10**9+7
    Ax=pow_mat(A,k,n,mod)
    print(sum(sum(x)%mod for x in Ax)%mod)

if __name__=='__main__':
    main()

Measured memory_bytes: 42300
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

int main() 
{
	fast;
	ll N,M,x,y; cin>>N>>M;
	vector<ll>*graph = new vector<ll>[N+1];
	for(ll i = 0; i < M; i++)
	{
		cin>>x>>y;
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	for(ll i = 1; i <= N; i++)
	{
		cout << graph[i].size() << endl;
	}
 	return 0;
}

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

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define scin(a) scanf("%d",&a);
#define scdo(a) scanf("%lf",&a);
#define scch(a) scanf("%s",a);
#define anin(a) printf("%d\n",a);
#define ando(a) printf("%lf\n",a);
#define anch(a) printf("%s\n",a);

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(void){
	int ans;
	char S[3],T[3];
	scch(S)
	scch(T)
	rep(i,0,3){
		if(S[i] == T[i]) ans ++;
	}
	anin(ans)
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    for(;;){
        int w,d;cin>>w>>d;
        if(w==0&&d==0)break;
        int h[w],hh[d];
        map<int,int> mp;
        int ans=0;
        rep(i,0,w){
            cin>>h[i];
            ans+=h[i];
            mp[h[i]]++;
        }
        rep(i,0,d){
            cin>>hh[i];
            ans+=hh[i];
            if(mp[hh[i]]>0){
                mp[hh[i]]--;
                ans-=hh[i];
            }
        }
        cout<<ans<<endl;
    }
}





Measured memory_bytes: 3092
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

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

    vector<pair<int, int>> pos(N);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        pos[i] = pair<int, int>(x, y);
    }

    vector<int> indices(N);
    for (int i = 0; i < N; i++) {
        indices[i] = i;
    };

    double sum = 0.0;
    int cnt = 0;
    do {
        cnt++;
        for (int n = 1; n < N; n++) {
            int i = indices[n - 1];
            int j = indices[n];
            // cout << "xi: " << pos[i].first << ", yi: " << pos[i].second << endl;
            sum += sqrt((pos[i].first - pos[j].first) * (pos[i].first - pos[j].first) + (pos[i].second - pos[j].second) * (pos[i].second - pos[j].second));
        }
    } while (next_permutation(indices.begin(), indices.end()));

    printf("%.10f\n", sum / cnt);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    rep(i,n-1)a[i+1]^=a[i];
    ll ans=1;
    vector<ll> ret1(1<<20),ret0(1<<20,1),cnt(1<<20,0);
    ll res=a[n-1];
    int x=0;
    rep(i,n){
        if(a[i]==0){
            ++x;
        }
        else {
            (ret0[a[i]]+=ret1[a[i]]*(x-cnt[a[i]]))%=mod;
            (ret1[a[i]]+=ret0[a[i]])%=mod;
            cnt[a[i]]=x;
        }
    }
    if(res)cout<<ret0[res]<<endl;
    else {
        rep(i,x-1)ans=2*ans%mod;
        rep(i,1<<20){
            ans+=ret1[i];
        }
        cout<<ans%mod<<endl;
    }

    return 0;
}

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

char chbig(char c){return c-32;}

int main(){
  string a,b,c;cin >> a >> b >> c;
  cout << chbig(a[0]) << chbig(b[0]) << chbig(c[0]) << endl;
  return 0;
}

Measured memory_bytes: 256
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
#import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""


def main():
    N, K = map(int, input().split())
    if N > K:
        a = N % K
        b = abs(a - K)
        c = abs(b - K)
        print(min(b, c))
    else:
        b = abs(N - K)
        c = abs(b - K)
        print(min(b, c))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<iostream>
 
int main() {
	unsigned short a;
	unsigned short b;
	a = 0;
	b = 0;
	std::cin >> a >> b;
	//6~12
	if (a <= 12 && a >= 6) std::cout << b / 2;
	//5以下
	else if (a <= 5)std::cout << 0;
	else std::cout << b;
  return 0;
}

Measured memory_bytes: 256
program main
  implicit none
  
  integer :: i,j,k,a,b,c,x,cou=0
  
  read(*,*)a
  read(*,*)b
  read(*,*)c
  read(*,*)x
  
  do i = 0, a
    do j = 0, b
      do k = 0, c
        if ((500*i+100*j+50*k) == x) then
          cou = cou + 1
        end if
      end do
    end do
  end do
  
  write(*,*)cou
end program main
          

Measured memory_bytes: 512
#include <iostream>

using namespace std;

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

    int D = 0;
    int i=0;
    for(i=0; D<=X; i++){
        if(i==N) {
            i++;
            break;
        }
        D += L[i];
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]
xyz = [[int(i) for i in input().split()] for _ in range(n)]

ans = 0
a = [0]*3
for a[0] in range(-1, 2, 2):
    for a[1] in range(-1, 2, 2):
        for a[2] in range(-1, 2, 2):
            d = list(map(lambda x: sum([i * j for i, j in zip(a, x)]), xyz))
            d.sort(reverse=1)

            ans = max(ans, sum(d[:m]))
print(ans)


Measured memory_bytes: 43120
# -*- coding: utf-8 -*-
import sys

sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
S=[input() for i in range(N)]
for a in ['AC','WA','TLE','RE']:
    c=0
    for s in S:
        if s==a:
            c+=1
    print(a+' x '+str(c))

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

using namespace std;

const int MOD = 1e9 + 7;

int dp[310][310][310];
vector<int> cond[310];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> l(m), r(m), x(m);
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> r[i] >> x[i];
		cond[r[i]].push_back(i);
	}
	dp[0][0][0] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (j != 0 && j == i) continue;
			for (int k = 0; k <= n; k++) {
				if (k != 0 && (k == i || k == j)) continue;
				int cmax = max({i, j, k});
				for (int idx : cond[cmax]) {
					int cnt = 0;
					cnt += (l[idx] <= i);
					cnt += (l[idx] <= j);
					cnt += (l[idx] <= k);
					if (cnt != x[idx]) dp[i][j][k] = 0;
				}
				(dp[cmax + 1][j][k] += dp[i][j][k]) %= MOD;
				(dp[i][cmax + 1][k] += dp[i][j][k]) %= MOD;
				(dp[i][j][cmax + 1] += dp[i][j][k]) %= MOD;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != 0 && i == j) continue;
			(ans += dp[n][i][j]) %= MOD;
			(ans += dp[i][n][j]) %= MOD;
			(ans += dp[i][j][n]) %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 114944