akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int W,H,N;
  cin >> W >> H >> N;
  int xl = 0;
  int xh = W;
  int yl = 0;
  int yh = H;

  for(int i=0;i<N;i++){
    int x,y,a;
    cin >> x >> y >> a;
    if(a == 1) xl = max(xl,x);
    if(a == 2) xh = min(xh,x);
    if(a == 3) yl = max(yl,y);
    if(a == 4) yh = min(yh,y);
  }

  int dx = max(xh - xl , 0);
  int dy = max(yh - yl , 0);

  cout << dx * dy << endl;
  return 0;
}

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

int main(){
  int lens = 0, lent = 0;
  char s[101], t[101], u;
  scanf("%s %s", s, t);
  
  while(s[lens]){
    if(lens >= 1){
      u = s[lens];
      for (int i = lens - 1; i >= 0; i--){
        if(u < s[i]){
          s[i + 1] = s[i];
          if(i == 0){
            s[i] = u;
          }
        } else {
          s[i + 1] = u;
          break;
        }
      }
    }
    lens++;
  }
  while(t[lent]){
    if(lent >= 1){
      u = t[lent];
      for (int i = lent - 1; i >= 0; i--){
        if(u > t[i]){
          t[i + 1] = t[i];
          if(i == 0){
            t[i] = u;
          }
        } else {
          t[i + 1] = u;
          break;
        }
      }
    }
    lent++;
  }
  if(strcmp(s, t) < 0){
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
import sys

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    cnt = set(range(1, M+1))
    for _ in range(N):
        K, *A = map(int, input().split())
        cnt.intersection_update(set(A))
    ans = len(cnt)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main()
{
	int N;
	cin>>N;
	int A,B,C;
	int ans=0;
	for (A=1;A<=N+1;A++){
		for (B=1;B<N/A+1;B++){
			C=N-A*B;
			if (C>=1 && C<=N){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3192
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
map<long long, long long> dp;
int main() {
#define int long long
	int n, k;
	cin >> n >> k;
	long long ans = 0;
	long long now = 0;
	dp[0] = 1;
	REP(i, n) {
		long long a;
		cin >> a;
		now += a;
		now %= k;
		ans += dp[now];
		dp[now]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

/*
 * 1  1  1  1
 * 1  1 -6  1
 * 1  1  1  1
 *
 */

int main(){
	int H, W, h, w;
	cin >> H >> W >> h >> w;

	int i = 0, j = 0;
	int a[700][700];
	while(i < 600){
		while(j < 600){
			//cout << i << ' ' << j << endl;
			rep(k,h){
				if(i + k >= 600) break;
				rep(l,w){
					if(j + l >= 600) break;
					if(k == h - 1 && l == w - 1) a[i + k][j + l] = -((h * w - 1) * 4000 + 1);
					else a[i + k][j + l] = 4000;
				}
			}
			j+=w;
		}
		j = 0;
		i+=h;
	}

	long long sum = 0;
	rep(i,H){
		rep(j,W){
			sum += a[i][j];
		}
	}

	if(sum < 0){
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
	rep(i,H){
		rep(j,W){
			if(j) cout << ' ';
			cout << a[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 3200
import java.math.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int num = 0;
        for(int i = 0; i < N; ++i) {
            String s;
            s = scan.next();
            if(new BigInteger(s).isProbablePrime(5)) ++num;
        }
        System.out.println(num);
    }
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
typedef long long ll;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 300 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int a;
    cin >> a;
    cout << a * a * 3 << endl;
}


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

static ll m = 1e9+7;

int main() {

    ll n, a, b;
    cin >> n >> a >> b;

    vl v(40);
    v[0] = 2;
    for (int i = 0; i < 32; ++i) {
        v[i+1] = v[i] * v[i] % m;
    }

    ll sum = 1;
    rep(i, 32) {
        if(n>>i&1) {
            // cout << (n>>i)<< endl;
            sum *= v[i];
            sum %= m;
            // cout << i << " " << sum << endl;
        }
    }

    if (sum == 0) sum += (m - 1);
    else sum--;

    vector<ll> modinv(2e5+9);
    modinv[1] = 1;
    for (int i = 2; i <= 2e5+3; i++) {
        modinv[i] = modinv[m%i] * (m-m/i) % m;
    }

    ll sum_a = 1;
    ll sum_b = 1;
    ll tmp = n;
    rep(i, a) {
        sum_a *= tmp;
        sum_a %= m;
        sum_a *= modinv[i+1];
        sum_a %= m;
        tmp--;
    }

    tmp = n;
    rep(i, b) {
        sum_b *= tmp;
        sum_b %= m;
        sum_b *= modinv[i+1];
        sum_b %= m;
        tmp--;
    }

    cout << (sum + 2 * m - sum_a - sum_b) % m << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");

  //   String nyu=sc.nextLine();
//int[] num=new int[6];
int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);
//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);


System.out.println(A*B /2) ;
	}
}

Measured memory_bytes: 22860
#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>;

const int MAX_V = 50;
const int MAX_S = MAX_V*50+5;
const ll INF = 1e18;

struct Edge {
  int to, a, b;
  Edge(int to, int a, int b):to(to),a(a),b(b) {}
};

struct Data {
  int v, s;
  ll x;
  Data(int v, int s, ll x):v(v),s(s),x(x) {}
  bool operator<(const Data& a) const {
    return x > a.x;
  }
};

vector<Edge> g[MAX_V];
ll dist[MAX_V][MAX_S+5];

int main() {
  int n, m, s;
  cin >> n >> m >> s;
  rep(i,m) {
    int u,v,a,b;
    cin >> u >> v >> a >> b;
    --u; --v;
    g[u].emplace_back(v,a,b);
    g[v].emplace_back(u,a,b);
  }
  rep(i,n)rep(j,MAX_S+5) dist[i][j] = INF;
  s = min(s, MAX_S);
  priority_queue<Data> q;
  auto push = [&](int v, int s, ll x) {
    if (s < 0) return;
    if (dist[v][s] <= x) return;
    dist[v][s] = x;
    q.emplace(v,s,x);
  };
  vector<int> c(n), d(n);
  rep(i,n) cin >> c[i] >> d[i];
  push(0,s,0);
  while (!q.empty()) {
    Data hoge = q.top(); q.pop();
    int v = hoge.v, s = hoge.s;
    ll x = hoge.x;
    if (dist[v][s] != x) continue;
    {
      int ns = min(s+c[v], MAX_S);
      push(v,ns,x+d[v]);
    }
    for (Edge e : g[v]) {
      push(e.to, s-e.a, x+e.b);
    }
  }
  for (int i = 1; i < n; ++i) {
    ll ans = INF;
    rep(j,MAX_S+5) {
      ans = min(ans, dist[i][j]);
    }
    cout << ans << endl;
  }
  return 0;
}

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

void solve(){	

	int n,m ;
	cin>>n>>m ;

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

	vector<priority_queue<int>> adj(n) ;

	rep(i,m){

		int a,b ;
		cin>>a>>b ;

		a-- ;
		b-- ;

		adj[a].push(h[b]) ;
		adj[b].push(h[a]) ;

	}

	int count=0; 

	rep(i,n){

		if(adj[i].empty()){
			count++ ;
		}
		else{

			int temp=adj[i].top() ;
			if(temp<h[i]){
				count++ ;
			}
		}

	}

	cout<<count ;

}

int main(){

	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

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


Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vector<pii> p;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        p.emplace_back(a, i + 1);
    }
    sort(p.begin(), p.end());
    for (auto &pp : p) {
        cout << pp.second << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1780
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
using namespace std;

int main() {
	int n, d;
	cin >> n >> d;
	if (n%(2*d+1)==0) {
		cout << int(n / (2 * d + 1));
	}
	else {
		cout << int(n / (2 * d + 1))+1;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n =  sc.nextInt();

        int[] heights = new int[n];

        for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }

        int maxLeft = 0;
        int count = 0;

        for (int i = 0; i < n; i++) {
            if (heights[i] >= maxLeft) {
                count++;
                maxLeft = heights[i];
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<n; i++)
using namespace std;
using ll = long long;
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;
}

int main() {  
    ll X;
    ll K;
    ll D;
    cin >> X >> K >> D;
    if(X<0)X *= -1;
    ll a = X/D;
    ll r = X%D;
    ll ans;
    if(K <= a){
        ans = X-K*D;
    }else{
        if((K-a) % 2 == 0){
            ans = X-a*D;
        }else{
            ans = D-r;
        }
    }
    
    cout << ans << endl;
}

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

#define fi first
#define se second

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

using namespace std;

int n, q;
long long a[N], b[N];

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n >> a[0];
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        b[n] = 1;
        for(int i = n - 1; i >= 1; i--){
                b[i] = b[i + 1];
                if(abs(b[i] - a[i + 1]) < b[i]){
                        b[i] += a[i + 1];
                }
        }
        for(int i = 1; i <= n; i++){
                a[i] = min(a[i - 1], abs(a[i - 1] - a[i]));
        }
        cin >> q;
        for(int i = 1; i <= q; i++){
                int x;
                cin >> x;
                cout << (a[x - 1] >= b[x] ? "YES" : "NO") << "\n";
        }
}


Measured memory_bytes: 9728
#include<iostream>
using namespace std;
int main(){
  int t,n,s,f,total=0;
  while(1){
    cin >> t;
    if(t==0){
      break;
    }
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> s >> f;
      total+=f-s;
    }
    if(t<=total){
      cout << "OK" << endl;
    }
    else{
      t-=total;
      cout << t << endl;
    }
    total=0;
  }
  return (0);
}

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

int main(){
  int n;
  cin >> n;
  string a;
  cin >> a;
  long long int r=0,g=0,b=0;
  for(int i=0; i<n; i++){
    if(a[i]=='R') r++;
    else if(a[i]=='G') g++;
    else b++;
  }
  long long int ans = r*g*b;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      int k = 2*j-i;
      if(k>=n) continue;
      if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]) ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
a, b, c = gets.split.map(&:to_i)
if b < a
	tmp = a
	a = b
	b = tmp
end
if c < a
	tmp = c
	c = b
	b = a
	a = tmp
elsif c < b
	tmp = c
	c = b
	b = tmp
end
printf("%d %d %d\n", a, b, c)



Measured memory_bytes: 6884
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int,vector<int>,greater<int>>
#define heap_max priority_queue<int>
#define precision(x) cout << setprecision(x) << fixed;
#define printv(v) for(auto p : v) cout << p << " ";
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout << a[i]; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;



int32_t main()
{
   fast;
   #ifndef ONLINE_JUDGE
   freopen("goodluckin.txt","r",stdin);
   freopen("goodluckout.txt","w",stdout);
   #endif
   int n;
   cin >> n;
   int ans = 0;
   for(int i = 1 ; i<=n ; i++){
    for(int j = 1 ; j <=n ; j++){
      if((i*1LL*j) < n){
        ans++;
      }
      else{
        break;
      }
    }
   }
       cout << ans;

}


Measured memory_bytes: 3648
import sys

s = sys.stdin.readline().rstrip()
q = int(sys.stdin.readline().rstrip())
query = [sys.stdin.readline().rstrip().split() for i in range(q)]
top = 1
s = list(s)
s_front = []
s_back = []
for i in range(q):
    que = query[i]
    if que[0] == '1':
        top *= -1
    else:
        if que[1] == '1':
            if top > 0:
                s_front.append(que[2])
                # s = ''.join([que[2], s])
                # s = que[2] + s
            else:
                s_back.append(que[2])
                # s = ''.join([s, que[2]])
                # s = s + que[2]
        else:
            if top > 0:
                s_back.append(que[2])
                # s = ''.join([s, que[2]])
                # s = s + que[2]
            else:
                s_front.append(que[2])
                # s = ''.join([que[2], s])
                # s = que[2] + s
s_front.reverse()
s_front.extend(s)
s_front.extend(s_back)
s = s_front
s = ''.join(s)
if top < 0:
    s = s[::-1]
print(s)


Measured memory_bytes: 111024
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N, K, C;
string S;
int dp[567890], ep[567890];

int main() {
	cin >> N >> K >> C;
	cin >> S;
	for (int i = 1; i <= N; ++i) {
		int how = dp[(i - C - 1 >= 0 ? (i - C - 1) : 0)] + 1;
		dp[i] = max(S[i - 1] == 'o' ? how : -1, dp[i - 1]);
	}
	for (int i = N - 1; i >= 0; --i) {
		int how = ep[(i + C + 1)] + 1;
		ep[i] = max(S[i] == 'o' ? how : -1, ep[i + 1]);
	}
	for (int i = 0; i < N; ++i) {
		if (dp[i] + ep[i + 1] < K) {
			cout << i + 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

lint gcd(lint a, lint b){
  if(a<b)swap(a,b);
  if(b==0)return a;
  if(a%b==0)return b;
  return gcd(a%b,b);
}

lint app() {
  int n;
  cin>>n;

  map<lint,map<lint,pair<int,int>>> m;
  rep(i,n){
    lint a,b;
    cin>>a>>b;
    if(a==0&&b==0){
      m[a][b].first++;
      continue;
    }
    if(a<0||(a==0&&b<0)){a=-a;b=-b;}
    if(b>0){
      lint g=gcd(a,b);
      a=a/g;b=b/g;
      m[a][b].first++;
    }else{
      b=-b;
      swap(a,b);
      lint g=gcd(a,b);
      a=a/g;b=b/g;
      m[a][b].second++;
    }
  }


  lint ans=1;
  for(auto ma:m){
    for(auto mb:ma.second){
      auto p=mb.second;
      if(ma.first==0&&mb.first==0){
        continue;
      }else{
        lint k2=0;
        lint k=1;
        rep(i,p.first){
          k*=2;k%=mod;
        }
        k2+=k;
        k=1;
        rep(i,p.second){
          k*=2;k%=mod;
        }
        k2+=k;
        k2--;  //duplicated 0,0

        k2%=mod;
        ans*=k2;
        ans%=mod;
      }
    }
  }
  ans+=m[0][0].first;

  ans--;
  ans+=mod;
  ans%=mod;
  return ans;
}


int main(){cout<<app()<<endl;return 0;}


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

#define llint long long

void openFile() {
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef Tr___
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
}

const int maxN = 1e5 + 5;
const int maxM = 1e6 + 5;
const llint INF = 1e9 + 7;

int N;
int a, b, c;

void enter() {
    cin >> a >> b >> c;
}

void solve() {
    cout << (a ^ b ^ c) << endl;
}

int main() {
    openFile();
    enter();
    solve();
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))

p = 0
cnt = 1

for i in range(N-1):
    if a[i] == a[i+1]:
        continue
    elif p == 0 and a[i] > a[i+1]:
        p = 1
    elif p == 0 and a[i] < a[i+1]:
        p = -1
    elif p == 1 and a[i] < a[i+1]:
        cnt += 1
        p = 0
    elif p == -1 and a[i] >a[i+1]:
        cnt += 1
        p = 0

print(cnt)


Measured memory_bytes: 14436
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int H = sc.nextInt();
   int W = sc.nextInt();
   int N = sc.nextInt();

   int ans =0;
   int wa =0;
   int t = 0;
   if(H>W) t = H;
   else t= W;
  
   if(N%t==0) ans = N/t;
   else ans = N/t +1;

   System.out.println(ans);
 }
}

Measured memory_bytes: 23124
s = input()

def set_char(data, c):
    for i in range(26):
        ret = chr(ord("a") + i)
        if ret not in data and ret > c:
            return ret

if len(s) < 26:
    data = set(s)
    for i in range(26):
        c = set_char(data, "")
    print(s + c)
else:
    i = len(s) - 1
    while i != 0 and s[i - 1] > s[i]:
        i -= 1
    if i == 0:
        print(-1)
    else:
        data = set(s[: i - 1])
        c = set_char(data, s[i - 1])
        print(s[: i - 1] + c)


Measured memory_bytes: 3064
/*
    Problem 100
    https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
/* constant */
/* global variables */
/* function */
/* main */
int main(){
    int n;
    cin >> n;
    int k = 0;
    while (n > 0) {
        k++;
        n -= k;
    }
    if (n < 0) {
        cout << "No" << '\n';
        return 0;
    }
    cout << "Yes" << '\n';
    cout << k + 1 << '\n';
    vector<vector<int> > s(k + 1, vector<int>(0));
    int cnt = 0;
    for (int i = 0; i <= k; i++) {
        for (int j = i + 1; j <= k; j++) {
            cnt++;
            s[i].push_back(cnt);
            s[j].push_back(cnt);
        }
    }
    for (int i = 0; i <= k; i++) {
        cout << k << ' ';
        for (int j = 0; j < k; j++) {
            cout << s[i][j] << (j < k - 1 ? ' ' : '\n');
        }
    }
}


Measured memory_bytes: 2304
import sys

def solve():
    file_input = sys.stdin
    H, W = map(int, file_input.readline().split())
    dp = [[0] * (W + 1)]
    for line in file_input:
        dp.append([0] + list(map(int, line.split())))
    max_width = 0
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if dp[i][j] == 1:
                dp[i][j] = 0
            else:
                dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
                max_width = max(max_width, dp[i][j])
    print(max_width ** 2)

solve()

Measured memory_bytes: 45860
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

char A[1000001];

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


	int N = getint();

	rep(i, N) A[getint()]++;

	if (A[1]) {
		if (A[1] == 1) co(1);
		else co(0);
		return 0;
	}
	if (A[2]) {
		int kotae = (A[2] == 1);
		for (int i = 3; i <= 500000; i += 2) {
			if (A[i]) {
				kotae += (A[i] == 1);
				for (int j = i + i; j <= 1000000; j += i) {
					A[j] = 0;
				}
			}
		}
		for (int i = 500001; i <= 1000000; i += 2) kotae += (A[i] == 1);
		co(kotae);
		return 0;
	}

	int kotae = 0;
	for (int i = 2; i <= 500000; i++) {
		if (A[i]) {
			kotae += (A[i] == 1);
			for (int j = i + i; j <= 1000000; j += i) {
				A[j] = 0;
			}
		}
	}
	for (int i = 500001; i <= 1000000; i++) kotae += (A[i] == 1);
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 4736
fn repeat(c: char, l: usize) -> String {
  (0..l).map(|_| c).collect()
}

fn main() {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let v: Vec<i32> = buf.trim().split(' ').map(|x| x.parse().unwrap()).collect();
  let x = (v[2] - v[0]) as usize;
  let y = (v[3] - v[1]) as usize;

  println!(
    "{}{}{}{}{}{}{}{}{}{}",
    'D',
    repeat('R', x + 1),
    repeat('U', y + 1),
    repeat('L', x + 1),
    repeat('D', y),
    repeat('R', x),
    repeat('U', y + 1),
    repeat('L', x + 1),
    repeat('D', y + 1),
    'R'
  )
}


Measured memory_bytes: 4352
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, P;
  cin >> N >> P;
  int64_t even = 0;
  int64_t odd = 0;
  for (int64_t i = 0; i < N; ++i) {
    int64_t a;
    cin >> a;
    if (a % 2 == 0) {
      ++even;
    } else {
      ++odd;
    }
  }
  int64_t result = 0;
  if (odd == 0) {
    result = (P == 0) ? (1LL << N) : 0;
  } else {
    result = 1LL << (N - 1);
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

void
solve() {
  ll a, b, c, k;
  cin>>a>>b>>c>>k;

  ll ans = 0;
  if (a > k) {
    ans += k;
    k -= k;
  }
  else {
    ans += a;
    k -= a;
  }

  if (b > k ) {
    ans += 0;
    k -= k;
  }
  else {
    ans += 0;
    k -= b;
  }

  if (c > k) {
    ans += -k;
    k -= k;
  }
  else {
    ans += -c;
    k -= c;
  }

  cout<<ans<<endl;
}

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

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3668
# define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

 int main(){
    int N = 0;
    char S[125];
    char X[256];
    char Y[256];
    int cnt[100];
    int loop = 0;
    int loop2 = 0;
    int loop3 = 0;
    int ans = 0;

    memset(S, 0x00, sizeof(S));
    memset(cnt, 0x00, sizeof(cnt));

    scanf("%d%s", &N, S);

    for (loop = 0; loop < N; loop++){
        memset(X, 0x00, sizeof(X));
        memset(Y, 0x00, sizeof(Y));
        strncpy(X, S, loop);
        strncpy(Y, S + loop, N - loop + 1);

        for (loop2 = 0; loop2 < 26; loop2++){
            if ((NULL != strchr(X, 'a' + loop2)) && (NULL != strchr(Y, 'a' + loop2))){
                cnt[loop]++;
            }
        }
    }

    ans = cnt[0];
    for (loop3 = 0; loop3 < 100; loop3++){
        if (cnt[loop3] > ans){
            ans = cnt[loop3];
        }
    }
    printf("%d", ans);

    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

#include <tuple>
#include <queue>
#include <algorithm>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main(void)
{
    int A, B; // water
    int C, D; // sugar

    int E; // max sugar / 100water
    int F; // size of beaker

    cin >> A >> B >> C >> D >> E >> F;

    double max_density = 0;
    int max_weight = 0;
    int max_sugar_total = 0;

    REP(A_i, F/(100*A) + 1)
    {
        REP(B_i, F/(100*B) + 1)
        {
            REP(C_i, F/C + 1)
            {
                REP(D_i, F/D + 1)
                {
                    int water_total = A_i * A + B_i * B;
                    int sugar_total = C_i * C + D_i * D;
                    int weight = water_total * 100 + sugar_total;

                    if( weight == 0 ) continue;
                    // check size of beaker
                    if( F < weight ) continue;
                    // check sugar is melted
                    if( E * water_total < sugar_total ) continue;

                    double density = (double)sugar_total/(double)weight;

                    if( max_density <= density )
                    {
                        max_density = density;
                        max_weight = weight;
                        max_sugar_total = sugar_total;
                    }
                }
            }
        }
    }

    cout << max_weight << " " << max_sugar_total << endl;

    return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
	t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])


Measured memory_bytes: 13040
f 'A' w = if w == '0' then 'X' else 'Y'
f 'X' w = if w == '0' then 'C' else 'Z'
f 'Y' w = if w == '0' then 'X' else 'C'
f 'Z' w = if w == '0' then 'W' else 'B'
f 'W' w = if w == '0' then 'B' else 'Y'
f 'B' w = if w == '0' then 'Y' else 'X'
f 'C' _ = 'C'

ans ("#":_) = []
ans (x:xs) =
  let d = foldl f 'A' x
      a = if d == 'B' then "Yes" else "No"
  in
    a:ans(xs)

main = do
  c <- getContents
  let i = lines c
      o = ans i
  mapM_ putStrLn o

Measured memory_bytes: 3860
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//
constexpr ll MOD = 1e9 + 7;
/*/
const ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll t(n), a(n);
  rep(i, n){
    cin >> t[i] >> a[i];
  }
  ll at = t[0], aa = a[0];
  repr(i, 1, n){
    ll k = max((at+t[i]-1)/t[i], (aa+a[i]-1)/a[i]);
    at = t[i]*k;
    aa = a[i]*k;
  }
  print(at+aa);
}


Measured memory_bytes: 256
H = input().split()
h = int(H[0])
w = int(H[1])
if h ==1 or w ==1:
    print(1)
else:
    if h % 2 == 0:
        print(int(h/2 * w))
    else:
        if w % 2 == 0:
            print(int(h * w/2))
        else:
            print(int((h +1)/2 * (w + 1)/2 + (h-1)/2 * (w-1)/2))

Measured memory_bytes: 3060
///
// File:  cgl_1_b.cpp
// Author: ymiyamoto
//
// Created on Sun Oct 22 19:02:33 2017
//

#include <cstdint>
#include <iomanip>
#include <iostream>

using namespace std;

struct vector_t {
  double x;
  double y;

  vector_t(double a, double b) : x(a), y(b)
  {
  }

  double norm2()
  {
    return x * x + y * y;
  }

  double cross(vector_t a)
  {
    return x * a.x + y * a.y;
  }

  vector_t operator*(double a)
  {
    return vector_t(a * x, a * y);
  }
};

struct point_t {
  double x;
  double y;

  point_t operator+(const point_t a)
  {
    return point_t({x + a.x, y + a.y});
  }

  void print()
  {
    cout << fixed << setprecision(10) << x << " " << y << endl;
  }

  point_t operator+(const vector_t vec)
  {
    return point_t({x + vec.x, y + vec.y});
  }

  vector_t operator-(const point_t p)
  {
    return vector_t({x - p.x, y - p.y});
  }

  point_t project(point_t p1, point_t p2)
  {
    vector_t vec1(x - p1.x, y - p1.y);
    vector_t vec2(p2.x - x, p2.y - y);
    return point_t({x, y}) + vec1 * (vec1.cross(vec2) / vec1.norm2());
  }

  point_t reflect(point_t p1, point_t p2)
  {
    point_t proj = project(p1, p2);
    return p2 + (proj - p2) * 2.0;
  }
};

int32_t main()
{
  double x, y;
  cin >> x >> y;
  point_t p = point_t({x, y});

  cin >> x >> y;
  point_t p1 = point_t({x, y});

  uint32_t q;
  cin >> q;
  for (uint32_t i = 0; i < q; i++) {
    double x, y;
    cin >> x >> y;
    point_t p2 = point_t({x, y});
    p.reflect(p1, p2).print();
  }
  return 0;
}

Measured memory_bytes: 3292
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

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

int N,K;
bool KK[101];

int main() {

	cin >> N;

	rep(i, 101)KK[i] = false;

	for(int i=1;i<10;i++)
	{
		for(int j=1;j<10;j++)
		{
			KK[i*j] = true;
		}
	}

	if(KK[N])
	{
	cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#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 INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a;cin >> a;
  string s;cin >> s;
  ll b = (s[0]-'0') * 100 + (s[2]-'0') * 10 + (s[3]-'0');
  cout << a * b  / 100 << endl;
}

Measured memory_bytes: 3572
from sys import stdin

def main():
	N = [int(x) for x in stdin.readline().strip().split()]
	a,b = N[0], N[1]
	if (a == b):
		print(0)
	elif (a < b):
		copy_a = (-1)*a
		if (copy_a == b):
			print(1)
		elif (a < 0) and (b == 0):
			newnum = a * (-1)
			print (newnum)
		elif (a == 0) and (b > 0):
			print (b)
		elif (a < 0) and (b < 0):
 			newnum = a - b
 			newnum = newnum * (-1)
 			print(newnum)
		elif (a < 0) and (b > 0):
			if (copy_a < b):
				newnum = b - copy_a + 1
				print(newnum)
			else:
				newnum = copy_a - b
				newnum += 1
				print(newnum)
		elif (a > 0) and (b > 0):
			newnum = b - a
			print(newnum)
	else:
		copy_a = (-1)*a
		if (copy_a == b):
			print(1)
		elif (a > 0) and (b == 0):
			print (a+1)
		elif (a == 0) and (b < 0):
			newnum = b * (-1)
			print (newnum+1)
		elif (a < 0) and (b < 0):
			newnum = b - a
			newnum = newnum * (-1)
			newnum += 2
			print(newnum)
		elif (a > 0) and (b < 0):
			if (copy_a < b):
				newnum = b - copy_a + 1
				print(newnum)
			else:
				newnum = b*(-1) - a + 1
				print(newnum)
		elif (a > 0) and (b > 0):
			newnum = (a - b)
			newnum += 2
			print(newnum)
main()


Measured memory_bytes: 3188
#include<stdio.h>
#define NIL -1

int D[10000],H[10000];

struct Node{
  int parent,left,right;
    };
  struct Node T[10000];
void print(int);
int dep;

int main(){
  int i,p,r,l,root=0,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d", &p, &l, &r);
    T[l].parent = p;
    T[r].parent = p;
    T[p].left = l;
    T[p].right = r;
   
  }
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}

  
int setDepth(int u){
  
    if(T[u].parent == NIL)return 0;
    if(T[u].parent!=NIL){
      dep++;
      setDepth(T[u].parent);
  }
    return dep;
}

int setHeight(int u){
  int h1 = 0,h2 = 0;
  if(T[u].left!=NIL){
    h1 = setHeight(T[u].left)+1;
  }
  if(T[u].right!=NIL){
    h2 = setHeight(T[u].right)+1;
  }
  if(h1 > h2) return h1;
  else return h2;
}

  
int Sibling(int u){
  if(T[u].parent == NIL) return NIL;
  else if(T[T[u].parent].left!=u && T[T[u].parent].left!=NIL){
    return T[T[u].parent].left;
  }
  else if(T[T[u].parent].right!=u && T[T[u].parent].right!=NIL) {
    return T[T[u].parent].right;
  }
  return NIL;
}

void print(int u){
  int deg = 0;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent); 
  printf("sibling = %d, ",Sibling(u));
  if(T[u].right!=NIL) deg++;
  if(T[u].left!=NIL) deg++;
  printf("degree = %d, ",deg);
  dep = 0;
  printf("depth = %d, ",setDepth(u));
  printf("height = %d, ",setHeight(u));
  if(T[u].parent == NIL) printf("root\n");
  else if(T[u].left==NIL && T[u].right==NIL) printf("leaf\n");
  else printf("internal node\n");
}

Measured memory_bytes: 620
n,m=map(int,input().split())
e=[]
for i in range(m):
    e.append(list(map(int,input().split())))
ans=0
for i in range(m):
    g=[[] for _ in range(n)]
    for j in range(m):
        if i==j:
            continue
        g[e[j][0]-1].append(e[j][1])
        g[e[j][1]-1].append(e[j][0])
    visited=[0]*n
    visited[0]=1
    q=[1]
    while len(q)>0:
        a=q.pop(0)
        visited[a-1]=1
        for k in g[a-1]:
            if visited[k-1]==0:
                q+=[k]
    if sum(visited)!=n:
        ans+=1
print(ans)
                    


Measured memory_bytes: 3064
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main(){
	int N, M, X, Y, Z,i;
	int x[200] = {};
	int y[200] = {};
	int flag = 0;
	int test = 0;
	int ans = 0;
	cin >> N >> M >> X >> Y;


	for (i = 0; i < N; ++i) {
		cin>>x[i];
	}

	for (i = 0; i < M; ++i) {
		cin>>y[i];
	}

	for (Z = X+1; Z <= Y; ++Z) {
		for (i = 0; i < N; ++i) {
			if (x[i] >= Z) {
				++flag;
			}
		}
		for (i = 0; i < M; ++i) {
			if (y[i] < Z) {
				++flag;
			}
		}
		if (flag == 0) {
			++ans;
		}
		flag = 0;
		//++test;
	}
	
	if (ans == 0) {
		cout << "War" << endl;
	}
	else {
		cout << "No War" << endl;
	}
	//cout << test << endl;
 }



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//


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

int main() {
  int n;
  cin >> n;
  vi a(n), c(1000005);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }

  bool ok = true;
  for (int i = 2; i < 1000005; i++) {
    int cnt = 0;
    for (int j = i; j < 1000005; j += i) cnt += c[j];
    if (cnt > 1) ok = false;
  }
  if (ok) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int x = a[0];
  rrep(i, n-1) x = gcd(x, a[i]);
  if (x == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;
}

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

int main(){
  
deque <char> S;
  string s;
int Q,T,F,j=0;
char C;
  cin >> s >> Q;
  rep(i,s.size())
  	S.push_back(s.at(i));
  
  char c=S.at(0);
  
  rep(i,Q){
    cin >> T;
    if(T==1)
      j++;
    else{
      cin >> F >> C;
      if((F==1 && j%2==0) || (F==2 && j%2==1)){
        S.push_front(C);
      }
      else if((F==1 && j%2==1) || (F==2 && j%2==0)){
        S.push_back(C);
      }
    }

  }
  
  if(j%2==1)
    reverse(S.begin(),S.end());

  rep(i,S.size())
   cout << S.at(i);
  
  cout << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

vec prime_list(int MAX_N){

    vector<bool> is_prime(MAX_N + 1, true);
    vec prime(0);
    is_prime[0] = false;
    is_prime[1] = false;

    FOR(i, 2, MAX_N + 1){
        if(is_prime[i]){
            prime.push_back(i);
            int tmp = i * 2;
            while(tmp <= MAX_N){
                is_prime[tmp] = false;
                tmp += i;
            }
        }
    }

    return prime;
}

void factmod3(int n, int &a, int &b, vec &prime){
    a = 1; b = 1;
    REP(i, prime.size()){
        int c = 0;
        while(n % prime[i] == 0){
            c++;
            n /= prime[i];
        }
        c %= 3;
        if(c > 0){
            REP(j, c) a *= prime[i];
            REP(j, 3 - c) b *= prime[i];
        }
    }
    //2155以上の素数を含む
    if(n > 1){
        a *= n;

        int r = (int)(sqrt(n) + 1e-3);
        if(r * r == n) b *= r;
        else if((double)b * (double)n * (double)n > INF) b = INF;
        else b *= (n * n);
    }
    //out << a << " " << b << endl;
}

signed main(){

    int N; cin >> N;
    vec s(N); readv(s);

    //2155^3=10007873875
    vec prime = prime_list(2154);
    //cout << prime.size() << endl;

    map<int, int> m, dual;
    int a, b;
    REP(i, N){
        factmod3(s[i], a, b, prime);
        m[a] += 1;
        dual[a] = b;
    }

    int ans = 0;
    for(auto p: m){
        if(p.first == 1) ans++;
        else if(!(dual[p.first] < p.first && m[dual[p.first]] > 0))
        ans += max(m[p.first], m[dual[p.first]]);
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 21632
import Data.List (foldl')

main :: IO ()
main = do
    n <- read <$> getLine
    answer $ solve n

type Answer = Int
answer :: Answer -> IO ()
answer = print

constMod = 10 ^ 9 + 7

solve :: Int -> Answer
solve = foldl' ((.) (`mod` constMod) . (*)) 1 . enumFromTo 1


Measured memory_bytes: 508
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
//#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define pb push_back


/* alias */


template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
//const int inf = 1000100010010010;
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alpha = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


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




/* main */




signed main(){


    cin.tie(0);
    ios::sync_with_stdio(false);

    int n = input();

	vi arr; rep(i,0,n) arr.push_back(input());

	int mx = *max_element(all(arr));
	int mxind = distance(arr.begin(), max_element(all(arr)));
	int mi = *min_element(all(arr));
	int miind = distance(arr.begin(), min_element(all(arr)));

	print(2 * n - 1);

	if(abs(mx) > abs(mi)){
		rep(i,0,n){
			arr[i] += mx;
			cout << mxind + 1 << " " << i + 1 << endl;
		}
	}else{
		rep(i,0,n){
			arr[i] += mi;
			cout << miind + 1 << " " << i + 1 << endl;
		}
	}



	if(arr[0] < 0){
		revrep(i,n - 2, -1){
			cout << i + 2 << " " << i + 1 << endl;
			arr[i] += arr[i + 1];
		}
	}else{
		rep(i,1,n){
			cout << i << " " << i + 1 << endl;
			arr[i] += arr[i - 1];
		}
	}



	








    



    





    


    

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main()
{
    int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<arr[k-1]<<endl;
}

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

int main() {
  int C[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> C[i][j];
    }
  }

  bool flag = false;
  for (int a1 = 0; a1 <= 100; a1++) {
    for (int b1 = 0; b1 <= 100 - a1; b1++) {
      if (a1 + b1 != C[0][0])
        continue;

      for (int a2 = 0; a2 <= 100; a2++) {
        if (a2 + b1 != C[1][0])
          continue;

        for (int b2 = 0; b2 <= 100 - a2; b2++) {
          if (a2 + b2 != C[1][1] || a1 + b2 != C[0][1])
            continue;

          for (int a3 = 0; a3 <= 100; a3++) {
            if (a3 + b1 != C[2][0] || a3 + b2 != C[2][1])
              continue;

            for (int b3 = 0; b3 <= 100 - a3; b3++) {
              if (a1 + b3 != C[0][2] || a2 + b3 != C[1][2] || a3 + b3 != C[2][2])
                continue;
              flag = true;

              if (flag)
                break;
            }
            if (flag)
              break;
          }
          if (flag)
            break;
        }

        if (flag)
          break;
      }
      if (flag)
        break;
    }
    if (flag)
      break;
  }

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256