akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
static const int INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool CompPair(const pint& arg1, const pint& arg2) { return arg1.second < arg2.second; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

struct edge {
    int to, cost;
};

vector<vector<edge>> graph(10);
vector<int> dist; 
vector<int> prever;

vector<int> dijkstra(int n, int s){
    vector<int> dist = vector<int>(n,INF);
    vector<int> prever = vector<int>(n,-1);
    dist[s] = 0;

    priority_queue<pint, vector<pint>, greater<pint>> pq;
    pq.push(make_pair(0,s));

    while(!pq.empty()){
        pint u = pq.top(); pq.pop();
        int v = u.second;
        if(dist[v] < u.first){
            continue;
        }
        for(int i=0;i<graph[v].size();i++){
            edge e = graph[v][i];
            if(dist[e.to] > dist[v] + e.cost){
                dist[e.to] = dist[v] + e.cost;
                prever[e.to] = v;
                pq.push(make_pair(dist[e.to],e.to));
            }
        }
    }
    // for(auto idist:dist) {
    //     cout << idist << " ";
    // }
    // cout << endl;
    return dist;
}

int main(void) {
    int h, w;
    cin >> h >> w;

    vector<vector<int>> a(h, vector<int>(w));
    int ctmp;
    for(int in=0;in<10;in++) {
        for(int jn=0;jn<10;jn++) {
            cin >> ctmp;
            graph[in].push_back((edge){jn, ctmp});
        }
    }
    for(int ih=0;ih<h;ih++) {
        for(int jw=0;jw<w;jw++) {
            cin >> a.at(ih).at(jw);
        }
    }

    vector<int> conv(10);
    for(int in=0;in<=9;in++) {
        if(in==1) conv.at(in) = 0;
        else {
            auto res = dijkstra(10, in);
            conv.at(in) = res.at(1);
        }
        
    }

    int ans = 0;
    for(int ih=0;ih<h;ih++) {
        for(int iw=0;iw<w;iw++) {
            if(a.at(ih).at(iw)==-1) continue;
            else ans += conv.at(a.at(ih).at(iw));
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  long long N;
  cin>>N;
  long long a[N];
  long long sum=0;
  for(long long i=0;i<N;i++){
    cin>>a[i];
    sum^=a[i];
  }
  for(long long i=0;i<N;i++){
    cout<<(sum^a[i]);
    if(i !=N-1) cout<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 5116
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n ;
    vl v;
    cin >> n ;
    forn(i ,1 , n ){
       ll x;
       cin >> x;
       v.pb(x);
    }
    ll ziz = acc(v) % n  ;
    ll foo ;
    if(ziz == 0){
        foo = acc(v)/n ;
    }
    else {
        foo = acc(v)/n ;
        ++foo ;
    }
    ll res = 0 ;
    forn(i , 0 , n-1){
       res = res + (foo-v[i])*(foo-v[i]);
    }
    ll res1 = 0 ;
    if(ziz== 0) {
        cout << res << el ;
        ro ;
    }
    else {
        --foo;
        forn(i , 0 , n-1){
           res1 = res1 + (foo-v[i])*(foo-v[i]);
        }
    }
    res = min(res , res1) ;
    cout << res << el ;
 }































Measured memory_bytes: 384
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

signed main(){
    int a,b,n;
    string s;
    cin>>s;
    if(s[0]=='A')cout<<'T'<<endl;
    if(s[0]=='T')cout<<'A'<<endl;
    if(s[0]=='C')cout<<'G'<<endl;
    if(s[0]=='G')cout<<'C'<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    if (2*x == w && 2*y == h) {
        cout << (double)w*(double)h/2.0 << " " << 1 << endl;
    } else {
        cout << (double)w*(double)h/2.0 << " " << 0 << endl;
    }
}

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;
    int a[3],b[3];
    rep(i,3)cin>>a[i];
    rep(i,3)cin>>b[i];
    vector<pair<int,int>> posi,nega;
    rep(i,3){
        if(a[i]<b[i])posi.push_back({a[i],b[i]});
        else nega.push_back({b[i],a[i]});
    }
    if(posi.size()==3){
        int ans = 0;
        rep(i,n+1)rep(j,n+1){
            if(i*a[0]+j*a[1]>n)break;
            int k = (n-i*a[0]-j*a[1])/a[2];
            int rem = n-i*a[0]-j*a[1]-k*a[2];
            ans = max(ans,i*b[0]+j*b[1]+k*b[2]+rem);
        }
        cout<<ans<<endl;
        return 0;
    }
    if(nega.size()==3){
        int ans = 0;
        rep(i,n+1)rep(j,n+1){
            if(i*b[0]+j*b[1]>n)break;
            int k = (n-i*b[0]-j*b[1])/b[2];
            int rem = n-i*b[0]-j*b[1]-k*b[2];
            ans = max(ans,i*a[0]+j*a[1]+k*a[2]+rem);
        }
        cout<<ans<<endl;
        return 0;
    }
    if(posi.size()==1){
        n = n%posi[0].first + n/posi[0].first * posi[0].second;
        ll ans =0 ;
        ll a1=nega[0].first, b1 = nega[0].second;
        ll a2=nega[1].first, b2 = nega[1].second;
        rep(i,n+1){
            if(a1*i>n)break;
            ll j = (n-a1*i)/a2;
            ll rem = n-a1*i-a2*j;
            ans = max(ans,i*b1+j*b2+rem);
        }
        cout<<ans<<endl;
        return 0;
    }
    if(posi.size()==2){
        swap(posi,nega);
        ll ans =0 ;
        ll a1=nega[0].first, b1 = nega[0].second;
        ll a2=nega[1].first, b2 = nega[1].second;
        rep(i,n+1){
            if(a1*i>n)break;
            ll j = (n-a1*i)/a2;
            ll rem = n-a1*i-a2*j;
            ans = max(ans,i*b1+j*b2+rem);
        }
        ans = ans%posi[0].first + ans/posi[0].first * posi[0].second;
        cout<<ans<<endl;
        return 0;
    }

    return 0;
}

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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        vector<_i64> input(3);
        _foreach(e, input) { cin >> e; } sort(_all(input));
        _rep(i, _size(input)) { cout << (i != 0 ? " " : "") << input[i]; }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>

namespace TokorotenLab
{
    /*
    Arguments:
        Search range: [begin, end)
        Target function: f(x)
    Requirement:
        f(x) => { false, ..., false, true, ..., true }
    Judge:
        true_bound == begin => All f(x) are true
        true_bound == end => All f(x) are false
    */
    std::pair<long long, long long> binary_search(long long begin, long long end, std::function<bool(long long)> f)
    {
        long long false_bound = begin - 1LL; // ( ..., false_bound] => false
        long long true_bound = end; // [true_bound, ... ) => true
        long long x;

        while(true_bound - false_bound > 1LL)
        {
            x = false_bound + (true_bound - false_bound) / 2LL;
            if(f(x))
            {
                true_bound = x;
            }
            else
            {
                false_bound = x;
            }
        }

        return std::make_pair(false_bound, true_bound);
    }
}

using namespace std;

int main()
{
    int n;
    vector<int> h;
    vector<int> min_h;

    cin >> n;

    h.resize(n);
    min_h.resize(n + 1);

    for(int i = 0; i < n; ++i)
    {
        cin >> h[i];
    }

    min_h[n] = 1e9 + 1;
    for(int i = n - 1; i >= 0; --i)
    {
        min_h[i] = min(h[i], min_h[i + 1]);
    }


    for(int i = 0; i < n; ++i)
    {
        if(h[i] > min_h[i] + 1)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;

    while (1)
    {
        int l = s.length();
        int sum = 0;

        for (int i = 0; i < l; i++)
        {
            sum += s[i] - '0';
        }

        cout << sum << endl;
        cin >> s;
        if (s == "0")
        {
            break;
        }
    }
    return 0;
}



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

using namespace std;

long long inf=1000000007;

int main(){
	long long n;
	cin>>n;
	vector<long long> hoge(n);
	long long sum=0;

	for(int i=0;i<n;i++){
		cin>>hoge.at(i);
		sum+=hoge.at(i);
	}

	long long ans=inf*10000;
	long long pre=0;

	for(auto a:hoge){
		pre+=a;
		sum-=a;
		ans=min(ans,abs(sum-pre));
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
int main(){
     ll n;
     cin >>n;
     vector<vector<int>> v(10,vector<int>(10));
     for (int i=1;i<n+1;i++){
          int x=i;
          int a =x%10;
          while (x>=10) {x /=10;}
          int b =x;
          v[a][b]++;
     }
     ll ans =0;
     for (int i=1;i<10;i++){
          for (int j=1;j<10;j++){
               ans += v[i][j] * v[j][i];          
          }
     }
     cout <<ans <<endl;
}

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

void solve(int m,int n, string X, string Y){
	
   int L[m+1][n+1]; 
   for (int i=0; i<=m; i++){ 
     for (int j=0; j<=n; j++){ 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 

   int index = L[m][n]; 
   char lcs[index+1]; 
   lcs[index] = '\0';  
   int i = m, j = n; 

   while (i > 0 && j > 0){ 
   	
      if (X[i-1] == Y[j-1]){ 
          lcs[index-1] = X[i-1]; 
          i--; j--; index--;
      }
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
   cout<<lcs;
}

int main() {
	string s1,s2;
	cin>>s1>>s2;
	int m=s1.length();
	int n=s2.length();
	solve(m,n,s1,s2);
	return 0;
}

Measured memory_bytes: 35456
object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val n, m = sc.nextInt
	val ps = List.fill(m)((sc.nextInt, sc.next)).groupBy(_._1).toList.map(_._2)
	
	println(s"${ps.filter(_ exists (_._2 == "AC")).size} ${ps.map(_.indexWhere(_._2 == "AC")).map(a => if (a == -1) 0 else a).sum}")
}

Measured memory_bytes: 130200
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数


int main()
{
  int hoge = 0 ;
  int n ;
  cin >> n ;
  vector<int> num(n) ;
  REP(i,n){
    cin >>num.at(i) ;
  }
  int m ;
  cin >> m ;
  vector<int> numnum(m) ;
  REP(i,m){
    cin >> numnum.at(i) ;
  }
  sort(ALL(num)) ;
  sort(ALL(numnum)) ;
  
  REP(i,m){
    bool flag = true ;
    int tmp = numnum.at(i) ;
    FOR(j,hoge,n){
      if(num.at(j)==tmp){
        hoge = j+1 ;
        flag = false ;
        break ;
      }
    }
      
    if(flag){
      cout <<"NO"<<endl ;
      return 0 ;
      }
    
  }
  cout <<"YES"<<endl ;
   


  return 0 ;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

int dp[1001][bit32(12)];

void solve() {
  repc(i, 1000) rep(j, bit32(12)) dp[i][j] = 1e9;
  dp[0][0] = 0;
  int N, M;
  cin >> N >> M;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    vi32 c(b);
    cin >> c;
    int mask = 0;
    rep(j, b) mask |= bit32(c[j] - 1);
    rep(j, bit32(N)) {
      if (dp[i][j] == 1e9) continue;
      amin(dp[i + 1][j], dp[i][j]);
      amin(dp[i + 1][j | mask], dp[i][j] + a);
    }
  }
  int ans = dp[M][bit32(N) - 1];
  if (ans == 1e9) ans = -1;
  cout << ans << endl;
}


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

namespace Prac
{
    class Program
    {
        static void Main(string[] args)
        {
            var Hs = new List<int>();
            var Ws = new List<int>();
            var temp = new int[2];
            while (true)
            {
                temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if (temp[0] == 0 && temp[1] == 0)
                    break;
                Hs.Add(temp[0]);
                Ws.Add(temp[1]);
            }
            for (var i = 0; i < Hs.Count; i++)
            {
                for (var h = 0; h < Hs[i]; h++)
                {
                    if ((h == 0) | (h == Hs[i] - 1))
                    {
                        for (var w = 0; w < Ws[i]; w++)
                        {
                            Console.Write("#");
                        }
                    }
                    else
                    {
                        Console.Write("#");
                        for (var w = 1; w < Ws[i]-1; w++)
                        {
                            Console.Write(".");
                        }
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
            
        }


    }
}
    

Measured memory_bytes: 13776
from heapq import heappush,heappop
n,*t=map(int,open(0).read().split())
a=t[:n]
b=t[n:]
B=[]
for i,j in enumerate(b):heappush(B,(-j,i))
c=0
d=0
while B and d<2*10**6:
    d+=1
    y,i=heappop(B)
    x,z=b[(i-1)%n],b[(i+1)%n]
    t=(b[i]-a[i])//(x+z)
    b[i]-=t*(x+z)
    c+=t
    if b[i]>a[i]:
        heappush(B,(-b[i],i))
print([-1,c][a==b])

Measured memory_bytes: 151568
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int N, K;
	cin >> N;
	char A[100];
	for (int i = 1; i <= N; i++)
	{
		cin >> A[i];
	}
	cin >> K;

	for (int i = 1; i <= N; i++)
	{
		if (A[i] != A[K])
		{
			A[i] = '*';
		}
	}
	for (int i = 1; i <= N; i++)
	{
		
		cout << A[i];
	}

	// system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long n;
long long ans;
long long qkpow(long long x,long long y)
{
	long long sum=1;
	while(y)
	{
		if(y&1)
		sum=(sum*x)%mod;
		x=(x*x)%mod;
		y>>=1;
	}
	return sum%mod;
}
int main()
{
	cin>>n;
	ans=((qkpow((long long)10,n)%mod-(long long)2*qkpow((long long)9,n)%mod+qkpow((long long)8,n)%mod)+mod)%mod;
	cout<<ans;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

struct edge{int to,id;};

vector<vector<edge> > adj;
vector<bool> seen;
vi dp;
vi ans;

int dfs(int v)
{
    seen[v]=true;
    for(auto e:adj[v]){
        if (seen[e.to]) continue;
        dp[v]+=dfs(e.to);
        if (dp[e.to]%2==1) ans.pb(e.id);
    }
    return dp[v];
}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vector<pi> bomb(n);
    rep(i,n) cin>>bomb[i].fi>>bomb[i].se;
    sort(all(bomb));
    adj.resize(n+1);
    seen.resize(n+1);
    dp.resize(n+1);
    int now=0;
    rep(i,n)if(bomb[i].se!=now) dp[i]++, now=1-now;
    if (now==1) dp[n]++;
    rep(i,m){
        int l,r; cin>>l>>r;
        int L = lower_bound(all(bomb), mp(l,0))-bomb.begin();
        int R = upper_bound(all(bomb), mp(r,1))-bomb.begin();
        adj[L].pb({R,i+1});
        adj[R].pb({L,i+1});
    }
    rep(v,n+1)if(!seen[v] && dfs(v)%2==1){
        cout<<"-1\n";
        return 0;
    }
    sort(all(ans));
    cout<<ans.size()<<"\n";
    rep(i,ans.size()){
        if (i>0) cout<<" ";
        cout<<ans[i];
    }cout<<"\n";
    return 0;
}


Measured memory_bytes: 15228
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define ini(a,n)    memset(a,n,sizeof(a))
#define ff          first
#define ss          second
#define inf         10000000000000000
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;
unordered_map<ll,vi> g;
unordered_map<ll,ll> vis;

const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
const ll N = 2e5+10;
ll dx[4]={-1, +1, 0, 0};
ll dy[4]={0, 0, +1, -1};
bool imp = false;
bool isPowerOfTwo (ll x)
{
    return x && (!(x&(x-1)));
}


void solve() {

    ll n;cin>>n;

    ll c=1;
    while((c*360)%n != 0)
        c++;

    cout<<(c*360)/n<<endl;

}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    fio
    int t=1;
    if(imp) cin>>t;

    while(t--)
    {
        // cout<<"Case #"<<tc<<": ";
        g.clear();
        vis.clear();
        solve();
        // tc++;
    }

}


Measured memory_bytes: 3552
local mfl = math.floor
local n, k = io.read("*n", "*n")
local as, bs = {}, {}
local kdigs = {}
do
  local tk = k
  for i = 1, 32 do
    kdigs[i] = tk % 2
    tk = mfl(tk / 2)
  end
end
local klim = 1
for i = 32, 1, -1 do
  if kdigs[i] == 1 then
    klim = i
    break
  end
end

local digs = {}
local maxdig = {}
for i = 1, n do
  digs[i] = {}
  local a = io.read("*n")
  bs[i] = io.read("*n")
  for j = 1, 32 do
    digs[i][j] = a % 2
    a = mfl(a / 2)
  end
  maxdig[i] = 1
  for j = 32, 1, -1 do
    if digs[i][j] == 1 then
      maxdig[i] = j
      break
    end
  end
end

local ret = 0
local mma = math.max
for lim = 0, klim do
  if lim == 0 or kdigs[lim] == 1 then
    local score = 0
    for i = 1, n do
      local isok = maxdig[i] <= klim
      for dig = 1, klim do
        if dig < lim then
          -- nothing
        elseif dig == lim then
          if digs[i][dig] == 1 then isok = false break end
        else
          if kdigs[dig] < digs[i][dig] then isok = false break end
        end
      end
      if isok then score = score + bs[i] end
    end
    ret = mma(ret, score)
  end
end
print(ret)


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> f(h);
  vector<vector<int>> tmp(h,vector<int>(w,0));
  rep(i,h){
    cin >> f[i];
  }
  rep(i,h){
    int x=0;
    rep(j,w){
      if(f[i][j]=='.'){
        x++;
      }else{
        repp(k,j-x,j){
          tmp[i][k]+=x;
        }
        x=0;
      }
    }
    repp(k,w-x,w){
      tmp[i][k]+=x;
    }
    x=0;
  }
  rep(j,w){
    int x=0;
    rep(i,h){
      if(f[i][j]=='.'){
        x++;
      }else{
        repp(k,i-x,i){
          tmp[k][j]+=x;
        }
        x=0;
      }
    }
    repp(k,h-x,h){
      tmp[k][j]+=x;
    }
    x=0;
  }
        
  int ans=0;
  rep(i,h){
    rep(j,w){
      ans=max(ans,tmp[i][j]-1);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 20096
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int del(int* b, int p,int leng){
    int ans=*(b+p);
    for(int i=p;i<leng-1;i++){
        *(b+i)=*(b+i+1);
    }
    return ans;
}

int find(int* b,int leng){
    int place=-1;
    REP(i,leng){
        if(i==*(b+i))place=i;
    }
    return place;
}

int main()
{
    int n;
    int b[105]={};
    int operation[105]={};
    scanf("%d",&n);
    REP(i,n)scanf("%d",&b[i]);
    REP(i,n)b[i]--;
    int space;
    REP(i,n){
        if((space=find(b,n-i))!=-1){
            operation[i]=del(b,space,n-i);
        }
        else{
            printf("-1\n");
            return 0;
        }
    }
    REP(i,n){
        printf("%d\n",operation[n-1-i]+1);
    }
    return 0;
}

Measured memory_bytes: 764
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int64_t n;
  cin>>n;
  std::vector<int64_t> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }



  int64_t result=0;
  int64_t npow2=n*n;
  for(int i=0;i<n;i++){
    int64_t alpha=(a[i]/npow2);
    a[i]+=(-alpha*npow2+alpha*(n-1));
    for(int j=0;j<n;j++){
      if(i!=j){
        a[j]+=(alpha*(n-2));
      }
    }
    result+=alpha*(2*n-1);

  }

  while(true){
    bool found_greater=false;
    for(int i=0;i<n;i++){
      if(a[i]>=n){
        found_greater=true;
        int64_t operation=a[i]/n;
        a[i]%=n;
        result+=operation;
        for(int j=0;j<n;j++){
          if(i!=j){
            a[j]+=operation;
          }
        }
      }
    }
    if(!found_greater){
      break;
    }
  }
  cout<<result<<endl;


  return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
    int N,K,i,j;
    scanf("%d%d",&N,&K);
    
    int A[N];
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    
    int cnt[N+1];
    for(i=0;i<=N;i++){
        cnt[i] = 0;
    }
    int a = 0;
    for(i=0;i<N;i++){
        a = A[i];
        cnt[a]++;
    }

    int v;
    for(i=1;i<=N;i++){
        v = cnt[i];
        j = i-1;
        while(j >= 0 && cnt[j] < v){
            cnt[j+1] = cnt[j];
            j--;
        }
        cnt[j+1] = v;
    }
    
    int ans = 0;
    for(i=K;i<=N;i++){
        if(cnt[i]==0){
            break;
        }
        ans+=cnt[i];
    }
    
    printf("%d",ans);
    
}

Measured memory_bytes: 1664
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
    int n;
    long long m;
    scanf("%d %lld", &n, &m);
    vector<long long> v;
    for(int i = 0 ; i < n ; i++){
        long long x;
        scanf("%lld", &x);
        v.push_back(x);
    }
    int j = 0;
    for(j = 50 ; j >= 0 ; j--) {
        if(m & (1LL<<j)) break;
    }
    long long ans = 0;
    long long tmp = 0;
    long long out = 0;
    
    for(; j >= 0 ; j--) {
        if((ans ^ (1LL<<j)) > m) continue;

        long long a = 0, b = 0;
        for(int k = 0 ; k < n ; k++) {
            a += (v[k] & (1LL<<j));
            b += (v[k] & (1LL<<j)) ^ (1LL<<j);
        }

        if(a < b) ans ^= 1LL<<j;
    }

    for(auto e: v) {
        tmp += ans ^ e;
    }

    out = tmp;

    ans = 0;
    for(int j = 0 ; j < 50 ; j++) {
        if((ans ^ (1LL<<j)) > m) break;
 
        long long a = 0, b = 0;
        for(int k = 0 ; k < n ; k++) {
            a += (v[k] & (1LL<<j));
            b += (v[k] & (1LL<<j)) ^ (1LL<<j);
        }
 
        if(a < b) ans ^= 1LL<<j;
    }
    tmp = 0;
    for(auto e: v) {
        tmp += ans ^ e;
    }

    out = max(out, tmp);

    printf("%lld\n", out);
    return 0;
}


Measured memory_bytes: 1400
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#define forn(i,n) for(i=0;i<n;++i)
#define for1(i,n) for(i=1;i<=n;++i)
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fill(x,b) memset((x),b,sizeof((x)))
#define fill2D(x,r,c,b) memset((x),b, sizeof(x[0][0]) * r * c)
#define whatIs(a) cout<<#a<<" is : "<<a<<endl

typedef long long ll;
typedef vector<ll> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<vs> vvs;

const ll mod = 1e9 + 7;
clock_t t1, t2;

ll binPow(ll a, ll b) {ll x = 1, y = a; while (b) {if (b & 1)x = (x * y) % mod; y = (y * y) % mod; b >>= 1;} return x % mod;}

ll inverserEuler(ll n) {return binPow(n, mod - 2);}

ll C(ll k, ll n) {vll f(n + 1, 1); for (ll i = 2; i <= n; i++)f[i] = (f[i - 1] * i) % mod; return (f[n] * ((inverserEuler(f[k]) * inverserEuler(f[n - k])) % mod) % mod) % mod;}

/* Extend Euclid: ax + by = c;
ll x, y;

void extendEuclid(ll a, ll b){if(b == 0){x = 1;y = 0;return;}extendEuclid(b,a%b);ll x1 = y, y1 = x - (a/b) * y;x = x1;y = y1;}
// nghiem : x + (b/d)*k, y - (a/d) * k;
*/
/*--------------------------------------------------------------------------------------------------*/

void trunghieu()
{
	int a,b;
	cin>>a>>b;
	if((a + b) % 2 == 0)
		cout<<(a + b)/2;
	else cout<<"IMPOSSIBLE";
}

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

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

using namespace std;

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

	int p1 = a * n;	//	plan 1
	int p2 = b;		//	plan 2
	
	if (p1 < p2) {
		cout << p1 << endl;
	}
	else if (p1 > p2) {
		cout << p2 << endl;
	}
	else {
		cout << p1 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
     
    int main()
    {
     
      int l,r,d,cnt=0;
      cin>>l>>r>>d;
      for(int i=l;i<=r;i++)
      {
      	if(i%d==0) cnt++;
	  }
	  cout<<cnt<<endl;
    }
    
     

Measured memory_bytes: 3600
import math

#n = int(input())
a, b = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = input()
#list = list(s)
#temp = [[0 for _ in range(13)] for _ in range(13)]

print(math.ceil(a/(2*b + 1)))

Measured memory_bytes: 3060
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin>>N;
  cout<<N*N<<endl;


}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int mod=998244353;
const int lim=15,maxn=(1<<20)+5,N=110;
int F[lim+1][maxn],G[lim+1][maxn];
int dp[10][N];int g[N][N];
int a[N];char s[N];
ll p[N],c[N][N];
int n;

void work(int K){
	int i,j,k;int cur,x;
	rep(i,0,(1<<K)-1){
		rep(j,1,K/2)	if(K%j==0){
			x=i;cur=p[j];rep(k,1,K/j)	cur&=x,x>>=j;		
			G[K][i]=(G[K][i]+F[j][cur])%mod;
		}
		//F[K][i]=(F[K][i]+1ll*F[K-1][i>>1]*((i&1)+1))%mod;
		rep(j,1,K)	if(G[j][i&p[j]])	F[K][i]=(F[K][i]+1ll*G[j][i&p[j]]*F[K-j][i>>j])%mod;
	}
}	

void init(){
	int i;
	rep(i,1,50)	p[i]=(1ll<<i)-1;
	F[0][0]=1;
	G[1][0]=F[1][0]=1;F[1][1]=G[1][1]=2;
	rep(i,2,lim)	work(i);
}

int solve(int K,ll w,int d){
	if(K<=lim)	return F[K][w];
	int i,j,k;ll cur;int x;int opt;
	//memset(dp[d],0,(K+1)*sizeof(int));
	rep(i,0,K)	dp[d][i]=0;
	dp[d][0]=1;
	rep(i,0,K-1) if(dp[d][i]){
		if(K-i<=lim){dp[d][K]=(dp[d][K]+1ll*dp[d][i]*F[K-i][w>>i])%mod;continue;}
		opt=(w>>i)&1;
		dp[d][i+1]=(dp[d][i+1]+1ll*dp[d][i]*(opt+1))%mod;
		rep(j,1,(K-i)>>1){		
			for(cur=(w&p[i+j])>>i,x=i+j,k=2;k<=(K-i)/j;k++){
				cur&=(w&p[x+j])>>x;x+=j;
				dp[d][x]=(dp[d][x]+1ll*dp[d][i]*solve(j,cur,d+1))%mod;
			}
		}
	}
	return dp[d][K];
}

int getG(int l,int r){
	if(r-l+1<=lim)	return G[r-l+1][c[l][r]];
	int len=r-l+1;int ret=0;int i;
	ll cur;int x;
	rep(i,1,len/2)	if(len%i==0){
		for(cur=p[i],x=l;x<=r;x+=i)	cur&=c[x][x+i-1];
		ret=(ret+solve(i,cur,1))%mod;
	}
	return ret;
}		

int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int i,j;
	init();
	scanf("%s",s+1);n=strlen(s+1);
	rep(i,1,n)	a[i]=s[i]-'0';
	for(i=n;i;i--)	rep(j,i,n)	c[i][j]=(c[i+1][j]<<1)+(a[i]&1);
	rep(i,1,n)	rep(j,i,n)	g[i][j]=getG(i,j);
	dp[0][0]=1;
	rep(i,0,n-1) rep(j,i+1,n) dp[0][j]=(dp[0][j]+1ll*dp[0][i]*g[i+1][j])%mod;
	printf("%d\n",dp[0][n]);
}
			
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

Measured memory_bytes: 63744
from math import sqrt
from itertools import product

import numpy as np

def helper(N,D):
  if D%2 == 1:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
    grid[:,1::2] = ~grid[:,1::2]
  elif D%4 == 2:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
  else:
    M = (N-1)//2+1
    D //= 4
    g = helper(M, D)
    grid = np.zeros((2*M,2*M),dtype=bool)
    grid[::2,::2] = g
    grid[1::2,::2] = g
    grid[::2,1::2] = g
    grid[1::2,1::2] = g
    grid = grid[:N,:N]
  return grid


N,D1,D2 = map(int,input().split())
M = N*2
g1 = helper(N*2,D1)
g2 = helper(N*2,D2)
ans = g1&g2


for x,y in np.transpose(np.nonzero(ans))[:N*N]:
  print(x,y)


Measured memory_bytes: 19284
N, x = map(int, input().split())
*A, = map(int, input().split())
ans = 0
for i in range(N - 1):
    w = A[i] + A[i + 1]
    if w <= x: continue
    r = max(0, A[i + 1] - (w - x))
    l = x - r
    ans += A[i] - l + A[i + 1] - r
    A[i + 1] = r
print(ans)


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

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


Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int h,w;
  cin >> h >> w;
  vvc data(h+2,vc(w+2,'.'));
  rep(i,h){
    rep(j,w){
      cin >> data.at(i+1).at(j+1);
    }
  }
  char c1,c2,c3,c4;
  rep(i,h){
    rep(j,w){
      if(data.at(i+1).at(j+1) == '.') continue;
      c1 = data.at(i+2).at(j+1);
      c2 = data.at(i).at(j+1);
      c3 = data.at(i+1).at(j+2);
      c4 = data.at(i+1).at(j);
      if(c1 == '.' && c2 == '.' && c3 == '.' && c4 == '.'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


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

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

int main()
{
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String S = scan.next();

	int pattern = pow(2, S.length()-1);
	long ans = 0;
	for (int i = 0; i < pattern; i++) {
	    ans = ans + calc(S, i);
	}

	System.out.println(ans);
	scan.close();
    }

    private static long calc(String s, int value) {
	String t = Integer.toBinaryString(value);
	StringBuilder str = new StringBuilder();
	str.append(s.substring(0, s.length()-t.length()));
	for (int i = 0; i < t.length(); i++) {
	    if(t.charAt(i) == '1') str.append('+');
	    str.append(s.charAt(s.length() - t.length() + i));
	}

	long result = 0;
	long tmp = 0;
	for (int i = 0; i < str.length(); i++) {
	    if(str.charAt(i) == '+') {
		result = result + tmp;
		tmp = 0;
	    } else {
		tmp = tmp * 10 + str.charAt(i) - '0';
	    }
	}
	result = result + tmp;
	return result;
    }

    private static int pow(int x, int y) {
	if(y == 0) return 1;

	int x2 = pow(x, y/2);
	int result = x2 * x2;
	if(y % 2 != 0) result = result * x;
	return result;
    }
}


Measured memory_bytes: 22228
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int A = scn.nextInt();
		int B = scn.nextInt();
		int K = scn.nextInt();
		int ans;
		int k = 0;
		for(int i = Math.min(A, B);i > 0;i--) {
			if(A%i==0 && B%i == 0) {
				k++;
				if(k == K) {
					System.out.println(i);
					break;
				}
			}
		}
	}

}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<n;i++)
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  cin >> s;
  long long a = 1;
  int c;//0が縦置き1が横置き
  int i;
  //1個目の色付け
  if(s[0] != s[1]){
    i = 1;
    c = 0;
    a = 3;
  }else{
    i = 2;
    c = 1;
    a = 6;
  }
  //2個目からの色付け
  for(;i<n;++i){
    if(i<n-1 && s[i+1] == s[i]){
      i++;
      if(c==0){
        a*=2;
      }else{
        a*=3;
      }
      c = 1;
    }else{
      if(c==0){
        a*=2;
      }else{
        a*=1;
      }
      c = 0;
    }
    a %= 1000000007;
  }
  cout << a << endl;
  return 0;
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c; cin>>a>>b>>c;
    int k; cin>>k;
    if(b<c) swap(b,c);
    if(a<b) swap(a,b);
    REP(i,k){
        a*=2;
    } 
    print(a+b+c);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 220000
using namespace std;
int a[N],b[N],sum[N],l[N],r[N],A,B,ans0[N],ans1[N];
int q,n,x;
int main(){
	scanf("%d",&x);
	scanf("%d",&n);
	n++;
	for(int i=1;i<=n;i++){
		if(i<n)scanf("%d",&a[i]);
		else a[i]=1200000000;
		b[i]=a[i]-a[i-1];
		b[i]=b[i]*((i&1)?-1:1);
		sum[i]=sum[i-1]+b[i];
	}
	l[0]=0,r[0]=x;
	for(int i=1;i<=n;i++){
		l[i]=l[i-1];
		r[i]=r[i-1];
		l[i]=max(l[i],-sum[i]);
		r[i]=min(r[i],x-sum[i]);
	}
	//for(int i=1;i<=n;i++)printf("%d %d\n",l[i],r[i]);
	A=0,B=x;
	for(int i=1;i<=n;i++){
		A=A+b[i];
		B=B+b[i];
		A=max(A,0);A=min(A,x);
		B=max(B,0);B=min(B,x);
		ans0[i]=A;
		ans1[i]=B;
	}
//	for(int i=1;i<=n;i++)printf("%d ",b[i]);printf("\n");
//	for(int i=1;i<=n;i++)printf("%d ",ans1[i]);printf("\n");
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int X,y;
		scanf("%d%d",&X,&y);
		int p=lower_bound(a+1,a+1+n,X)-a;
		if(a[p]>X)p--;
	//	printf("%d %d %d\n",X,y,p);
		int ans=0;
		if(y<=l[p]){
			ans=ans0[p];
		}
		if(y>=r[p]){
			ans=ans1[p];
		}
		if(y>=l[p]&&y<=r[p]){
			ans=y+sum[p];
		}
		if(p&1)ans+=X-a[p];
		else ans-=X-a[p];
		ans=max(ans,0);
		ans=min(ans,x);
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 5120
def chk(arr, i_str, n):
  if len(i_str) < n:
    return False
  for a in arr:
    if a[0] > len(i_str):
      return False
    if a[1] != int(i_str[a[0]-1]):
      return False
  return True
      
n, m = [int(_) for _ in input().split()]
arr = []
val = -1

for _ in range(m):
  s, c = [int(_) for _ in input().split()]
  arr.append((s, c))

for i in range(1000):
  i_str = str(i)
  if chk(arr, i_str, n):
    val = i
    break

print(val)
  

Measured memory_bytes: 3064
import java.io.*;
public class Main{
	public static void main(String [] args) throws  IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] st=br.readLine().split(" ");
		int a=Integer.parseInt(st[0]);
		int b=Integer.parseInt(st[1]);

		System.out.printf("%d %d %.6f",a/b,a%b,(double)a/b);
		}
	}

Measured memory_bytes: 17088
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A));
  int sum = 0;
  REP(i,K){
    sum+=A.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 3628
if __name__ == '__main__':
    import sys
    input=sys.stdin.readline
    N,Q=list(map(int,input().split()))
    events=[list(map(int,input().split())) for _ in range(N)]
    D=[int(input()) for i in range(Q)]
    ans=["-1"]*Q
    skip=[-1]*Q
    events.sort(key=lambda x:x[2])
    import bisect
    for S,T,X in events:
        right=bisect.bisect_left(D,T-X)
        left=bisect.bisect_left(D,S-X)
        while left<right:
            if skip[left]==-1:
                ans[left]=str(X)
                skip[left]=right
                left+=1
            else:
                left=skip[left]
    print("\n".join(ans))


Measured memory_bytes: 122076
package main

import (
	"fmt"
)

func main() {
	var b string
	fmt.Scan(&b)

	if b == "A" {
		fmt.Print("T")
	} else if b == "T" {
		fmt.Print("A")
	} else if b == "C" {
		fmt.Print("G")
	} else {
		fmt.Print("C")
	}
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

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

Measured memory_bytes: 3624
def BubbleSort(c, n)
  for i in 0..n-1
    (n-1).downto(i+1){|j|
      c[j], c[j-1] = c[j-1], c[j] if c[j].value < c[j-1].value
    }
  end
end

def SelectionSort(c, n)
  for i in 0..n-1
    minj = i
    for j in i..n-1
      minj = j if c[j].value < c[minj].value
    end
    c[i], c[minj] = c[minj], c[i]
  end
end

class Card
  attr_accessor :value, :key
  def initialize(k, v)
    @key = k
    @value = v
  end
end
n = gets.to_i
c = Array.new(n)
i = 0
gets.split.each{|s|
  tmp = s.split("")
  c[i] = Card.new(s, tmp[1].to_i)
  i += 1
}

c1 = c.clone
c2 = c.clone
BubbleSort(c1, n)
s1 = ""
0.upto(n-1){|j|
  s1 << c1[j].key
  s1 << " " if j < n-1
}
printf "%s\nStable\n", s1;

SelectionSort(c2, n)
s2 = ""
0.upto(n-1){|j|
  s2 << c2[j].key
  s2 << " " if j < n-1
}
printf "%s\n", s2
if s1 == s2 then
  printf "Stable\n"
else
  printf "Not stable\n"
end

Measured memory_bytes: 8760
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
  while(1){
    ll N; cin >> N;
    if(N == 0) break;
    vector<P> s(N);
    vector<string> st(N); vector<string> re(N);
    rep(i,N) cin >> st[i] >> re[i];
    rep(i,N){
      rep(j,8){
        if(j == 2 or j == 5) continue;
        s[i].fi += (st[i][j] - '0') * modpow(10, 8 - j , MOD);
        s[i].sc += (re[i][j] - '0') * modpow(10, 8 - j , MOD);
      }
    }
    SORT(s);
    // binary search
    vector<ll> mono(N); rep(i,N) mono[i] = s[i].fi;
    vector<P> num(N); rep(i,N) num[i].fi = i;
    rep(i,N){
      num[i].sc = POSL(mono , s[i].sc);
    }
    // rep(i,N) cout << num[i].fi << " " << num[i].sc << endl;
    ll ans = 0 , tmp = 0;
    map<ll,ll> m; rep(i,N) m[num[i].sc]++;
    rep(i,N){
      tmp++; tmp -= m[i];
      ans = max(ans , tmp);
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 4976