akhauriyash/Code-Regression huggingface dataset:
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_tpl):
        self.faces = str_tpl

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return True
        return False


str_tpl1 = tuple(input().split())
dice1 = Dice(str_tpl1)

str_tpl2 = tuple(input().split())
dice2 = Dice(str_tpl2)

if dice1.is_same(dice2):
    print('Yes')
else:
    print('No')

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  string s;
  cin >> s;
  vector<bool> dp(s.size() + 1, false);
  dp[0] = true;
  for (int i = 0; i < s.size(); i++) {
    if (!dp[i]) continue;
    if (s.substr(i, 5) == "dream") dp[i + 5] = true;
    if (s.substr(i, 7) == "dreamer") dp[i + 7] = true;
    if (s.substr(i, 5) == "erase") dp[i + 5] = true;
    if (s.substr(i, 6) == "eraser") dp[i + 6] = true;
  }
  cout << (dp[s.size()] ? "YES" : "NO") << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 512
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
num = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        A, B = X[i], X[j]
        d = math.sqrt(sum([(A[k] - B[k]) ** 2 for k in range(D)]))
        if abs(d - int(d)) < 10 ** (-4):
            num += 1
print(num)

Measured memory_bytes: 9380
object Main extends App {
  import scala.io.StdIn._

  val Array(n, _) = readLine.trim.split(' ').map(_.toInt + 1)
  val cake = readLine.trim.split(' ').map(_.toInt).sum
  println(
    if (cake % n == 0) cake / n
    else cake / n + 1
  )
}


Measured memory_bytes: 44132
n = gets.split[0].to_i
c = gets.split.map(&:to_i).select {|i| i <= n}
m = (0..n+1).to_a
c.each {|e| m[e]=1 }

(2..n).each do |i|
  c.each {|j| m[i] = m[i-j]+1 if j <= i && m[i-j]+1 < m[i] } if m[i] >= 2
end

puts m[n]

Measured memory_bytes: 9108
#include <bits/stdc++.h> 
using namespace std; 
int a[1000000];
int main() 
{ 
    map<long long ,long long >m;
   int n;
   cin>>n;
   long long x;
   //cin>>x;
   for(int i=0;i<n;i++){
       cin>>x;
       a[i]=x;
       m[x]++;
   }long long sum=0;
   for(int i=1;i<=n;i++){
       sum+=(m[i]*(m[i]-1))/2;
       //cout<<sum<<" "<<m[i]<<"\n";
   }//cout<<"\n";cout<<sum;
   for(int i=0;i<n;i++){
      // cout<<m[a[i]]<<" ";
       cout<<sum-max((long long )0,m[a[i]]-1)<<"\n";
   }
} 

Measured memory_bytes: 15872
/*input
CSS
CSR
hooded_sweater   
*/

#include <bits/stdc++.h>
using namespace std;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#define debug(...) cout << "debug: " << #__VA_ARGS__ " = "; _dbg(__VA_ARGS__);
#define debuga(arr, n) _dbga(arr, n, #arr)
typedef long long int ll;
#define int ll
#define F first
#define S second
#define float double
const int inf = LLONG_MAX;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int mod = 1e9+7;
const int N = 1e6+1;

using namespace std;
int32_t main()
{
    fast_io();
    string s,t;
    cin >> s;
    cin >> t;
    int ans = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i] == t[i]){
            ans++;
        }
    }
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const* argv[])
{
    int a, b, k;
    std::cin >> a >> b >> k;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int L, R, d;
  cin >> L >> R >> d;
  int ans = 0;
  for (int i = L; i <= R; i++){
    if (i % d == 0){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long xx,yy;
	long long ans=0;
	cin>>xx>>yy;
	if(xx*yy==1) {cout<<1<<endl;return 0;}
	if(xx==2||yy==2) {cout<<0<<endl;return 0;}
	if(xx==1) {cout<<yy-2<<endl;return 0;}
	if(yy==1) {cout<<xx-2<<endl;return 0;}
	ans=(xx-2)*(yy-2);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int v[10][10];
int N,c;

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

bool done[10][10] = {0};
bool chk(int x,int y,int num,int &c){
	if(y < 0 || x >= y+1 || x < 0 || y >= N) return false;	
	if(!v[y][x])return true;
	if(num != v[y][x])return false;
	if(done[y][x])return false;
	else done[y][x] = true;
	c++;
	bool ans = false;
	rep(i,6) ans |= chk(x+dx[i],y+dy[i],num,c);
	return ans;
}


void cl(){
	rep(i,10)rep(j,10)done[i][j] = false;
}
void init(int t[10][10]){
	rep(i,10)rep(j,10)v[i][j] = t[i][j];
}

int sim(int t[10][10],int c){
	int ans = -(1<<21);
	rep(i,N){
		rep(j,i+1){
			int sum = 0;
			init(t);
			cl();
			if( t[i][j] ) continue;
			v[i][j] = c;
			int a=0;
			
			if( !chk(j,i,v[i][j],a) ) sum -= 2*a;
			cl();

			rep(y,N)rep(x,y+1){
				if( done[y][x] || !v[y][x])continue;
				int b = 0;
				if( !chk(x,y,v[y][x],b) )sum += b;
				//cout << v[y][x] << " " << b << endl;
			}
			ans = max(ans,sum);
		}
	}
	return ans;
}

int main(){
	while(cin >> N >> c,N){
		int t[10][10];
		rep(i,N)rep(j,i+1)	cin >> t[i][j];
		cout << sim(t,c) << endl;
	}
}

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

LL mod = 1000000007;

int main()
{
	LL n, m;
	cin >> n >> m;

	vector<pair<LL, string>> d(m);

	for (auto &e : d) {
		cin >> e.first >> e.second;
	}


	vector<LL> done(n, 0);

	LL ac = 0;
	LL cnt = 0;
	for (LL i = 0; i < m; ++i) {
		LL f= d[i].first-1; string s = d[i].second;
		if (!done[f]) {
			if (s == "AC") {
				done[f] = 1;
				ac++;
			}
			else {
				cnt++;
			}
		}
	}
	for (LL i = 0; i < m; ++i) {
		LL f= d[i].first-1; string s = d[i].second;
		if (!done[f]) {
			cnt --;
		}
	}
	cout << ac << " " << cnt << endl;
}

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

int main()
{
 	char c1[3];
  	char c2[3];
  	cin >> c1;
  	cin >> c2;
  	if(c1[0] != c2[2])
      cout << "NO";
  	else if(c1[1] != c2[1])
      cout << "NO";
  	else if(c1[2] != c2[0])
      cout << "NO";
  	else
      cout << "YES";
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5)

n,m=map(int,input().split())
g=[[] for i in range(10**5+10)]
for i in range(m):
  a,b=map(lambda x:int(x)-1, input().split())
  g[a].append(b)
  g[b].append(a)
chk=[-1]*n

def dfs(s,cnt):
  for u in g[s]:
    if chk[u]>-1: continue;
    chk[u]=cnt
    dfs(u,cnt)

cnt=0
for i in range(n):
  if chk[i]==-1:
    chk[i]=cnt
    dfs(i,cnt)
    cnt+=1
    
print(max(chk))

Measured memory_bytes: 48380
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    
    vector<int> A(N,0);
    for(int i=1;i<N;++i){
        int a;
        cin>>a;
        --a;
        ++A[a];
    }
    
    for(int i=0;i<N;++i) cout<<A[i]<<endl;
}


Measured memory_bytes: 4048
from heapq import heappush, heappop

INF = float("inf")

N, M, *LRC = map(int, open(0).read().split())

E = [[] for _ in range(N)]
for i in range(N - 1):
    E[i + 1].append((i, 0))
for l, r, c in zip(*[iter(LRC)] * 3):
    E[l - 1].append((r - 1, c))

D = [INF] * N
D[0] = 0

Q = [0]
while Q:
    t = heappop(Q)
    dist, cur = divmod(t, N)
    for nxt, cost in E[cur]:
        cand = dist + cost
        if D[nxt] > cand:
            D[nxt] = cand
            heappush(Q, cand * N + nxt)

print(-1 if D[N - 1] == INF else D[N - 1])

Measured memory_bytes: 50164
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 
 using namespace std;
 
 long long int min(long long int a,long long int b)
 {
   if(a<b) return a;
   else return b;     
 }
 
 int main()
 {
   long long int q,h,s,d;
   long long int n;
   long long int result;
   while(cin>>q>>h>>s>>d>>n)
   {
     long long int special=d;
     long long int kk=min(s,min(q*4,2*h));
     if(special<(2*kk))
     {
       if(n%2==0) result=(special*n/2);
       else result=((n-1)/2)*special+kk;                            
     }    
     else
     {
       result=n*kk;      
     }                     
     cout<<result<<endl;
   }
   return 0;    
 }
 
 

Measured memory_bytes: 256
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int;  // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

void comb(int X, int M, vector<vector<int>>& A, vector<int>& C, vector<int>& h, int first, int end, int index, int& ans) {
  if (index == h.size()) {
    int sum = 0;
    // アルゴリズム理解度たりてるかチェック
    // 足りてないなら　returnする
    vector<int> s(M, 0);
    for (int i = 0; i < h.size(); ++i) {
      for (int j = 0; j < M; ++j) {
        s[j] += A[h[i]][j];
      }
    }

    for (auto v : s) {
      if (v < X) return;
    }

    // cout << endl;

    // for (auto v : s) {
    //   cout << v << "||";
    // }
    // 合計金額チェック ansと比較する
    int mon = 0;
    for (int i = 0; i < h.size(); ++i) {
      mon += C[h[i]];
    }

    if (mon < ans) {
      ans = mon;
    }

    return;
  }

  for (int i = first; i <= end; ++i) {
    h[index] = i;
    comb(X, M, A, C, h, i + 1, end + 1, index + 1, ans);
  }
}

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));

  for (int i = 0; i < N; ++i) {
    cin >> C[i];
    for (int j = 0; j < M; ++j) {
      cin >> A[i][j];
    }
  }
  // 全パターン網羅する
  // vector<int> A(2);
  // comb(A, 0, 2, 0);
  int ans = 1e9;

  for (int i = 1; i <= N; ++i) {
    vector<int> tmp(i);
    comb(X, M, A, C, tmp, 0, N - i, 0, ans);
  }

  if (ans == 1e9) {
    cout << -1 << endl;
    return 0;
  }

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


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define ulli unsigned long long int
#define ld long double  
#define endl "\n"
using namespace std; 

void solve() {
    int n;
    cin >> n;

    unordered_map<int, int> m;
    int temp;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        m[temp] = i+1;
    }

    for (int i = 0; i < n; i++) {
        cout << m[i+1] << " ";
    }
    cout << endl;
}

int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
  
    int t = 1; 
    //cin >> t; 
    while (t--) { 
        solve(); 
    } 
  
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
    return 0; 
} 


Measured memory_bytes: 4900
using System;

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            if(s.Length <= k)
            {
                Console.WriteLine(s);
            }
            else
            {
                var ans = s.Substring(0,k) + "...";
                Console.WriteLine(ans);
            }
        }
    }
}

Measured memory_bytes: 27432
#include <iostream>
#include <bitset>

using namespace std;

const int N = 10000000;

int main(int argc, char *argv[])
{
  for(;;) {
    int m, n;
    cin >> m >> n;
    if(n == 0 && m == 0) break;
    bitset<N> bs;
    for(int i = 0; i < m; i++) {
      bs[i] = true;
    }
    for(int j = 0; j < n; m++) {
      if(bs[m]) continue; 
      for(int i = m; i < N; i+=m) {
        bs[i] = true;
      }
      j++;
    }
    for(int i = 0; i < N; i++) {
      if(!bs[i]) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4288
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;
const int mod=1e9+7;
ll ad(ll x,ll y)
{
    ll ret;
    ret=(x%mod)+(y%mod);
    if(ret<0)ret+=mod;
    ret=ret%mod;
    return ret;
}
inline bool checkBit(ll n, int i) { return n&(1LL<<i); }

ll mult(ll a, ll b) {
ll ret = (a%mod)*(b%mod);
if(ret >= mod) ret %= mod;
return ret;
}
int o[70],z[70];
main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n,x;
  cin>>n;
  for(int i=0;i<n;i++)
  {
      cin>>x;
      for(int j=0;j<=61;j++)
      {
          if(checkBit(x,j))o[j]++;
          else z[j]++;
      }
  }
   int ses=0;
   for(int i=0;i<=61;i++)
   {
       ses=ad(ses,mult(z[i]*o[i],(1LL<<i)));
   }
   cout<<ses<<endl;

return 0;
}














































Measured memory_bytes: 256
#include <stdio.h>
int rot[5][7]={{0,1,2,3,4,5,6},{0,2,6,3,4,1,5},{0,4,2,1,6,5,3},{0,3,2,6,1,5,4},{0,5,1,3,4,6,2}};
int assign[7];
int tr['Z'];
void dice_init(int*a){
    int i;
    int t[5]={0,'N','E','W','S'};
    for(i=1;i<=6;i++)assign[i]=a[i];
    for(i=1;i<=4;i++)tr[t[i]]=i;}
    
char s[102];
int main (){
    int i,k1,k2;
    int a[7],dice[2][7];
    char*p;
    for(i=1;i<=6;i++)scanf("%d",a+i);
    dice_init(a);
    scanf("%s",p=s);
    for(i=1;i<=6;i++)dice[0][i]=rot[0][i];
    for(k1=0,k2=1;*p;k1=k2,k2=!k2){
        for(i=1;i<=6;i++)dice[k2][i]=dice[k1][rot[tr[*p]][i]];
        p++;
    }
    printf("%d\n",assign[dice[k1][1]]);
    return 0;
}



Measured memory_bytes: 2068
/*
 * Author : Sadi
 * Sat 04/07/2020
 * 18:26:42.02
 */
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;
map<int, int> mp;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        for(int i = 0; i < k; ++i) {
            int type;
            cin >> type;
            mp[type]++;
        }
    }
    int ans = 0;
    for(auto it = mp.begin(); it != mp.end(); ++it) {
        if(it->se == n) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
	int N;
	cin >> N;
	vector<ll> a(3*N), large_a(N+1), small_a(N+1);
	priority_queue<ll> large, small;
	large_a[0] = 0; small_a[0] = 0;
	rep(3*N){
		cin >> a[i];
		if(i < N) large_a[0] += a[i];
		else if(2*N <= i) small_a[N] += a[i];
	}
	rep(N){
		large.push(-a[i]);
		small.push(a[3*N-1-i]);
	}

	reppp(i, N, 2*N-1){
		large.push(-a[i]);
		ll tmp = large.top();large.pop();
		large_a[i-N+1] = large_a[i-N] + a[i] + tmp;
	}
	for(int i=2*N-1; i>=N; i--){
		small.push(a[i]);
		ll tmp = small.top();small.pop();
		small_a[i-N] = small_a[i-N+1] + a[i] - tmp;
	}

	vector<ll> ans(N+1);
	rep(N+1){
		//cout << large_a[i] << " " << small_a[i] << endl;
		ans[i] = large_a[i] -  small_a[i];
	}
	cout << *max_element(all(ans));
}


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

int main(){

    int K;
    cin >> K;
    string S;
    cin >> S;

    if (S.size() <= K) cout << S << endl;
    else {
        cout << S.substr(0, K) + "..." << endl;
    }

    return 0;
}

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

int main()
{
    int r, D, x;
    cin >> r >> D >> x;

    for (int i = 0; i < 10; i++)
    {
        x = r * x - D;
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> a[10];
int n, m, ans;
int vis[10];

void dfs(int x, int t)
{
	if(t == n) {ans ++; return;}
	for(int i = 0; i < a[x].size(); i ++)
	{
		int y = a[x][i];
		if(vis[y]) continue;
		vis[y] = 1;
		dfs(y, t + 1);
		vis[y] = 0;
	}
}

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= m; i ++)
	{
		int x, y;
		cin >> x >> y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	vis[1] = 1;
	dfs(1, 1);
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		System.out.println(gcd(x, y));
	}

	public static int gcd(int x, int y) {

		int r = x % y;
		while (r != 0) {
			x = y;
			y = r;
			r = x % y;
		}
		return y;
	}
}

Measured memory_bytes: 17200
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define _USE_MATH_DEFINES
#define mp       make_pair
#define pb       push_back
#define fst      first
#define snd      second
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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


int main()
{
    string S; cin >> S;
    string T; cin >> T;
    reverse(S.begin(), S.end());
    reverse(T.begin(), T.end());

    rep(i, S.size()-T.size()+1) {
        for(int j = T.size()-1; j >= 0; j--) {
            if(S[i+j] != '?' && S[i+j] != T[j])
                break;
            if(j == 0) {
                rep(k, T.size())
                    S[i+k] = T[k];
                rep(k, S.size())
                    if(S[k] == '?') S[k] = 'a';
                reverse(S.begin(), S.end());
                cout << S << endl;
                return 0;
            }
        }
    }

    cout << "UNRESTORABLE" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int arr[100005];
int dpl[100005];
int dpr[100005];
int32_t main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    sort(arr, arr + n);
    if(n == 1){
        cout << 1000000000 << endl;
        return 0;
    }
    dpl[0] = arr[0];
    dpr[n - 1] = arr[n - 1];
    for(int i = 1; i < n; i++){
        dpl[i] = __gcd(dpl[i - 1], arr[i]);
        // cout << dpl[i] << " ";
    }
    // cout << '\n';
    for(int i = n - 2; i >= 0; i--){
        dpr[i] = __gcd(dpr[i + 1], arr[i]);
        // cout << dpr[i] << " ";
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        int tmp;
        if(i == 0){
            tmp = dpr[i + 1];
        }
        else{
            if(i == n - 1){
                tmp = dpl[i - 1];
            }
            else{
                tmp = __gcd(dpl[i - 1], dpr[i + 1]);
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(void)
{

        char S[100000];

        int n,a=0,b=0,i,s;

        scanf("%s",&S);
        n=strlen(S);
        for(i=0;i<n;i++){
                if(S[i]=='0')a++;
                else if(S[i]=='1')b++;
        }
        if(a>b)s=b*2;
        else s=a*2;

        printf("%d\n",s);
        return 0;
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> valid(3, -1);
  vector<ll> cnt(3, 0);
  ll v = 0;
  
  auto check = [&](ll a) -> bool {
    for (ll p = 0; p < v; p++) {
      if (valid[p] == a) {
	cnt[p]++;
	return true;
      }
    }
    if (v < 3) {
      valid[v] = a;
      cnt[v] = 1;
      v++;
      return true;
    }else {
      return false;
    }

  };

  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    if (!check(a)) {
      cout << "No\n";
      return 0;
    }
  }

  auto check2 = [&]() -> bool {
    if (v == 1) return valid[0] == 0;
    if (v == 2) {
      return (valid[0] == 0 && cnt[0] * 2 == cnt[1])
	|| (valid[1] == 0 && cnt[1] * 2 == cnt[0]);
    }
    if (v == 3) return cnt[0] == cnt[1] && cnt[1] == cnt[2]
		  && (valid[0] ^ valid[1]) == valid[2];
    assert(0);
  };
  cout << (check2() ? "Yes\n" : "No\n");

  return 0;
}



Measured memory_bytes: 3652
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc161_a solver = new abc161_a();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc161_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int Wk;

            Wk = A;
            A = B;
            B = Wk;
            Wk = C;
            C = A;
            A = Wk;
            out.print(A);
            out.print(' ');
            out.print(B);
            out.print(' ');
            out.print(C);
            out.println();
        }

    }
}



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

using namespace std;

int main(){
  int N,L,i;
  cin >> N >> L;
  int max,min;
  max=L+N-1;
  min=L;
  int total=0;
  for(i=min;i<=max;i++){
    total+=i;
  }
  if(max*min<=0){
    cout << total << endl;
    return 0;
  }
  if(total>=0){
    cout << total-min << endl;
    return 0;
  }
  else{
    cout << total-max << endl;
  }
}

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

using namespace std;

int N = 0;
int map[21][21] = { 0 }; //map[w][h]
int w, h;

int check(int cw, int ch){
//	cout << cw << "cheching" << ch << endl;
	if (  (cw >= 1) && (cw <= w) && (1 <= ch) && (ch <= h) ){
		if (map[cw][ch] == 0){
			map[cw][ch] = 2;
			N++;
			check(cw + 1, ch);
			check(cw, ch + 1);
			check(cw - 1, ch);
			check(cw, ch - 1);
		}
	}
	return(0);
}


int main(void){
	int i, j;
	int sw, sh;

	string input;
	cin >> w >> h;

	while (w != 0 && h != 0){
	
		for (i = 0; i < h; i++){
			cin >> input;
			for (j = 0; j < w; j++){
				if (input[j] == '.') map[j + 1][i + 1] = 0;
				else{	if(input[j] == '#') map[j + 1][i + 1] = 1;
						else{
							map[j + 1][i + 1] = 2;
							sw = j + 1; sh = i + 1;
						}
				}
			}
		}



		map[sw][sh] = 0;

/*		for (i = 0; i < h; i++){
			for (j = 0; j < w; j++){
				cout << map[j + 1][i + 1];
			}
			putchar('\n');
		}
		*/
		N = 0;
		check(sw,sh);

/*		for (i = 0; i < h; i++){
		for (j = 0; j < w; j++){
		cout << map[j + 1][i + 1];
		}
		putchar('\n');
		}
*/
		cout << N << endl;
		cin >> w >> h;
	}



	return(0);
}

Measured memory_bytes: 1212
H,W,A,B = map(int,input().split())
ans = [[0]*W for i in range(H)]
for i in range(A):
  for j in range(B):
    ans[j][i] = 1

for i in range(A,W):
  for j in range(B,H):
    ans[j][i] = 1

for l in ans:
  for i in l:
    print(i,end="")
  print()

Measured memory_bytes: 13300
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C


# HACK: More smartly.
def identify_a_and_b_from(grid_values):
    a = list()
    b = list()

    # Transform to equivalent expression.
    # (a1, a2, a3, b1, b2, b3)
    # = (p1 + x, p2 + x, p3 + x, q1 - x, q2 - x, q3 - x)
    # Because pi + qi = (pi + x) + (qi - x) holds.

    # It assumes that a1 = 0
    a.append(0)

    for j in range(3):
        b.append(grid_values[0][j] - a[0])

    for i in range(1, 3):
        a.append(grid_values[i][0] - b[0])
    return a, b


def satisfy_takahashi_information(grid_values, a, b):
    result = 'Yes'

    for i in range(0, 3):
        for j in range(0, 3):
            if grid_values[i][j] != a[i] + b[j]:
                return 'No'
    return result


if __name__ == '__main__':
    grid_values = [list(map(int, input().split())) for i in range(3)]

    # See:
    # https://img.atcoder.jp/abc088/editorial.pdf
    a, b = identify_a_and_b_from(grid_values)

    result = satisfy_takahashi_information(grid_values, a, b)
    print(result)


Measured memory_bytes: 3064
// 解答不能.
// aropan氏.
// https://atcoder.jp/contests/abc158/submissions/10630416
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<int, int>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define a first
#define b second
#define all(x) x.begin(), x.end()
const int MOD = 998244353;

int main(){
    int n;
    scanf("%d", &n);
    vector<P> a(n);
    rep(i, n) scanf("%d %d", &a[i].a, &a[i].b);
    sort(all(a));
    reverse(all(a));
    stack<P> st;
    st.push({2e+9 + 42, 1});
    int ans = 1;
    rep(i, n){
        int val = a[i].a + a[i].b;
        while(val > st.top().a) st.pop();
        ans = (ans + st.top().b) % MOD;
        st.push({a[i].a, ans});
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2688
#include<stdio.h>
int main(void){
	int i,j,N,k;
	int v;
	scanf("%d",&N);
	int a[N];
	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
	}

	for (i=0;i<N;i++){
		v=a[i];
		j=i-1;
		while(j>=0 && a[j]>v){
			a[j+1]=a[j];
			j--;
		}
			a[j+1]=v;
		
	for(k=0;k<N-1;k++){
		printf("%d ",a[k]);
	}
	printf("%d\n",a[N-1]);
	}
	return 0;
}

Measured memory_bytes: 600
from collections import defaultdict
from math import gcd
mod = 10**9+7
n = int(input())
dic = defaultdict(lambda:[[0,0],[0,0]])
zero = [0,0]
zerozero = 0
for i in range(n):
    a,b = map(int,input().split())
    if a == 0 or b == 0:
        if a == 0 and b == 0:
            zerozero += 1
            continue
        else:
            if a == 0:
                zero[0] += 1
            else:
                zero[1] += 1
        continue
    minus = False
    rev = False
    if a * b < 0:
        minus = True
    a,b = abs(a),abs(b)
    g = gcd(a,b)
    a,b = a//g,b//g
    if a > b:
        a,b = b,a
        rev = True
    if minus:
        if rev:
            dic[(a,b)][0][1] += 1
        else:
            dic[(a,b)][0][0] += 1
    else:
        if rev:
            dic[(a,b)][1][1] += 1
        else:
            dic[(a,b)][1][0] += 1
ans = 1
for y in dic.keys():
    x = dic[y]
    if y == (1,1):
        ans *= 2**sum(x[0])+2**sum(x[1])-1
    else:
        ans *= 2**x[0][1]+2**x[1][0]-1
        ans *= 2**x[0][0]+2**x[1][1]-1
        ans %= mod
ans *= 2**zero[0]+2**zero[1]-1
ans += zerozero
ans %= mod
ans += 10**9+6
ans %= mod
print(ans)

Measured memory_bytes: 166568
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,a,b;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++)
    A[i]=2e7;
  int B[n];
  for(int i=0;i<n;i++)
    cin>>B[i];
  A[0]=0;
  A[1]=B[1]-B[0];
  if(A[1]<0)
  A[1]*=-1;
  for(int i=2;i<n;i++)
  {
    
    a=B[i]-B[i-1];
    if(a<0)
    a=a*(-1)+A[i-1];
    else
    a+=A[i-1];
    
	b=B[i]-B[i-2];
    if(b<0)
    b=b*(-1)+A[i-2];
    else
    b+=A[i-2];

    A[i]=a<b?a:b;
  }
  cout<<A[n-1];
  return 0;
}

Measured memory_bytes: 1024
def main():
    MOD = 10**9 + 7
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 0
    from collections import Counter
    c = Counter(A)
    if N % 2 == 1:
        if all(v == 2 if k != 0 else v == 1 for k, v in c.items()):
            ans += pow(2, (len(c.keys())-1), MOD)
    else:
        if all(v == 2 for k, v in c.items()):
            ans += pow(2, (len(c.keys())), MOD)
    k = sorted(set(A))
    for i in range(len(c.keys())-1):
        if k[i] + 2 != k[i+1]:
            ans = 0
            break
    print(ans)


if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

LL h,w;

int main()
{
	cin>>h>>w;
	if(h==1||w==1)
	{
		cout<<1<<endl;
		return 0;
	}
	LL val=(w+1)/2,val2=w%2==1 ? val-1:val;
	cout<<val*((h+1)/2)+val2*(h/2)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
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; }
typedef long long ll;

int main()
{
    int A[3][3];
    rep(i, 0, 3) {
        cin >> A[i][0] >> A[i][1] >> A[i][2];
    }

    int N;
    cin >> N;
    int b[N];
    rep(i, 0, N) {
        cin >> b[i];
    }

    bool exist = false;


    // tate
    rep(i, 0, 3) {
        int sum = 0;
        rep(j, 0, 3) {
            rep(k, 0, N) {
                if (A[i][j] == b[k]) {
                    sum++;
                    break;
                }
            }
        }
        if (sum == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    // yoko
    rep(i, 0, 3) {
        int sum = 0;
        rep(j, 0, 3) {
            rep(k, 0, N) {
                if (A[j][i] == b[k]) {
                    sum++;
                    break;
                }
            }
        }
        if (sum == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    // naname
    bool x = false, y = false, z = false;
    rep(i, 0, N) {
        if (A[0][2] == b[i]) x = true;
        if (A[1][1] == b[i]) y = true;
        if (A[2][0] == b[i]) z = true;
    }
    
    if (x && y && z) {
        cout << "Yes" << endl;
        return 0;
    }

    x = false, y = false, z = false;
    rep(i, 0, N) {
        if (A[0][0] == b[i]) x = true;
        if (A[1][1] == b[i]) y = true;
        if (A[2][2] == b[i]) z = true;
    }
    if (x && y && z) {
         cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;
}

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

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

using namespace std;

using int64 = int64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i, h) {
    cin >> a[i];
  }
  const int mx = 205;
  vector<vector<int>> dp(h, vector<int>(w, mx));
  rep(i, h) {
    rep(j, w) {
      if (i == 0 && j == 0) dp[0][0] = (a[0][0] == '#');
      if (i > 0)
        dp[i][j] = min(dp[i][j],
                       dp[i - 1][j] + (a[i - 1][j] == '.' && a[i][j] == '#'));
      if (j > 0)
        dp[i][j] = min(dp[i][j],
                       dp[i][j - 1] + (a[i][j - 1] == '.' && a[i][j] == '#'));
    }
  }
  cout << dp[h - 1][w - 1];
  return 0;
}

Measured memory_bytes: 3680
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main ()
{
    int s, w;
    cin >> s >> w;
    if (s <= w)
        cout << "unsafe";
    else
        cout << "safe";
}


Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <cstring>
#include <cstdlib>
#include <cctype>

#define fo(i, x, y) for (int i = x; i <= y; ++i)
#define fd(i, x, y) for (int i = x; i >= y; --i)

using namespace std;

const int maxn = 1e5 + 5;

int n, cnt, ans;
int a[maxn], b[maxn], tmpa[maxn], tmpb[maxn], fa[maxn], rank[maxn];
map<int, int> mp;

int getint() {
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && ch != '-');
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = res * 10 + ch - '0' , ch = getchar();
	return res * p;
}

int getfa(int x) {
	return fa[x]? fa[x] = getfa(fa[x]) : x;
}

void un(int x, int y) {
	int fx = getfa(x), fy = getfa(y);
	if (fx == fy) return;
	if (rank[fx] < rank[fy]) fa[fx] = fy;
		else fa[fy] = fx, rank[fy] += rank[fx] == rank[fy];
}

int main() {
	//freopen("duliu.in", "r", stdin);
	//freopen("duliu.out", "w", stdout);
	
	n = getint();
	fo (i, 1, n) tmpa[i] = a[i] = getint(), a[0] ^= a[i];
	fo (i, 1, n) tmpb[i] = b[i] = getint(), b[0] ^= b[i];
	tmpa[0] = a[0]; tmpb[0] = b[0];
	sort(tmpa, tmpa + 1 + n);
	sort(tmpb, tmpb + 1 + n);
	fo (i, 0, n)
		if (tmpa[i] != tmpb[i]) {
			printf("-1\n");
			return 0;
		}
	if (!mp[a[0]]) mp[a[0]] = ++cnt;
	if (!mp[b[0]]) mp[b[0]] = ++cnt;
	fo (i, 1, n)
		if (a[i] != b[i]) {
			ans++;
			if (!mp[a[i]]) mp[a[i]] = ++cnt;
			if (!mp[b[i]]) mp[b[i]] = ++cnt;
		}
	fo (i, 1, n)
		if (a[i] != b[i]) un(mp[a[i]], mp[b[i]]);
	fo (i, 1, cnt)
		if (!fa[i]) ans++;
	ans--;
	printf("%d\n", ans);
	return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
  	int r=0;
  	cin >> s;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R')
       r=3;
    else if((s[0]=='R' && s[1]=='R')||(s[1]=='R' && s[2]=='R'))
      r=2;
   else if(s[0]=='R' || s[1]=='R' || s[2]=='R')
     r=1;
   cout << r;
    return 0;
}

Measured memory_bytes: 3676
n, m = (int(_) for _ in input().split())
a = [int(input()) for _ in range(m)]
ai = 0

p1 = 0
p2 = 1

for i in range(1, n+1):
    if ai < m:
        if i == a[ai]:
            p = 0
            ai += 1
        else:
            p = p1 + p2
    else:
        p = p1 + p2
    p1 = p2
    p2 = p

print(p%1000000007)


Measured memory_bytes: 7080
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
static const double pi = 3.141592653589793;

int main(){
  long double a, b;
  long double h, m;
  long double rad, ans, ans2;

  cin >> a >> b >> h >> m;

  rad = 2 * pi * (h / 12 + m / 60 / 12 - m / 60);


  ans2 = pow(a, 2) + pow(b, 2) - 2 * a * b * cos(rad);
  ans = pow(ans2, 0.5);

  cout << fixed << setprecision(20) << ans << endl;

  return 0;
}


Measured memory_bytes: 4140
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int n,m,X;std::cin>>n>>m>>X;
    int a=0,b=0;
    for(int i=0;i<m;i++){
        int x;std::cin>>x;
        a+=x<X;
        b+=x>X;
    }
    std::cout<<std::min(a,b)<<std::endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		long[]	formula = null;

		while ((formula = parseFormula()) != null) {
			calc(formula);
		}
	}

	private static void calc(long[] formula) {
		String	out = "NA";
		long	x   = formula[3] - formula[1];
		long	n   = formula[0] - formula[2];

		if (x != 0L) {
			if (n % x == 0L) {
				long	res = n / x;
				if (!(res == 0L && formula[4] != 0L) && (0L <= res && res <= 9L)) {
					out = String.valueOf(res);
				}
			}
		}

		System.out.println(out);
	}

	private static long[] parseFormula() {
		long[]	formula = null;
		String	str     = null;

		if ((str = parseStdin()) != null) {
			String[]	lines = str.split("[+=]");

			formula = new long[5];

			for (int l = 0; l < lines.length; l++) {
				int		diff = (l == lines.length - 1) ? 2 : 0;
				long[]	line = parseLine(lines[l]);

				formula[0+diff] += line[0];
				formula[1+diff] += line[1];
				formula[4]      |= line[2];
			}
		}

		return formula;
	}

	private static long[] parseLine(String stdin) {
		long[]	line = new long[3];

		if (stdin != null) {
			if (!stdin.isEmpty()) {
				int	size = stdin.length();
				for (int l = size-1; l >= 0; l--) {
					char	c = stdin.charAt(l);
					long	b = (long)Math.pow(10, size - 1 - l);
					if (c == 'X') {
						line[1] += b;
						line[2]  = (l == 0 & size > 1) ? 1 : 0;
					} else {
						line[0] += (int)(c - '0') * b;
					}
				}
			}
		}

		return line;
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (tmp != null) {
            	if (!tmp.isEmpty()) {
            		stdin = tmp;
            	}
        	}
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

Measured memory_bytes: 17088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = br.readLine();
		
		char[] ch = input.toCharArray();
		for(int i = 0; i < ch.length; i++){
			if(Character.isUpperCase(ch[i])){
				ch[i] = Character.toLowerCase(ch[i]);
			}else if(Character.isLowerCase(ch[i])){
				ch[i] = Character.toUpperCase(ch[i]);
			}
			System.out.print(ch[i]);
		}
		System.out.println();

	}

}

Measured memory_bytes: 24988
from collections import deque
n=int(input())
a=list(map(int,input().split()))
b=deque([])
for i in range(n):
    if i%2==0:
        b.appendleft(a[i])
    else:
        b.append(a[i])

if n%2==0:
    b=list(b)[::-1]

print(*b)

Measured memory_bytes: 32512
S = input()
T = str(S)
A=int(T[0:2])
B=int(T[2:4])
if 1<=A<=12:
  if 1<=B<=12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if 1<=B<=12:
    print('YYMM')
  else:
    print('NA')

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

const int N=1010;
char S[N],T[N];
int ls,lt;

int main()
{
    int i,j,now,ans=N;
    cin>>S>>T;
    while(S[ls]) ls++;
    ls--;
    while(T[lt]) lt++;
    lt--;
    for(i=0;i<=ls-lt;i++)
    {
        now=0;
        for(j=0;j<=lt;j++)
            if(S[i+j]!=T[j]) now++;
        if(ans>now) ans=now;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int v[200000];
    int n;
    int tmp;
    cin>>n;
    for(int i=0;i<200000;i++){
        v[i]=0;
    }
    for(int i=2;i<=n;i++){
        cin>>tmp;
        v[tmp-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<v[i]<<endl;
    }
}


Measured memory_bytes: 4420
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

std::string solve(int n, int m, std::vector<int>& counts)
{
  auto sum = std::accumulate(counts.begin(), counts.end(), 0);
  std::sort(counts.begin(), counts.end(), [](int lhs, int rhs) { return lhs >= rhs; });
  return counts[m - 1] >= std::ceil(sum / (4.0 * m)) ? "Yes" : "No";
}

int main()
{
  int n, m;
  std::cin >> n >> m;
  std::vector<int> counts(n);
  for (auto& a : counts) {
    std::cin >> a;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, m, counts) << std::endl;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val A, B, C, X, Y = sc.nextLong()
  val sum = if (A + B < C * 2) {
    A * X + B * Y
  } else {
    val diff = X min Y
    diff * C * 2 +
      (A min (C * 2)) * (X - diff) +
      (B min (C * 2)) * (Y - diff)
  }
  println(sum)
}


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

namespace std
{
    class Test {
        static void Main(string[] args) {
       
            List<int> ary_H= new List<int>();
            List<int> ary_W= new List<int>();
           
           
            while(true) {
                var input = Console.ReadLine().Split(' ');
                var H = int.Parse(input[0]);
                var W = int.Parse(input[1]);
            
                if(H == 0 && W == 0) break;
                ary_H.Add(H);
                ary_W.Add(W);
            }        
       
            for ( int k = 0; k < ary_H.Count; k++) {
                for ( int i = 0; i < ary_H[k]; i++) {
                  
  		    for ( int j = 0; j < ary_W[k]; j++) {
                        if (i == 0 || i == ary_H[k]-1 ) {Console.Write("#");}
                        else if (j == 0 || j == ary_W[k]-1) {Console.Write("#");}
                        else { Console.Write(".");}
                    }
                     Console.WriteLine("");  //改行
                }
                 Console.WriteLine("");//空行
		
            }  
          //   Console.WriteLine("");
       
       
        }
    }
}


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

int main() {
 ll N;
 cin >> N;
 double n = sqrt(N);
 ll m = 0;
for (ll i = 1; i <= n; i++)
{
  if (N % i == 0)
  {
    m = i;
  }
}
 ll l = N/m;
 cout << l + m -2 << endl;


}

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

using namespace std;

typedef long long ll;

#define MOD 1000000007

// x^n
ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

// x^{-1}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }

int main() {
  int n, k;
  cin >> n >> k;
  ll ans = 0;
  vector<ll> cnt(k + 1);
  for (int i = k; i >= 1; --i) {
    cnt[i] = mod_pow(k / i, n);
    for (int j = 2; i * j <= k; ++j) {
      cnt[i] = (cnt[i] - cnt[i * j] + MOD) % MOD;
    }
    ll res = (cnt[i] * i) % MOD;
    ans = (ans + res) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8, pi = acos(-1.0);
bool eq(ld a, ld b){return (abs(b-a)<eps);}
ld dot(Point a, Point b){return real(conj(a)*b);}
ld cross(Point a, Point b){ return imag(conj(a)*b);}
class Line{
public:
  Point a,b;
};
Line Midependicular(const Point& a, const Point& b){
  Point normal = Point(a.imag()-b.imag(),b.real()-a.real());
  Line result;
  result.a = (b + a + normal) * 0.5L;
  result.b = (b + a - normal) * 0.5L;
  return result;
}
Point a,b,c;
void solve(){
  // center point is the cross point of 2 midperpendiculars
  Line s = Midependicular(a,b);
  Line t = Midependicular(a,c);
  Point sv=s.b-s.a,tv=t.b-t.a;
  Point result=s.a+sv*cross(tv,t.a-s.a)/cross(tv,sv);
  printf("%.3Lf %.3Lf %.3Lf\n",result.real(),result.imag(),abs(result-a));
}

int main(){ _;
  int n;cin>>n;
  REP(z,n){
    ld tmpX,tmpY;
    cin>>tmpX>>tmpY; a=Point(tmpX,tmpY);
    cin>>tmpX>>tmpY; b=Point(tmpX,tmpY);
    cin>>tmpX>>tmpY; c=Point(tmpX,tmpY);
    solve();
  }
}

Measured memory_bytes: 1272
S  = str(input())
p1 = 0
p2 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            p1 += 1
        else:
            p2 += 1
    else:
        if S[i] == '0':
            p2 += 1
        else:
            p1 += 1
print(min(p1, p2))


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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 2005;
int n, q[MX];
ll mem[MX][MX], a[MX];

ll dp (int i, int j) {
	if (i > j) return 0;

	ll &res = mem[i][j];
	if (res != -1) return res;

	int x = q[i + ((n - 1) - j)];

	return res = max(
		dp(i + 1, j) + a[x] * (x - i),
		dp(i, j - 1) + a[x] * (j - x)
	);
}

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

	cin >> n;
	forn (i, n) cin >> a[i];

	iota(q, q + n, 0);
	sort(q, q + n, [&] (int i, int j) {
		return a[i] > a[j];
	});

	memset(mem, -1, sizeof(mem));
	cout << dp(0, n - 1) << endl;

	return 0;
}


Measured memory_bytes: 35204
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int num[101]={};
    for(int i=1;i<=100;i++){
        if(a%i==0) num[i]++;
        if(b%i==0) num[i]++;
    }
    int cnt=0;
    for(int i=100;i>0;i--){
        if(num[i]==2) cnt++;
        if(cnt==k){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 256