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

int main()
{
        int N, M;
        cin >> N >> M;
        vector<vector<int>> G(N);
        for (int i = 0; i < M; ++i) {
                int a, b;
                cin >> a >> b;
                G[a-1].push_back(b-1);
                G[b-1].push_back(a-1);
        }

        vector<int> dist(N, -1);
        queue<int> que;

        dist[0] = 0;
        que.push(0);
        int count = 1;

        while (1) {
                if (que.empty()) break;

                int v = que.front();
                que.pop();

                for (int nv : G[v]) {
                        if (dist[nv] != -1) continue;
                        dist[nv] = v + 1;
                        que.push(nv);
                        count++;
                }
        }
        if (count != N) {
                cout << "No" << endl;
        }
        else {
                cout << "Yes" << endl;
                for (int i = 1; i < N; ++i) {
                        cout << dist[i] << endl;
                }
        }



}


Measured memory_bytes: 10084
# UnionFind: https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n + 1)
        
    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.root[x] > self.root[y]:
            x, y = y, x
        self.root[x] += self.root[y]
        self.root[y] = x
        
    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return -self.root[self.find(x)]

n, m = map(int, input().split())
friends = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    friends.unite(a, b)
print(max(friends.size(i) for i in range(n)))

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

int a, b;
char g[105][105];

int main() {
    //freopen("in.txt", "r", stdin);
    scanf("%d%d", &a, &b);
    memset(g, 0, sizeof g);
    for (int i = 0; i < 50; ++i) {
        for (int j = 0; j < 100; ++j) {
            g[i][j] = '#';
        }
    }
    for (int i = 50; i < 100; ++i) {
        for (int j = 0; j < 100; ++j) {
            g[i][j] = '.';
        }
    }

    --a, --b;
    for (int i = 0; i < 49; i += 2) {
        for (int j = 1; j < 100 && a; j += 2) {
            g[i][j] = '.';
            --a;
        }
    }

    for (int i = 51; i < 100; i += 2) {
        for (int j = 1; j < 100 && b; j += 2) {
            g[i][j] = '#';
            --b;
        }
    }

    printf("100 100\n");
    for (int i = 0; i < 100; ++i) printf("%s\n", g[i]);
}


Measured memory_bytes: 256
def update(s, t, x, l, r, k)
  if s == l && t == r then
    $d[k] = x
  else
    if $d[k] > -1 then
      $d[2*k+1] = $d[2*k+2] = $d[k]
      $d[k] = -1
    end
    m = (l + r)/2
    if t <= m then
      update(s, t, x, l, m, 2*k+1)
    elsif m <= s then
      update(s, t, x, m, r, 2*k+2)
    else
      update(s, m, x, l, m, 2*k+1)
      update(m, t, x, m, r, 2*k+2)
    end
  end
end

def find(i, l, r, k)
  return $d[k] if $d[k] > -1
  m = (l+r)/2
  if i < m then
    return find(i, l, m, 2*k+1)
  else
    return find(i, m, r, 2*k+2)
  end
end

MAX = 2**31-1
n, q = gets.split.map(&:to_i)

m = 1
while m < n
  m *= 2
end

$d = Array.new(2*m-1){MAX}

q.times{
  com, s, t, x = gets.split.map(&:to_i)
  case com
  when 0
    update(s, t+1, x, 0, m, 0)
  when 1
    p find(s, 0, m, 0)
  end
}

Measured memory_bytes: 11252
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
 
int main(){
  int n;
  while(~scanf("%d",&n)){
    int b = 1;
    bool flag = false;
    while(n){
      if(n&1){
        if(!flag){
          cout<<b;
          flag = true;
        }else{
          cout<<" "<<b;
        }
      }
      b<<=1;
      n>>=1;
    }
    cout<<endl;
  }
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N, M;
    cin >> N >> M;
    if(N == 1 && M == 1) {
        cout << 1 << endl;
    } else if(N == 1) {
        cout << M - 2 << endl;
    } else if(M == 1) {
        cout << N - 2 << endl;
    } else {
        cout << (N - 2) * (M - 2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from collections import deque
h,w=map(int,input().split())
S=[input() for _ in range(h)]
inf=float("inf")
ans=0
for i in range(h):
   for j in range(w):
      if S[i][j]=="#":
         continue
      else:
         DP=[[inf for _ in range(w)]for _ in range(h)]
         DP[i][j]=0
         que=deque([(i,j)])
         while que:
            si,sj=que.popleft()
            for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
               if 0<=ni<h and 0<=nj<w and S[ni][nj]!="#":
                  if DP[ni][nj]>DP[si][sj]+1:
                     DP[ni][nj]=DP[si][sj]+1
                     ans=max(ans,DP[si][sj]+1)
                     que.append((ni,nj))
print(ans)

Measured memory_bytes: 48572
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a,b=map(int,input().split())
if a*b%2==0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
using namespace std;
//
const int inf=1e9;
//
int H,W;
int A[500][500];
int main(){
	cin>>H>>W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>A[i][j];
		}
	}
	bool have=(A[0][0]%2?1:0);
	vector<pair<int,int> > ans;
	for(int i=0;i<H;i++){
		if(i%2==0){
			for(int j=0;j<W-1;j++){
				if(have){
					ans.push_back(make_pair(i*W+j,i*W+j+1));
					if(A[i][j+1]%2){
						have=false;
					}
				}else if(A[i][j+1]%2){
					have=true;
				}
			}
			if(have){
				if(i+1<H){
					ans.push_back(make_pair(i*W+W-1,(i+1)*W+W-1));
				}
				if(i+1<H&&A[i+1][W-1]%2){
					have=false;
				}
			}else if(i+1<H&&A[i+1][W-1]%2){
				have=true;
			}
		}else{
			for(int j=W-1;j>0;j--){
				if(have){
					ans.push_back(make_pair(i*W+j,i*W+j-1));
					if(A[i][j-1]%2){
						have=false;
					}
				}else if(A[i][j-1]%2){
					have=true;
				}
			}
			if(have){
				if(i+1<H){
					ans.push_back(make_pair(i*W,(i+1)*W));
				}
				if(i+1<H&&A[i+1][0]%2){
					have=false;
				}
			}else if(i+1<H&&A[i+1][0]%2){
				have=true;
			}
		}
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++){
		cout<<ans[i].first/W+1<<" "<<ans[i].first%W+1<<" "<<ans[i].second/W+1<<" "<<ans[i].second%W+1<<endl;
	}
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}
int main(){
	int n;
	cin >> n;
	vector<pair<int, int>>v1(1e5+10), v2(1e5+10);
	for(int i = 0; i < 1e5 + 10; i++){
		pair<int, int>p;
		p.first = 0;
		p.second = i;
		v1[i] = p;
		v2[i] = p;
	}
	for(int i = 0; i < n; i++){
		int temp; cin >> temp;
		if(i%2 == 0)++v1[temp].first;
		else if(i%2 == 1)++v2[temp].first;
	}
	sort(v1.begin(), v1.end());
	reverse(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	reverse(v2.begin(), v2.end());
	int ans = 0;
	if(v1[0]!=v2[0]){
		ans += n - v1[0].first - v2[0].first;
	}else{
		int temp_ans1 = 0, temp_ans2 = 0;
		temp_ans1 = n - v1[0].first - v2[1].first;
		temp_ans2 = n - v1[1].first - v2[0].first; 
		ans = min(temp_ans1, temp_ans2);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define F               first
#define S               second
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18 + 1
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define forI(i,a,n)     for(int i=a;i<=n;i++)
#define forD(i,a,n)     for(int i=n;i>=a;i--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void init(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

int dp[404][404];
int sum[404][404];

void preCompute(int *a, int n){
    forI(i, 1, n){
        forI(j, i, n){
            sum[i][j] = a[j] + sum[i][j-1];
        }
    }
}

int compute(int i, int j){
    if(i == j)  return 0;

    if(dp[i][j] != -1)  return dp[i][j];

    int minCost = inf;

    forI(k, i, j-1)
        minCost = min(minCost, sum[i][j] + compute(i, k) + compute(k+1, j));

    return dp[i][j] = minCost;
}

void solve(){
    int n;  cin>>n;
    int a[n+1]; forI(i, 1, n)   cin>>a[i];
    
    memset(dp, -1, sizeof dp);
    preCompute(a, n);
    cout<<compute(1, n)<<endl;
}   

int32_t main(){
    init();
    // w(t) 
    solve();
    return 0;
}

Measured memory_bytes: 6224
#include <stdio.h>
#include <string.h>

char *reverse(char *s)
{
  int i;
  char tmp;
  for(i=0; i<strlen(s)/2; i++){
      tmp = s[i];
      s[i] = s[strlen(s)-1-i];
      s[strlen(s)-1-i] = tmp;
  }
  return s;
}

int main()
{
  char str[21];

  scanf("%s", str);

  printf("%s\n", reverse(str));

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0 ; i < N ; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int sum = 0;
  for (int i = 0 ; i < N ; i++) {
    if (i + 1 < N && vec.at(i) ==vec.at(i + 1)){
      continue;
    }
    sum += 1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
N = int(input())
D, X = map(int, input().split())
A = [int(input()) for i in range(N)]
t = 0
c = X
for i in range(N):
    t = A[i]
    for j in range(100):
        if 1 + t * j <= D:
            c += 1
        else:
            break
print(c)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    int n;
    int a[10000];
    cin>>n;
    
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
        
    }
    
    for(int i = n - 1;i >= 0;i--)
    {
        if(i == 0)
        {
            cout << a[i] << endl;
        }else{
            cout << a[i] << " ";
        }
            
    }
}



Measured memory_bytes: 3092
import Control.Applicative

main = do xs <- map read . concatMap words . lines <$> getContents
          putStr . unlines . map show $ solve xs

solve :: [Int] -> [Double]
solve (0:_) = []
solve (n:xs) = sig : solve rest
        where (ss,rest) = splitAt n xs
              ss' = map fromIntegral ss
              n' = fromIntegral n
              m = (sum ss') / n' :: Double
              sig = sqrt $ (sum [(x-m)**2.0| x<-ss'])/n' :: Double
          

Measured memory_bytes: 5172
// g++ A.cpp -Wall -Wextra -Woverflow -Wshadow -O2
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>
 
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;

string s;
int main() {
  ios::sync_with_stdio(false); 
  cin >> s;
  int n = s.size();
  s = '?' + s;
  if (s[n] == '1' || s[1] == '0') {
    cout << -1 << '\n';
    return 0;
  }
  vector<int> pos;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[n - i]) {
      cout << -1 << '\n';
      return 0;
    }
    if (s[i] == '1') {
      pos.push_back(i);
    }
  }
  pos.push_back(n);
  for (int i = 1, j = 0; i < n && j < pos.size(); i++) {
    if (i == pos[j]) j++;
    cout << i << ' ' << pos[j] << '\n';
  }
}

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

#define y1 as214
#define ii pair < int , ll >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)

#define ll long long
#define oo INT_MAX

// dp[i][j] là dãy con chung dài nhất khi xét tới 1 -> i và 1 -> j của 2 xâu đó.

const int N = 3e3 + 5;
char f1[N] , f2[N];
int dp[N][N];

void res(int i , int j)
{
    if(i != 0 && j != 0)
    {
        if(dp[i][j] == dp[i - 1][j])
            res(i - 1 , j);
        else if(dp[i][j] == dp[i][j - 1])
            res(i , j - 1);
        else
        {
            res(i - 1 , j - 1);
            cout << f1[i];
        }
    }
}

int main()
{
    //freopen("F.inp","r",stdin);
    cin >> f1;
    cin >> f2;
    int n = strlen(f1);
    int m = strlen(f2);
    for(int i = n ; i >= 1 ; i--)
        f1[i] = f1[i - 1];
    for(int i = m ; i >= 1 ; i--)
        f2[i] = f2[i - 1];
    FOR(i , 1 , n)
        FOR(j , 1 , m)
        {
            if(f1[i] == f2[j]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j] , dp[i][j - 1]);
        }
    res(n , m);
}


Measured memory_bytes: 35584
// OURL: https://atcoder.jp/contests/abc165/tasks/abc165_b
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));  }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v);  }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", ";  } first = false; res += to_string(x);  } res += "}"; return res;  }

string to_string(string s) { return '"' + s + '"';  }
string to_string(const char* s) { return to_string((string) s);  }
string to_string(bool b) { return (b ? "true" : "false");  }
string to_string(vector<bool>::reference b) { return to_string(bool(b));  }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";  }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res; }

void debug_out() { cerr << endl;  }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...);  }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

  ll x;
  cin >> x;
  ll t = 0;
  ll p = 100;
  while (true) {
    p *= 1.01;
    t++;
    if (p >= x) break;
  }
  cout << t << endl;

  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(ll i = 0; i < N; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    int n;cin>>n;
    rep(i,10)rep(j,10){
        if(i*j==n){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int x,i;
	scanf("%d",&x);
	while(1)
	{
		int s=0;
		for(i=2;i<=x/2;i++)
		{
			if(x%i==0)
			{
				x++;
				s=1;
				break;
			}
		}
		if(s==0)
		{
			printf("%d\n",x);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
ll exp(ll x,ll y){
    if(y==0)return 1;
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

int main(){
  int k,a,b;cin >> k >> a >> b;
  rep2(i,a,b+1)if(i%k==0){cout << "OK" << endl;return 0;}
  cout << "NG" << endl;
}

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

int N,K,T;
const int B = 512;
int bfr[200010/B+1], aft[200010/B+1];
int val[200010/B*B+B];

void sync(int b){
  if(bfr[b] == -1) return;
  for(int i = b*B; i < (b+1)*B; ++i){
    val[i] = (val[i] == bfr[b]) ? aft[b] : -2;
  }
  bfr[b] = -1;
  aft[b] = -1;
}

void naive(int l, int r, int x){
  for(int i = l; i < r; ++i){
    val[i] = (val[i] == x-1) ? x : -2;
  }
}

void block(int l, int r, int x){
  l /= B; 
  r /= B;
  while(l < r){
    if(aft[l] != -1){
      aft[l] = (aft[l] == x-1) ? x : -2;
    } else {
      bfr[l] = x-1;
      aft[l] = x;
    }
    ++l;
  }  
}

void exec(int l, int r, int x){
  if(l/B == r/B){
    sync(l/B);
    naive(l,r,x);
  } else {
    if(l%B){
      sync(l/B);
      naive(l, l-l%B+B, x);
      l = l-l%B+B;
    }
    if(r%B){
      sync(r/B);
      naive(r-r%B, r, x);
      r = r-r%B;
    }
    block(l,r,x);
  }
}

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

  cin >> N >> K;
  cin >> T;

  memset(bfr, -1, sizeof bfr);
  memset(aft, -1, sizeof aft);

  while(N%B) ++N;

  for(int it = 0; it < T; ++it){
    int l,r,x;
    cin >> l >> r >> x;
    --l;
    exec(l,r,x);
  }

  for(int i = 0; i < N/B; ++i){
    sync(i);
  }

  cout << count(val, val+N, K) << endl;
}

Measured memory_bytes: 3992
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

int main(){
	ll n,m,c,ans=0,sum;
	cin >> n >> m >> c;
	vector<ll> a(m),b(m);
	REP(i,m) cin >> b[i];
	REP(i,n){
		sum=0;
		REP(j,m) cin >> a[j];
		REP(j,m) sum += a[j]*b[j];
		if(sum+c > 0) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(lint i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint p=1e9+7;

int main(){
  lint N,K;
  cin>>N>>K;
  set<lint> s;
  FOR(i,1,sqrt(N)+1){
    if(s.find(N/i)==s.end()){
      s.insert(i);
      s.insert(N/i);
    }
  }
  vector<lint> v;
  for(auto e:s)v.push_back(e);
  lint M=v.size();
  lint dp[M][K];
  dp[0][0]=1;
  FOR(i,1,M){
    dp[i][0]=(dp[i-1][0]+1*(v[i]-v[i-1]))%p;
  }
  FOR(k,1,K){
    dp[0][k]=dp[M-1][k-1];
    FOR(i,1,M){
      dp[i][k]=(dp[i-1][k]+dp[M-1-i][k-1]*(v[i]-v[i-1]))%p;
    }
  }
  // REP(i,K){
  //   REP(j,M)cerr<<dp[j][i]<<" ";
  //   cerr<<endl;
  // }
  cout<<dp[M-1][K-1]<<endl;
  return 0;
}


Measured memory_bytes: 53244
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef struct pair<int,int> P;
typedef long long ll;

ll n,k,l;

int dp1[16002][3]={};
int dp2[16002][3]={};
ll c[200001]={};
int main() {
	int a,b,c;

	cin>>a>>b>>c;
	bool d[101]={};
	int k=a%b;
	for(int i=1;i<101;++i){
		int j=(k*i)%b;
		d[j]=true;
	}
	if(d[c]){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
//	int ls=s.length();
//
//	int m=0;
//	int a1=0;
//	int a2=0;
//	int a3=0;
//	int a0=0;
//	bool flg=true;
//	for(a1=1;(s[a1]==s[a1-1])&&(a1<ls);a1++);
//	m=a1-a0;
//	for(a2=a1+1;(s[a2]==s[a2-1])&&(a2<ls);a2++);
//	m=max(a2-a1,a1-a0);
//	if(a2==ls)flg=false;
//	for(a3=a2+1;a3<ls;a3++){
//		for(;(s[a3]==s[a3-1])&&(a3<ls);a3++);
//		m=max(m,((a2-a1)+min(a1-a0,a3-a2)));
//		a0=a1;
//		a1=a2;
//		a2=a3;
//	}
//	if(flg)m=max(m,((a2-a1)+min(a1-a0,a3-a2)));
//	cout<<m<<endl;
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const int MX = 60;

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

  ll n, k;
  cin >> n >> k;
  vii to(MX, vi(n)); // to[i][j] = jから2^i回テレポートした先  
  rep(i,n) {
    cin >> to[0][i];
    to[0][i]--;
  }
  rep(i,MX-1) {
    rep(j,n) {
      to[i+1][j] = to[i][to[i][j]];
    }
  }
  int v = 0;
  per(i,MX-1) {
    ll l = 1ll<<i;
    if(l <= k) {
      v = to[i][v];
      k -= l;
    }
  }
  cout << v+1 << endl;
}

Measured memory_bytes: 50972
a, b = map(int,input().split())
cnt = 0
for i in range(a, b+1):
    i_s = str(i)
    i_r = 0
    for j in range(len(i_s)):
        i_r *= 10
        i_r += int(i_s[-j-1])
    if i == i_r:
        cnt += 1
print(cnt)

Measured memory_bytes: 73464
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  a.push_back(-1);
  int ans = 0, pre = -1, cnt = 1;
  rep(i, n + 1) {
    if (a[i] != pre) {
      ans += cnt / 2;
      pre = a[i];
      cnt = 1;
    }
    else cnt++;
  }
  cout << ans << '\n';


  
  return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if ((A==7&&B==5&&C==5)||(A==5&&B==7&&C==5)||(A==5&&B==5&&C==7))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
"""
2つの集合から積集合を求める

input:
4
2 3 5 6
5
2 5 6 7 9
output:
2
5
6
"""

if __name__ == "__main__":
    input()
    A = set(map(int, input().split()))
    input()
    B = set(map(int, input().split()))
    I = A & B
    if I:
        print(*sorted(I), sep="\n")



Measured memory_bytes: 55768
// I am Varun Das from Jadavpur University
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define dbg(x) cerr << #x << " = " << x << endl
#define INF LLONG_MAX
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int dp1[1003][1003],dp[1003][1003];
int i,j,n,m;
string s[1003];
int f(int i,int j){
    if(i==n-1 and j==m-1) return 1;
    if(dp[i][j]!=-1) return dp[i][j];
    int sol=0;
    if(i < n-1 and s[i+1][j]=='.'){ 
    	sol=(sol+f(i+1,j))%mod;
    } 
    if(j < m-1 and s[i][j+1]=='.'){
        sol=(sol+f(i,j+1))%mod;
    }
    return dp[i][j]=sol;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout<<fixed<<setprecision(12);
cin>>n>>m;
loop(p,0,n){
    cin>>s[p];
}
memset(dp,-1,sizeof(dp));
cout<<f(0,0);
	return 0;
}

Measured memory_bytes: 5504
#!/usr/bin/env python3

n = int(input())

count = 1
ans = 10**12
while(count <= (n)**0.5):
    if n % count == 0:
        ans_tmp = (count-1) + (n//count-1)
    ans = min(ans, ans_tmp)
    count += 1

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;

template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}
ll s[200001];
int memo[200001];
vector<Pii> cordinate;
int main(){
	fill(s,s+200001,1LL);
	memset(memo,0,sizeof(memo));
	int N,M;
	cin >> N >> M;
	rep(i,M){
		ll x,y;
		cin >> x >> y;
		--y;
		cordinate.pb(mk(x,y));
	}
	sort(cordinate.begin(),cordinate.end());

	rep(i,M){
		ll y = cordinate[i].sc;
		if(memo[y] == 0){
			ll sum = s[y]+s[y+1];
			s[y] = s[y+1] = sum;
			memo[y] = sum;
		}
		else{
			s[y] = s[y+1] = s[y] + s[y+1] - memo[y];
			memo[y] = s[y];
		}
	}

	rep(i,N){
		printf("%lld%c",s[i],i==N-1?'\n':' ');
	}

	return 0;
}

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

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

    vector <long> g4(0), g2(0), g1(0);
    rep(i,N){
        long d;
        cin >> d;
        if(d % 4 == 0){
            g4.push_back(d);
        }
        else if(d % 2 == 0){
            g2.push_back(d);
        }
        else{
            g1.push_back(d);
        }
    }

    int size4 = g4.size(), size2 = g2.size(), size1 = g1.size();

    if(size2 == 0){
        if(size4 >= size1 - 1){
            cout << "Yes" << endl;
            return 0;
        }
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    else{
        if(size4 >= size1){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 1528
A,B= map(int,input().split())

Bb = format(B,"b")
l = len(Bb)
#Ab = format(A, "b").zfill(l)

ans = []
for i in range(l-1,0,-1):
  d = 2**(i)
  #if (B-(A-1))%d == 0:
  #  ans.append('0')
  #  print('a')
  if (B//d%2 == 0)&(A//d%2 == 0):
    ans.append('0')
  elif (B//d%2 == 0)&(A//d%2 != 0):
    if A%d%2 == 0:
      ans.append('0')
    else:
       ans.append('1')
  elif (B//d%2 != 0)&(A//d%2 == 0):
    if B%d%2 == 0:
       ans.append('1')
    else:
       ans.append('0')
  elif (B//d%2 != 0)&(A//d%2 != 0):
    if B%d%2 == A%d%2:
       ans.append('1')
    else:
       ans.append('0')
if (B-(A-1))%4 ==0:
  ans.append("0")
elif (B-(A-1))%4 ==2:
  ans.append("1")
elif (B-(A-1))%4 ==3:
  if A%2==0:
    ans.append("1")
  else:
    ans.append("0")
else:
  if A%2==0:
    ans.append("0")
  else:
    ans.append("1")
             
print(int('0b'+''.join(ans),2))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
const int inf =2e9;
int N,top=0;
int st[maxn];
int main(){
    cin>>N;
    st[top]=-inf;
    for(int i=1;i<=N;i++){
        int x;
        cin>>x;
        x=-x;
        if(x>=st[top])st[++top]=x;
        else{
            int l=1,r=top;
            while(l<=r){
                int mid=(l+r)/2;
                if(x>=st[mid])l=mid+1;
                else r=mid-1;
            }
            st[l]=x;
        }
    }
    cout<<top<<endl;
}


Measured memory_bytes: 3900
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n;
int a[100000];

int main(int argc, char **argv) {
	cin >> n;
	map<int, int> m;
	REP(i, n) {
		cin >> a[i];
		++m[a[i]];
	}
	int res = 0, cnt = 0;
	for (auto &p : m) {
		while (p.second >= 3) {
			++res;
			p.second -= 2;
		}
		if (p.second >= 2) ++cnt;
	}
	res += (cnt + 1) / 2;
	cout << (n - res * 2) << endl;
	return 0;
}


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

int main(){
	char s[200];
	scanf("%s",s);
	int len=strlen(s);
	int l=0,r=len-1;
	int ans=0;
	while (l<r){
		if (s[l]!=s[r]) ans++;
		l++;r--;
	}
	printf("%d",ans);
	return 0;
}

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

int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(void){
  int a;
  cin >> a;
  if (1200 > a) cout << "ABC" << endl;
  else if (2800 > a) cout << "ARC" << endl;
  else cout << "AGC" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    ll n, k;
    cin >> n >> k;

    bool sunuke[n] = {};

    rep(i, k){
        ll d;
        cin >> d;
        rep(i, d){
            ll a;
            cin >> a;
            sunuke[a-1] = true;
        }
    }

    ll ans = 0;
    rep(i, n)if(!sunuke[i])ans++;

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
bool check(string s);//プロトタイプ宣言

int main(){
  string s;
  cin >> s;
  //関数を作っちゃう
  if (check(s)){
    cout << "AC" << endl;
  }
  else {
    cout << "WA" << endl;
  }
  return 0;
}
  //おかしいの見つけたら即座にfalseを返して最後のcheckまで耐えられたら0を返す
bool check(string s){
    if(s[0]!='A') return false;
    int c=0;
    for (int i=2;i<s.length()-1;++i){
      if (s[i]=='C') c++;
    }
    if (c!=1) return false;
    
    int upper=0;
    for (int i=0;i<s.length();++i){
      if (s[i]>='A'&&s[i]<='Z'){
        upper++;
      }
    }
    if (upper!=2) return false;
    return true;
}
    


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $behind_int);
fscanf(STDIN, "%s", $string);

$alpha_s = range('A','Z');
$str_splited_string = str_split(trim($string));
$result_string = "";

foreach ($str_splited_string as $key => $val) {
  $current_alphanum = array_search($val, $alpha_s);
  $next_alphanum = $current_alphanum + $behind_int;
  if ($next_alphanum > 25) {
    $next_alphanum = $next_alphanum % 26;
  }
  $result_string .= $alpha_s[$next_alphanum];
}

echo $result_string;

Measured memory_bytes: 4728
#include<iostream>

using namespace std;



main(){
  double minv;
  while(cin >>minv){
    int i,ans=0;
    double t = minv/9.8;
    double y;
    y = 4.9*t*t;
    double tall;
    for(i=1;; i++){
      tall = 5*i-5;
      if(tall >= y){ans=i;break;}
    }

    cout << ans << endl;

    
  }





  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;

struct tree{
	long long int val;
	struct tree* left;
	struct tree* right;
	int w;
	long long int weight;
};
typedef struct tree* Tree;

Tree insertNode(long long value, Tree root) {
	if (root == nullptr) {
		root = new struct tree();
		root -> val = value;
		root -> left = root -> right = nullptr;
		root -> w = 1;
		root -> weight = root -> val;
		return root;
	}	
	root -> w += 1;	
	root -> weight += value;
	if (root -> val == value) {
		return root;
	}

	if (root -> val > value) {
		root -> left = insertNode(value, root -> left);
	}
	else {
		root -> right = insertNode(value, root -> right);
	}
	return root;
}
// return w and weight
pair<long long int, long long int> searchNode(int n, Tree root, long long int previousWeight) {
	
	if (root -> right != nullptr && root -> w - root -> right -> w < n) {
		return searchNode(n - root -> w + root -> right -> w, 
			root -> right, 
			root -> weight - root -> right -> weight + previousWeight) ;
	}

	if ((root -> left == nullptr) || root -> left -> w < n) {
		if (root -> left == nullptr) 
			return make_pair(root -> val, root -> val * n + previousWeight);
		else
			return make_pair(root -> val, previousWeight + root -> left -> weight + root -> val * (n - root -> left -> w));
	}
	return searchNode(n, root -> left, previousWeight);
}

int main(int argc, char *argv[]) {
	Tree root = nullptr;
	int q;
	cin >> q;
	long long bs = 0, as = 0;
	int num = 0;
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			long long int a, b;
			cin >> a >> b;
			bs += b;
			as += a;
			num++;
			root = insertNode(a, root);
		}
		else {
			pair<long long int, long long int> p = searchNode((num - 1) / 2 + 1, root, 0);
			int n = (num - 1) / 2 + 1;
			// cout << p.second << endl;
			cout << p.first << " " << (n * p.first - p.second) - (num - n) * p.first + as - p.second + bs << endl;
		}
	}
	
}



Measured memory_bytes: 7296
k = int(input())
a = list(map(int, input().split()))
def solve():

    if a[k-1] != 2:
        print(-1)
        return

    mi = 2
    mx = 2

    for i in range(k):
        j = k-i-1

        mx = mx + a[j] - 1

        if j == 0:
            pass
        else:
            na = a[j-1]
            
            if mx % na != 0 and mi % na != 0 and ((mx % na) - (mi % na)) == (mx - mi):
                print(-1)
                return

            if mi%na != 0:
                mi = mi + (na - mi%na)

            if mx%na != 0:
                mx = mx - (mx % na)

    print(mi, mx)
solve()


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

const int INF = 1<<29;

const int MAX_N = 100, MAX_M = 100;

int n, m;
int G[MAX_N][MAX_N];
int d[MAX_N];
bool visited[MAX_N];

int main(){
    while(scanf("%d%d", &n, &m) && (n||m)){
        for(int x = 0; x < n; x++){
            for(int y = 0; y < n; y++){
                if(x - y) G[x][y] = INF;
                else G[x][y] = 0;
            }
        }
        for(int x = 0; x < m; x++){
            int a, b, c;
            scanf("%d%d%d", &a, &b, &c);
            G[a][b] = c;
            G[b][a] = c;
        }
        fill(d, d+n, INF);
        fill(visited, visited+n, false);
        d[0] = 0;
        visited[0] = true;
        int ans = 0;
        int a = 0;
        for(int x = 0; x < n; x++){
            int v = -1;
            for(int y = 0; y < n; y++){
                if(visited[y]) continue;
                d[y] = min(d[y], G[a][y]);
                if(v == -1 || d[y] < d[v]){
                    v = y;
                }
            }
            if(v == -1) break;
            visited[v] = true;
            ans += d[v];
            a = v;
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1228
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N;
int D;
int ans;

int main(){
	cin >> N >> D;
	D *= 2;
	D++;
	ans = N / D;
	if (N%D != 0)ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
while(1):
    num=int(raw_input())
    if num==0:
        break
    else:
        d=[0,1,2,3,4,5,6]
        sum=1
        for i in range(num):
            dir=num=raw_input()
            if dir=="North":
                d=[0,d[2],d[6],d[3],d[4],d[1],d[5]]
            elif dir=="East":
                d=[0,d[4],d[2],d[1],d[6],d[5],d[3]]
            elif dir=="West":
                d=[0,d[3],d[2],d[6],d[1],d[5],d[4]]
            elif dir=="South":
                d=[0,d[5],d[1],d[3],d[4],d[6],d[2]]
            elif dir=="Right":
                d=[0,d[1],d[3],d[5],d[2],d[4],d[6]]
            else:
                d=[0,d[1],d[4],d[2],d[5],d[3],d[6]]
            sum=sum+d[1]
        print sum

Measured memory_bytes: 4784
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
int main(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  int n;cin >> n;
  while(n--){
    int a,b;cin >> a >> b;
    if(d.left()==a) d.roll('E');
    if(d.right()==a) d.roll('W');
    while(d.top()!=a) d.roll('N');
    while(d.front()!=b) d.roll('R');
    cout << d.right() << endl;
  }
  return 0;
}



Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main(){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    int ans;
    if(K>=A){
        ans += A;
        if(K-A > B){
            if(K-A-B > C){
                ans -= C;
            }else{
                ans -= K-A-B;
            }
        }else{}
    }else{
        ans = K;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int n,x,t;
    cin>>n>>x>>t;
    cout<<(n+x-1)/x*t<<endl;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MSIZE = 100100;

vector<int> g[MSIZE];
vector<int> order;
bool used[MSIZE];

void Dfs(int from) {
    used[from] = true;
    for (int v : g[from]) {
        if (used[v]) continue;
        Dfs(v);
    }
    order.push_back(from);
}

int dp[MSIZE];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    memset(dp, 0, sizeof dp);
    for (int i = 0; i < m; i++) {
        int f, t;
        cin >> f >> t;
        f--, t--;
        g[f].push_back(t);
    }
    for (int i = 0; i < n; i++) {
        if (!used[i]) Dfs(i);
    }
  
    int ans = 0;
    for (int v : order) {
        for (int nxt : g[v]) {
            dp[v] = max(dp[v], dp[nxt] + 1);
        }
        ans = max(ans, dp[v]);
    }
    cout << ans << endl;

}

Measured memory_bytes: 8956
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    vector<ll> a(7);
    for(int i = 0; i < 7; ++i)  cin >> a[i];
    ll ans = a[0] / 2 * 2 + a[1] + a[3] / 2 * 2 + a[4] / 2 * 2;
    if(a[0] > 0 && a[3] > 0 && a[4] > 0){
        ll foo = a[1];
        --a[0], --a[3], --a[4];
        foo += 3;
        foo += a[0] / 2 * 2 + a[3] / 2 * 2 + a[4] / 2 * 2;
        chmax(ans, foo);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
a, b, x = map(int, input().split())
import math
if x == b * a** 2:
  print(0)
elif x  <= 0.5 * b * a **2:
  print(round(90 - math.degrees(math.atan(2*x / (a * b ** 2))),10))
else:
  print(round(90 - math.degrees(math.atan(a/  (2*(b-x/(a**2)))  )),10))

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using namespace std;
int a[20][20], t[1<<16];
long long dp[1<<16], s[1<<16];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &a[i][j]);
		}
		t[1<<i] = i;
	}
	for (int i = 1; i < 1 << n; i++) {
		dp[i] = -1ll << 61;
		int ni = i & (i - 1), k = t[i^ni];
		s[i] = s[ni];
		for (int j = 0; j < n; j++) {
			if (ni >> j & 1) s[i] += a[j][k];
		}
	}
	for (int i = 1; i < 1 << n; i++) {
		for (int j = i; j; j = i & (j - 1)) {
			dp[i] = max(dp[i], s[j] + dp[i^j]);
		}
	}
	printf("%lld\n", dp[(1<<n)-1]);
	return 0;
}


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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n, m;
	cin >> n >> m;
	priority_queue<int,vi,less<int>> a;
	rep(i, n) {
		int k;
		cin >> k;
		a.push(k);
	}

	rep(i, m) {
		int k;
		k = a.top();
		a.pop();
		k /= 2;
		a.push(k);
	}

	ll ans = 0;

	rep(i, n) {
		ans += a.top();
		a.pop();
	}

	cout << ans << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	deque<char> d(s.begin(), s.end());
	bool flag = 1;
	int q;
	char c;
	cin >> q;
	while(q--){
		int t,f;
		cin >> t;
		if(t == 1)flag = !flag; else {
			cin >> f >> c;
			--f;
			if(flag ^ f)d.push_front(c); else d.push_back(c);
		}
	}
	while(!d.empty()){
		if(flag)cout << d.front(); else cout << d.back();
		if(flag)d.pop_front(); else d.pop_back();
	}
	return 0;
	
} 

Measured memory_bytes: 976
n=int(input())
li=list(map(int,input().split()))

count=0
for i in range(n-2):
  a=li[i]
  b=li[i+1]
  c=li[i+2]
  if (a<b and (b<c or b==c)) or (c<b and (b<a or b==a)):
    count+=1
print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
#include<climits>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<unordered_set>
#include<unordered_map>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack> 
using namespace std;
#define ff              first
#define ss              second
#define int             unsigned long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define si              set<int>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define sp(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(t)            int t; cin>>t; while(t--)
#define asc(i,a,n)      for (int i=a;i<n;i++)
#define dsc(i,a,n)      for (int i=n-1;i>=a;i--)
#define sz(x)           ((int)(x).size())
#define flg             if(flag==0)cout<<"Yes"<<endl;else{cout<<"No"<<endl;}
#define FLG             if(flag==0)cout<<"YES"<<endl;else{cout<<"NO"<<endl;}
#define input(arr,n)    for(int i=0; i<n ; i++) cin>>arr[i];
#define output(arr,n)   for(int i=0; i<n ; i++) cout<<arr[i]<<" ";
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"



int32_t main()
{

  int a=1 , b;

  b = 1e18;


  int n ;

  cin>>n;

  int arr[n];


  for(int i=0; i < n ; i++)
    cin>>arr[i];


  sort(arr, arr+n);


  if(arr[0]==0)
  {
    cout<<"0"<<endl;
    return 0;
  }

  
  for(int i=0; i<n ; i++)
  {

    if(a >(b/arr[i]))
    {
      cout<<"-1"<<endl;
      return 0;
    }
     a*=arr[i];


  }


  cout<<a<<endl;







    


    








  


    return 0;
}





Measured memory_bytes: 4432