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

#define ascent(i, a, b) for(int i = a; i < b; i ++)
#define loop(_n) for(int lp; lp < _n; lp ++)

#define pic pair<int, char>
#define pist pair<int, string>

using namespace std;

int D;
vector<int> ap;
vector<int> bcq;

int search(int level, int ans, int d) {
  int point;
  int nxt_d;

  if(level >= ap.size() + bcq.size()) { return ans; }
  if(d <= 0) { return ans; }

  if(level >= ap.size() && d >= 2) {
    point = bcq[level-ap.size()];
    nxt_d = 2;
  }
  else if(level >= ap.size() && d < 2) {
    return ans;
  }
  else if(level < ap.size()) {
    point = ap[level];
    nxt_d = 1;
  }
  
  return max(search(level+1, ans+point, d-nxt_d), search(level+1, ans, d));
}

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

  ascent(i, 0, x) {
    char a;
    int  p;
    cin >> a >> p;
    if(a == 'D') ap.push_back(p);
  }

  int y;
  cin >> y;
  ascent(i, 0, y) {
    string bc;
    int q;
    cin >> bc >> q;
    if(bc == "DD") bcq.push_back(q);
  }

  cout << search(0, 0, D) << endl;
  return 0;
}

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

using namespace std;

int main(){

  long long int x;
  cin>>x;

  long long int cnt=0;

  long long int ans=0;

  if(x%11==0){ 
    cnt = (x/11)*2;
    cout<<cnt<<endl;
  }
  else if(x%11!=0){ 
    cnt=(x/11)*2+2;
    if(((cnt/2)*11)-5<x) cout<<cnt<<endl;
    else if (((cnt/2)*11)-5>=x) cout<<cnt-1<<endl;
  } 
}


Measured memory_bytes: 3632
N = int(input())
best_count = 0
ans = 1

while (N > 0):
  n = N
  count = 0
  while(True):
    if n % 2 != 0:
      break
    else:
      n /= 2 
      count += 1
  if count > best_count:
    ans = N
    best_count = count
  N -= 1
  
print(ans)
        

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int findSumOfDigits(int n)
{
  int sum = 0;
  while (n > 0)
  { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
main()
{
  int N;
  cin>>N;
  int sum = findSumOfDigits(N);
  if(N%sum==0)
    cout << "Yes" << endl;
    else
      cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define pi acos(-1)
#define int long long int
#define ld long double
#define ar array
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<int> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const int ths = 1LL << 40;
const int NN = 5e3 + 6;

const int maxN = 1003;

///

void solve()
{

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

    for(int i = 0; i < n; i ++) {
        int x = t ^ a[i];
        cout<<x<<' ';
    }

    cout<<"\n";
    return ;
}

/*
*/

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 5104
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n, x = 0, ans = 0;
    sc(n)
    string s;
    cin >> s;
    for (int i = 0; i < n; i++){
        if (s[i] == 'I') x += 1;
        else x -= 1;
        ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    ll n,p;
    cin>>n>>p;
    vector<ll> a(n);
    bool ok = true;
    for(ll i=0; i<n; i++) {
        cin>>a[i];
        if(a[i] % 2 == 1) ok = false;
    }
    ll ans1 = pow(2,n);
    ll ans2 = pow(2,n-1);
    if(ok) {
        if(p == 0) cout<< ans1 <<endl;
        else cout<< 0 <<endl;
        return 0;
    }
    else {
        cout<< ans2 <<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
const int  n=100;
 int arr[n];
int main()
{

   int n,k=0,sum=0;
   cin>>n;
   int val=n;
  while(k<val)
  {
      if(n<5)
      {
          break;
      }
      if(n>=500)
      {
          k=k+500;
          sum=sum+1000;
          n=n-500;
      }
      else
        {
        k=k+5;
        sum=sum+5;
        n=n-5;
      }

  }
  cout<<sum;




}

Measured memory_bytes: 256
N = int(input())
if N == 0:
    print(0)
    exit()
res = ""
while N != 1:
    res += str(abs(N%(-2)))
    if N%2 == 0:
        N //= -2
    else:
        N //= -2
        N += 1
res += '1'
print(res[::-1])

Measured memory_bytes: 3060
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

void solve();

char c;

int main() {
  cin >> c;

  solve();

  return 0;
}

void solve() {

  if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;

  return;
}

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

int main()
{
	int n,k;
	cin >> n >> k;
	int ans  = 1000000;
	for(int i = 0;i<=n;i++)
	{
		int a = 1;
		for(int j = 0;j<i;j++)a*=2;
		for(int j = i;j<n;j++)a+=k;
		ans = min(ans,a);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int H, W;
char A[10][10];
bool visited[10][10];

bool dfs(int y, int x)
{
    visited[y][x] = true;
    
    if (y == H - 1 && x == W - 1){
        if (!(A[y-1][x]=='#' && !visited[y-1][x]) && !(A[y][x-1]=='#' && !visited[y][x-1])) {
            return true;
        }
    }
        
    if (x<W-1 && A[y][x+1]=='#' && y<H-1 && A[y+1][x]=='#') return false;
    else if ((0<x && !visited[y][x-1] && A[y][x-1]=='#') || (0<y && !visited[y-1][x] && A[y-1][x]=='#')) return false;
    else if (x<W-1 && A[y][x+1]=='#') return dfs(y, x+1);
    else if (y<H-1 && A[y+1][x]=='#') return dfs(y+1, x);
    else return false;
}

signed main()
{
    cin >> H >> W;
    REP(i,H) REP(j,W) cin >> A[i][j];

    if (dfs(0, 0)) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    int main()
    {
    	cin.tie(0);
        ios::sync_with_stdio(0);
    	int a,b,c,d;
    	cin>>a>>b>>c>>d;
        while(true){
        	c-=b;
        	if(c<=0){
        		cout<<"Yes\n";return 0 ;}
            a-=d;
            if(a<=0){
            	cout<<"No\n";return 0;}
        }
    	return 0;
    }
    

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using ll = int_fast64_t;
#define REP(i,b,e) for(ll i=b; i<e; i++)
const int MOD = 1e9+7;
const int MAX = 1e5+10;

ll fac[MAX], finv[MAX], inv[MAX];

void combinit(){
	fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
	REP(i, 2, MAX){
		fac[i] = fac[i-1]*i % MOD;
		inv[i] = MOD - inv[MOD%i]*(MOD/i) % MOD;
		finv[i] = finv[i-1]*inv[i] % MOD;
	}
}

ll comb(int n, int k){
	if(n<k) return 0;
	if(n<0 || k<0) return 0;
	return fac[n] * (finv[k]*finv[n-k] % MOD) % MOD;
}

int main(){
	int n;
	scanf("%d", &n);
	int a[n+1], cnt[n] = {}, doub;
	REP(i, 0, n+1){
		scanf("%d", &a[i]);
		if(++cnt[a[i]-1]>1) doub = a[i];
	}

	int sep[3] = {}, pos = 0;
	REP(i, 0, n+1){
		if(a[i]==doub) pos++;
		else sep[pos]++;
	}

	combinit();
	REP(i, 1, n+2){
		ll ans = comb(n+1, i);
		ans -= comb(sep[0]+sep[2], i-1);
		ans = (ans + MOD) % MOD;
		printf("%ld\n", ans);
	}
	return 0;
}



Measured memory_bytes: 6888
main = interact $ show . sol . map read . words

sol [h,w] 
  | h `mod` 3==0 || w `mod` 3==0  = 0
  | otherwise                     = minimum $ concatMap f [(h,w), (w,h)]

f (x,y) = [x, x*a - (x `div` 2)*(y-a), ((x+1) `div` 2)*(y-a') - x*a']
  where
  (a,a') = ((y+2) `div` 3, y `div` 3)

Measured memory_bytes: 508
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a * b == 15) {
        cout << "*" << endl;
    } else if(a + b == 15) {
        cout << "+" << endl;
    } else {
        cout << "x" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
const int N=105;
int n,m,x,B[N][N],lf[N],C[N][N],d[N],f[N];
bool vis[N],e[N][N];
vector<int>vec[N][N];
bool dfs(int v){
    for(int i=1;i<=n;++i)
    if(!vis[i]&&e[v][i]){
        vis[i]=1;
        if(!lf[i]||dfs(lf[i])){
            lf[i]=v;
            return 1;
        }
    }
    return 0;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j)
        cin>>x,vec[i][(x-1)/m+1].push_back(x);
    }
    for(int i=1;i<=m;++i){
        memset(e,0,sizeof e);
        for(int j=1;j<=n;++j)
        for(int k=1;k<=n;++k)e[j][k]=!vec[j][k].empty();
        memset(lf,0,sizeof lf);
        for(int j=1;j<=n;++j){
            memset(vis,0,sizeof vis);
            dfs(j);
        }
        for(int j=1;j<=n;++j){
            d[lf[j]]=f[j]=vec[lf[j]][j].back();
            vec[lf[j]][j].pop_back();
        }
        for(int j=1;j<=n;++j)B[j][i]=d[j],C[j][i]=f[j];
    }
    for(int i=1;i<=n;++i)
    for(int j=1;j<=m;++j)
    cout<<B[i][j]<<" \n"[j==m];
    for(int i=1;i<=n;++i)
    for(int j=1;j<=m;++j)
    cout<<C[i][j]<<" \n"[j==m];
    return 0;
}

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

class Node
{
public:
    ll val;
};

class Graph
{
public:
    vector<Node> Nodes;
    vector<vector<ll>> G;
    Graph(ll N)
    {
        this->G = vector<vector<ll>>(N);
        this->Nodes = vector<Node>(N);
    };
    void addEdge(ll a, ll b)
    {
        this->G[a].push_back(b);
        this->G[b].push_back(a);
    };
};


int main(void)
{
    ll N, Q;
    cin >> N >> Q;
    Graph g(N);
    
    rep(i, N - 1)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        g.addEdge(a,b);
    }

    rep(i, Q)
    {
        ll p, x;
        cin >> p >> x;
        p--;
        g.Nodes[p].val += x;
    }

    //根から全ての木をたどる
    auto dps = [&](auto dps, ll n, ll p) -> void {
        for_each(g.G[n].begin(), g.G[n].end(), [&](auto v) {
            if (v != p)
            {
                g.Nodes[v].val += g.Nodes[n].val;
                dps(dps, v, n);
            }
        });
        return;
    };

    dps(dps, 0, -1);
    rep(i, N)
    {
        if (i > 0)
            cout << " ";
        cout << g.Nodes[i].val;
    }
    cout << endl;
}




Measured memory_bytes: 31488
#import sys
#input = sys.stdin.readline
def eratosthenes(N):
    from collections import deque
    work = [True] * (N+1)
    work[0] = False
    work[1] = False
#    ret = []
    for i in range(N+1):
        if work[i]:
#            ret.append(i)
            for j in range(2* i, N+1, i):
                work[j] = False
    return work

def main():
    primes = eratosthenes(2*10**5)
    X = int( input())
    for i in range(X, 2*10**5):
        if primes[i]:
            print(i)
            return
if __name__ == '__main__':
    main()


Measured memory_bytes: 4980
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;

int main(){
    string S;
    cin >> S;
    if(S == "ABC"){
        cout << "ARC" << endl;
    }
    else{
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define f(i, j) f[i][j+3000]
#define int long long 

using namespace std;
const int N = 6100;

int n, P;
int f[N][N+3000];

signed main(void)
{
	cin >> n >> P;
	f(0, 0) = 1;
	for (int i = 0; i < n * 3; ++ i)
		for (int j = -n; j <= 3 * n; ++ j) {
			f(i+1, j+1) = (f(i+1, j+1) + f(i, j)) % P;
			f(i+2, j-1) = (f(i+2, j-1) + f(i, j) * (i + 1) % P) % P;
			f(i+3, j) = (f(i+3, j) + f(i, j) * (i + 1) % P * (i + 2) % P) % P; 
		}
	int res = 0;
	for (int i = 0; i <= n; ++ i) res = (res + f(n*3, i*3)) % P;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 402860
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  string S;
  cin>>S;
  bool CAN=true;
  REP(i,S.size()){
    if(i%2==0 && S.at(i)=='L'){
      CAN=false;
      break;
    }
    else if(i%2==1 && S.at(i)=='R'){
      CAN=false;
      break;
    }
  }
  
  
  if(CAN) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main() {
  int N;
  cin >> N;
  long long A[N];

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

  long long ans = A[N - 1] - A[0];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
typedef pair<double,double> P;
double po(double d){return d*d;}
int main(){
    vector<P> ps;
    double x,y;
    while(scanf("%lf,%lf\n",&x,&y)!=-1){
        ps.push_back(make_pair(x,y));
    }
    double s=0;
    for(int i=1;i+1<ps.size();i++){
        double x[3],y[3];
        x[0]=ps[0].first;
        x[1]=ps[i].first;
        x[2]=ps[i+1].first;
        y[0]=ps[0].second;
        y[1]=ps[i].second;
        y[2]=ps[i+1].second;
        double a=sqrt(po(x[0]-x[1])+po(y[0]-y[1])),b=sqrt(po(x[1]-x[2])+po(y[1]-y[2])),c=sqrt(po(x[2]-x[0])+po(y[2]-y[0])),z=(a+b+c)/2;
        s+=sqrt(z*(z-a)*(z-b)*(z-c));
    }
    printf("%lf\n",s);
}

Measured memory_bytes: 0
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
print = sys.stdout.write
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

class SegmentTree:
    def __init__(self,N,d):
        self.N0 = 2**(N-1).bit_length()
        self.node = [d]*(self.N0*2)
        self.lazy = [None]*(self.N0*2)

    def gindex(self,l,r):
        L = l + self.N0
        R = r + self.N0
        lm = (L // (L & -L)) >> 1
        rm = (R // (R & -R)) >> 1
        while L < R:
            if R <= rm:
                yield R
            if L <= lm:
                yield L
            L >>= 1; R >>= 1
        while L:
            yield L
            L >>= 1

    def propagates(self,*ids):
        for i in reversed(ids):
            v = self.lazy[i-1]
            if v is None:
                continue
            self.lazy[2*i-1] = self.lazy[2*i] = v
            self.node[2*i-1] = self.node[2*i] = v
            self.lazy[i-1] = None

    def update(self,l,r,x): #iの値をxに更新
        *ids, = self.gindex(l, r)

        # トップダウンにlazyの値を伝搬
        self.propagates(*ids)

        # 区間[l, r)のnode, lazyの値を更新
        L = self.N0 + l
        R = self.N0 + r
        while L < R:
            if R & 1:
                R -= 1
                self.lazy[R-1] = self.node[R-1] = x
            if L & 1:
                self.lazy[L-1] = self.node[L-1] = x
                L += 1
            L >>= 1; R >>= 1

        # 伝搬させた区間について、ボトムアップにnodeの値を伝搬する
        for i in ids:
            self.node[i-1] = self.process(self.node[2*i-1], self.node[2*i])

    def query(self,l, r):
        # トップダウンにlazyの値を伝搬
        self.propagates(*self.gindex(l, r))
        L = self.N0 + l
        R = self.N0 + r

        # 区間[l, r)の最小値を求める
        s = INF
        while L < R:
            if R & 1:
                R -= 1
                s = self.process(s, self.node[R-1])
            if L & 1:
                s = self.process(s, self.node[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

    def process(self,x,y): #x,yが子の時，親に返る値
        return min(x,y)

N,Q = inpl()
ST = SegmentTree(N,2**31-1)
ans = []
for _ in range(Q):
    c,*arg = inpl()
    if c:
        s,t = arg
        ans.append(str(ST.query(s,t+1)))
    else:
        s,t,x = arg
        ST.update(s,t+1,x)

print('\n'.join(ans))
print('\n')



Measured memory_bytes: 19312
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n, k; cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int cnt = 0;
    for (int x : h) {
        if (x >= k) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    

    string s;
    cin >> s;
    if(s[0] == s[1] or s[1] == s[2] or s[2] == s[3]){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

#define PC __builtin_popcountll

int main() {
	int n;
	cin >> n;
	vector<vector<pair<int, int>>> g(n);
	inc(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].EB(b, i);
		g[b].EB(a, i);
	}
	vector<int> sv(n), se(n - 1);
	int m;
	cin >> m;
	inc(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		sv[a] ^= 1 << i;
		sv[b] ^= 1 << i;
	}
	
	function<int(int, int, int, int)> dfs = [&](int v, int pv, int pe, int S) {
		S ^= sv[v];
		RF(e, g[v]) {
			int nv = e.FI;
			int ne = e.SE;
			if(nv == pv) { continue; }
			se[ne] ^= S;
			S = dfs(nv, v, ne, S);
		}
		if(pe != -1) { se[pe] ^= S; }
		return S;
	};
	dfs(0, -1, -1, 0);
	
	LL ans = 0;
	inc(B, 1 << m) {
		int t = 0;
		inc(i, n - 1) { if((se[i] & B) != 0) { t++; } }
		ans += (PC(B) % 2 == 0 ? +1 : -1) * (1LL << (n - 1 - t));
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main(){
    //入力
    string ABCD;
    cin >> ABCD;

    //処理
    char op1,op2,op3;
    for(int i=0;i<(1<<3);i++){//1:+ 0:-
    int res=(int)(ABCD.at(0)-'0');
        if(i&(1)){
            res+=(ABCD.at(1)-'0');
            op1='+';
        }else{
            res-=(ABCD.at(1)-'0');
            op1='-';
        }

        if(i&(1<<1)){
            res+=(ABCD.at(2)-'0');
            op2='+';
        }else{
            res-=(ABCD.at(2)-'0');
            op2='-';
        }

        if(i&(1<<2)){
            res+=(ABCD.at(3)-'0');
            op3='+';
        }else{
            res-=(ABCD.at(3)-'0');
            op3='-';
        }
        if(res==7) break;
    }

    //出力
    cout << ABCD.at(0) << op1 << ABCD.at(1) << op2 << ABCD.at(2) << op3 << ABCD.at(3) << "=7" << endl;
}

Measured memory_bytes: 256
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

signed main()
{
  double pi = 3.141592653589793;
  double R;

  cin >> R;

  cout << 2.0 * pi * R << endl;
}


Measured memory_bytes: 3788
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <vector>
#define MAXN 100000

using namespace std;

int N, K;
vector <int> adj[MAXN];
int val[MAXN];
int par[MAXN];
bool vis[MAXN];

int parity[MAXN];
int minval[MAXN], maxval[MAXN];

void dfs(int i, int prv) {
    par[i] = prv;
    for (int j : adj[i])
        if (j != prv)
            dfs(j, i);
}

void dfs_set(int i) {
    int prv = par[i];
    if (prv == -1) {
        val[i] = minval[i];
        assert((val[i] % 2 + 2) % 2 == parity[i]);
    }
    else if (val[i] == -1) {
        if (val[prv] - 1 >= minval[i] && val[prv] - 1 <= maxval[i])
            val[i] = val[prv] - 1;
        else
            val[i] = val[prv] + 1;
    }
    for (int j : adj[i])
        if (j != prv)
            dfs_set(j);
}

bool solve() {
    for (int i = 0; i < N; i++) {
        if (adj[i].size() > 1)
            continue;
        int prv = i;
        int cur = par[i];
        while (cur != -1) {
            vis[prv] = true;
            if (parity[prv] != -1) {
                if (parity[cur] != -1) {
                    if (parity[cur] != 1 - parity[prv])
                        return false;
                    // opt: if no change, done
                    if (vis[cur]
                            && minval[cur] >= minval[prv] - 1
                            && maxval[cur] <= maxval[prv] + 1)
                        break;
                    minval[cur] = max(minval[cur], minval[prv] - 1);
                    maxval[cur] = min(maxval[cur], maxval[prv] + 1);
                    if (minval[cur] > maxval[cur])
                        return false;
                }
                else {
                    parity[cur] = 1 - parity[prv];
                    minval[cur] = minval[prv] - 1;
                    maxval[cur] = maxval[prv] + 1;
                }
            }
            prv = cur;
            cur = par[cur];
        }
    }
    return true;
}

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    for (int i = 0; i < N; i++) {
        val[i] = -1;
        parity[i] = -1;
    }
    scanf("%d", &K);
    int root = -1;
    for (int i = 0; i < K; i++) {
        int v, p;
        scanf("%d%d", &v, &p);
        v--;
        root = v;
        val[v] = p;
        parity[v] = p % 2;
        minval[v] = maxval[v] = p;
    }

    dfs(root, -1);

    if (solve()) {
        dfs_set(root);
        printf("Yes\n");
        for (int i = 0; i < N; i++)
            printf("%d\n", val[i]);
    }
    else {
        printf("No\n");
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int now = 0;
  int ans = now;
  for (int i = 1; i < n; ++i) {
    if (h[i] <= h[i-1]) ++now;
    else now = 0;
    ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define fi first
#define se second
#define tc int t; cin>>t; while(t--)
#define mod 1000000007
#define pie 3.141592653589793
#define endl "\n"
using namespace std;

void fastio(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed;
    cout.precision(9);
}

int main(){
    fastio();
	int n;
	cin>>n;
	n=n%10;
	if(n==0 or n==1 or n==6 or n==8)cout<<"pon";
	else if(n==3)cout<<"bon";
	else cout<<"hon";
    return 0;
}

Measured memory_bytes: 3652
# 2019/05/25
# AtCoder Beginner Contest 127 - C

# Input
n, m = map(int,input().split())

# Search Max L & Min R
max_l = -1
min_r = n + 1
for i in range(m):
    l, r = map(int,input().split())
    if l > max_l:
        max_l = l
    if r < min_r:
        min_r = r

ans = max(min_r - max_l + 1, 0)

# Output
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>
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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c));
typedef long long ll;

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

  vector<int> sumE(n + 1), sumW(n + 1);
  sumE[0] = 0, sumW[0] = 0;
  for (int i = 1; i <= n; i++)
  {
    if(s[i - 1] == 'E') {
      sumE[i] = sumE[i - 1] + 1;
      sumW[i] = sumW[i - 1];
    }
    else{
      sumE[i] = sumE[i - 1];
      sumW[i] = sumW[i - 1] + 1;
    }
  }
  

  int ans = 1e9;
  for(int i = 0; i < n; i++){
    int right, left, num;
    num = sumW[i] + (sumE[n] - sumE[i + 1]);
    ans = min(ans, num);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3076
#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int ma=1e5+10;
int a,b;
pair<int,int> c[ma];
priority_queue<int> q;
main()
{
    scanf("%d%d",&a,&b);
    for(int i=1;i<=a;i++)
    {
        int x,val;
        scanf("%d%d",&x,&val);
        c[i].first=b-x+1,c[i].second=val;
    }
    long long ret=0;
    sort(c+1,c+a+1);
    for(int i=b,j=a;i;i--)
    {
        for(;j;j--)
        {
            if(c[j].first<i)break;
            q.push(c[j].second);
        }
        if(!q.empty())
        {
            ret+=q.top();
            q.pop();
        }
    }   
    printf("%lld\n",ret);

}

Measured memory_bytes: 1660
from collections import deque
from typing import List


def get_longest_path_depth(
    graph: List[List[int]], in_degrees: List[int], first_index: int = 0
) -> int:
    """Return the depth of the longest path of DAG.
    if the given graph is not DAG, -1 is returned.
    """
    V = len(graph) + first_index
    queue = deque()
    depths = [-1] * V  # depths[i] := the length of the longest path to V_i
    for i in range(first_index, V):
        if not in_degrees[i]:
            queue.append(i)
            depths[i] = 0

    while queue:
        u = queue.popleft()
        cur_depth = depths[u]
        for v in graph[u]:
            in_degrees[v] -= 1
            if not in_degrees[v]:
                depths[v] = max(depths[v], cur_depth + 1)
                queue.append(v)

    return max(depths) if -1 not in depths else -1


def abc139_e():
    N, *A = map(int, open(0).read().split())

    ids = [[-1] * (N + 1) for _ in range(N + 1)]
    cur_id = 0
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            ids[i][j] = ids[j][i] = cur_id
            cur_id += 1

    graph = [[] for _ in range(N * (N - 1) // 2)]
    in_degrees = [0] * (N * (N - 1) // 2)
    for i, a in enumerate(zip(*[iter(A)] * (N - 1)), 1):
        source = -1
        for j in a:
            target = ids[i][j]
            if source != -1:
                graph[source].append(target)
                in_degrees[target] += 1
            source = target

    depth = get_longest_path_depth(graph, in_degrees)
    print(depth + 1 if depth != -1 else -1)


if __name__ == "__main__":
    abc139_e()


Measured memory_bytes: 140092
a, b, h, m = gets.split.map(&:to_i)
pi = Math::PI
rad_a = (60 * h + m) * (pi / 360)
rad_b = m * (pi / 30)
rad = (rad_a - rad_b).abs

puts Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(rad)) 


Measured memory_bytes: 14712
#include<stdio.h>

int main(){
  int h,m,s; //hour, minute, second
  int a; //input

  scanf("%d", &a);

  m=a/60;
  s=a-m*60;
  h=m/60;
  m=m-h*60;

  printf("%d:%d:%d\n", h, m, s);

  return 0;

}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
  int n;
  cin >> n;
  set<string> v;
  string s[1000];
  int p[1000];
  FOR(i,n){
    cin >> s[i] >> p[i];
    v.insert(s[i]);
  
  }

  

  int ans[1000];
  int cnt=1;

  FOR(i,v.size()){
    vector<pair<int,int>> v3;
    auto itr=v.begin();
    FOR(o,i)itr++;
    FOR(j,n){
      if(s[j]==*(itr)){
        v3.push_back(make_pair(p[j],j));
      }
    }
    sort(v3.begin(),v3.end());
    reverse(v3.begin(),v3.end());
    FOR(j,v3.size()){
      ans[cnt-1]=v3[j].second+1;
      cnt++;
      
    }
  }

  FOR(i,n){
    cout << ans[i] << endl;
  }
  
  
}

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

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int Cin()
{
    int n;
    cin >> n;
    return n;
}

int main()
{
    int N = Cin();
    set<int> As;
    for (int i = 0; i < N; ++i)
    {
        int Ai = Cin();
        As.insert(Ai);
    }
    cout << (As.size() == N ? "YES" : "NO") << endl;
}


Measured memory_bytes: 9600
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    int n;
    cin >> n;
    vector<int>an(n);
    for(int i = 0; i < n; i++){
        cin >> an.at(i);
    }
    bool ck = true;
    for(int i = 0; i < n; i++){
        if(an.at(i) % 2 == 0){
            if(an.at(i) % 3 != 0 && an.at(i) % 5 != 0){
                ck = false;
            }
        }
    }
    if(ck){
        cout << "APPROVED" << endl;
    }
    else{
        cout << "DENIED" << endl;
    }
    return 0;
}



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

using namespace std;

class dice {

public:

	int TOP, S, E, W, N, BOTTOM, tmp;

	void rotN () {
		tmp = N;
		N = TOP; TOP = S; S = BOTTOM, BOTTOM = tmp;
	}
	void rotE () {
		tmp = E;
		E = TOP; TOP = W; W = BOTTOM; BOTTOM = tmp;
	}
	void rotW () {
		tmp = W;
		W = TOP; TOP = E; E = BOTTOM; BOTTOM = tmp;
	}
	void rotS () {
		tmp = S;
		S = TOP; TOP = N; N = BOTTOM; BOTTOM = tmp;
	}
	void clockwise () {
		tmp = W;
		W = S; S = E; E = N; N = tmp;
	}
	void antiClockwise () {
		tmp = W;
		W = N; N = E; E = S; S = tmp;
	}
};


bool same_dice(dice dice_1, dice dice_2){

    return true;

}

int main(){

    int i, num, dice_num[6];

    for(i=0;i<6;i++){
        cin >> num;
        dice_num[i] = num;
    }
    dice dice_1 = {dice_num[0], dice_num[1], dice_num[2], dice_num[3], dice_num[4], dice_num[5]};

    for(i=0;i<6;i++){
        cin >> num;
        dice_num[i] = num;
    }
    dice dice_2 = {dice_num[0], dice_num[1], dice_num[2], dice_num[3], dice_num[4], dice_num[5]};

    int j = 0;

    while( (dice_1.TOP != dice_2.TOP || dice_1.BOTTOM != dice_2.BOTTOM) && j != 7){
        dice_1.rotN();
        // cout << "rotN" << endl;
        j++;
        if(j == 4){
            dice_1.rotE();
            // cout << "rotE" << endl;
        }
    }

    if( j == 7){
        cout << "No" << endl;
        return 0;
    }

    j = 0;

    while( (dice_1.N != dice_2.N  || dice_1.E != dice_2.E || dice_1.W != dice_2.W || dice_1.S != dice_2.S) && j < 4){
        dice_1.clockwise();
        // cout << "clock : " << j << endl; 
        j++;
    }

    if(j == 4){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;

}

// https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define forn(i,n) for(int i=0;i<(int) n;i++)
#define Forn(i,n) for(int i=1;i<=(int) n;i++)

int main()
{
  int n,i,j;
  cin>>n;
  int a[n];
  int b[n];
  for(i=0;i<n;i++) cin>>a[i];
  for(i=0;i<n;i++) cin>>b[i];
  int N=n;
  int x=0,y=0;
 for(i=0;i<n;i++)
  {

      if(a[i]>b[i])
      {
          x+=a[i];
          y+=b[i];
      }
  }
   cout<<x-y;

}






Measured memory_bytes: 3608
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        100005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
 
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}


void solve(){ 
    int n,m,k;
    cin >> n >> m >> k;
    vector<int>a(n+5),b(m+5),pb(m+5);
    FOR(i,1,n+1)cin >> a[i];
    FOR(i,1,m+1)cin >> b[i],pb[i] = pb[i-1]+b[i];
    int tot = 0,ans = 0;
    int lo = 0,hi = m;
    while(lo < hi){
        int mid = (lo+hi+1)/2;
        if(pb[mid]+tot <= k)lo = mid;
        else hi = mid-1;
    }
    ans = lo;
    FOR(i,1,n+1){
        tot += a[i];
        if(tot > k)break;
        lo = 0,hi = m;
        while(lo < hi){
            int mid = (lo+hi+1)/2;
            if(pb[mid]+tot <= k)lo = mid;
            else hi = mid-1;
        }
        ans = max(ans,i+lo);
    }
    cout << ans << "\n";
}

signed main()   
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
        solve();
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
long long INF = 1.0e-18;

int main() {
    ll a[200000];
    ll n;
    ll ans = 1;
    bool zero = false;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) zero = true;
    }
    if (zero) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, n) {
        if (ans > 1000000000000000000 / a[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4428
#include<stdio.h>
#include<string.h>
#include <math.h>
#include <stdlib.h>
#define MAX 100

#define M 1000000
#define L 12

char H[M][L];

int getChar(char ch){
  if(ch=='A') return 1;
  else if(ch=='C') return 2;
  else if(ch=='G') return 3;
  else if(ch=='T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key)
{
  return key%M;
}

int h2(int key)
{
  return 1+key%(M-1);
}

int find(char str[])
{
  long long sum;
  int i,j;

  sum = getKey(str);

  for(i=0;;i++){
    j = (h1(sum)+i*h2(sum))%M;
    if(strcmp(H[j],str)==0) return 1;
    else if(strlen(H[j])==0) return 0;
  }
}  

int insert(char str[]){
  long long sum;
  int i,h;

  sum = getKey(str);
  
  for(i=0;;i++){
    h = (h1(sum)+i*h2(sum))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
}

int main(){
  int i,n;
  char str[L],c[9];
  
  for(i=0;i<M;i++) H[i][0] = '\0';
    
  scanf("%d",&n);
    
  for(i=0;i<n;i++){
    scanf("%s%s",c,str);
    if(c[0]=='i') insert(str);
    else{
      if(find(str)==1) printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}  



Measured memory_bytes: 13464
n = int(input())

out = False
word1 = input()
words = [word1]
for i in range(n-1):
    next_w = input()
    if next_w in words:
        out = True
        break
    if next_w[0:1] != words[-1][-1]:
        out = True
        break
    words.append(next_w)
if out:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define rvc(i,S) for(int i=0;i<(int)S.size();++i)
#define fore(i,x) for(int i = head[x] ; i ; i = e[i].next)
//#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define ll long long 
#define LL long long
#define fi first
#define se second
#define sz siz
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
#define maxn 100200
#define int ll
int n,m;
char s1[maxn],s2[maxn];
int gcd(int a,int b)
{if(b==0) return a;
 else return gcd(b,a%b);
}
map<int,int> p;
signed main()
{cin>>n>>m;
 scanf("%s",s1+1); scanf("%s",s2+1);
  int L=(n*m)/gcd(n,m);
  rep(i,0,n-1)
  {int pos=i*(L/n)+1;
   if(p[pos]==0) {p[pos]=s1[i+1]-47;}
  }
   rep(i,0,m-1)
  {int pos=i*(L/m)+1;
   if(p[pos]==0) {p[pos]=s2[i+1]-47;}
   else
     {int val=s2[i+1]-47;
      if(p[pos]!=val) {cout<<"-1"<<endl;return 0;}
	 }
  }
  cout<<L<<endl;
return 0; 
} 

Measured memory_bytes: 10880
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[1000001],a2,a4,a1;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%4==0)
		{
			a4++;
			continue;
		}
		if(a[i]%2==0)
		{
			a2++;
			continue;
		}
		else
		{
			a1++;
			continue;
		}
	}
	if(a2==0)
	{
		if(a4>=a1-1) printf("Yes");
		else printf("No");
		return 0;
	}
	else
	{
		if(a4>=a1) printf("Yes");
		else printf("No");
		return 0;
		
	}
}

Measured memory_bytes: 640
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(r);
    cout << r*r << nn;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

const long long INF=10000000000ll;

int main()
{
  int R,C,n;
  scanf("%d%d%d",&R,&C,&n);
  vector<vector<int> > e(R+C);
  vector<vector<long long> > v(R+C);
  for(int i=0;i<n;i++){
    int a,b;
    long long c;
    scanf("%d%d%lld",&a,&b,&c);
    a--;
    b--;
    e[a].push_back(R+b);
    v[a].push_back(c);
    e[R+b].push_back(a);
    v[R+b].push_back(c);
  }
  bool F=1;
  static bool vis[200000]={0};
  static long long X[200000]={0};
  for(int s=0;s<R+C&&F;s++){
    if(vis[s]){
      continue;
    }
    vis[s]=1;
    X[s]=0;
    queue<int> Q;
    Q.push(s);
    long long P1=INF,P2=INF;
    while(!Q.empty()&&F){
      int i=Q.front();
      //printf("%d %lld\n",i,X[i]);
      Q.pop();
      if(i<R){
	P1=min(P1,X[i]);
      }
      else{
	P2=min(P2,X[i]);
      }
      for(int x=0;x<e[i].size();x++){
	int j=e[i][x];
	long long c=v[i][x];
	if(!vis[j]){
	  vis[j]=1;
	  X[j]=c-X[i];
	  Q.push(j);
	}
	else if(X[i]+X[j]!=c){
	  F=0;
	  break;
	}
      }
    }
    //printf("%d %lld %lld\n",s,P1,P2);
    if(P1+P2<0){
      F=0;
    }
  }
  puts(F?"Yes":"No");
  return 0;
}


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

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  map<int, int> x, y;
  rep(i, n){
    int a; cin >> a;
    ++x[i + 1 + a];
    ++y[i + 1 - a];
  }

  ll ans = 0;
  for(auto p: x){
    ans += (ll)p.second * y[p.first];
  }

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


Measured memory_bytes: 29136
#include<bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b){
    if(a%b==0)return b;
    else
    return gcd(b, a%b);
    }
long long int lcm(long long int a, long long int b){
    return (a*b)/gcd(a, b);
    }
int main(){
   long long  int a,b;
    cin>>a>>b;
  long long  int x=lcm(a,b);

    cout<<x<<endl;

return 0;}


Measured memory_bytes: 256
#include<stdio.h>
int n;
int a[200000];
int ans[200000],b,c,i;


int main(void){

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

	b = 0;
	c = n-1;
	for(i=0;i<n;i++){
		if(i%2==0){
			ans[b] = a[n-1-i];
			b++;
		}else{
			ans[c] = a[n-1-i];
			c--;
		}
	}

	for(i=0;i<n;i++){
		printf("%d ",ans[i]);
	}
	printf("\n");
}


Measured memory_bytes: 3712