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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n, m;
  cin >> n >> m;
  P s[51], p[51];
  rep(i, 0, n) {
    cin >> s[i].first >> s[i].second;
  }
  rep(i, 0, m) {
    cin >> p[i].first >> p[i].second;
  }

  rep(i, 0, n) {
    int mn = 1145141919;
    int mi;
    int a = s[i].first, b = s[i].second;
    rep(j, 0, m) {
      int c = p[j].first, d = p[j].second;
      if(mn > abs(a - c) + abs(b - d)) {
        mn = abs(a - c) + abs(b - d);
        mi = j;
      }
    }
    cout << mi + 1 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 200000
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
int n, A[MAXN+5], X[MAXN+5]; ll S[MAXN+5], Ans;
int main()
{
	n = read(); for(rint i = 1; i <= n; A[i++] = read()); for(rint i = 1; i <= n; S[i] = S[i-1]+A[i], X[i] = X[i-1]^A[i], i++);
	for(rint i = 1, lef, rig, mid, j; i <= n; i++)
	{
		for(j = lef = i, rig = n; lef <= rig; mid = (lef+rig)>>1, S[mid]-S[i-1]==(X[mid]^X[i-1])?j=mid,lef=mid+1:rig=mid-1);
		Ans += j-i+1;
	}	cout << Ans << endl;
 
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll a={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};
  COUT(a[n-1]);
}

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

#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define FORR(i,a,b) for(int i=(b)-1; i>=(a); i--)

#define DEBUG(x) cerr << #x << ": " << (x) << endl;

using ll = long long;
using vi = vector<int>;
using pii = pair<int,int>;

const ll MOD = 998244353;

ll modpow(ll a, ll b){
	ll r = 1;
	while(b){
		if(b&1)r=r*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return r;
}
ll modinv(ll a){
	return modpow(a, MOD-2);
}
ll fact[425252];
ll ifact[425252];
ll comb(int a, int b){
	if(a<0 || b<0 || b>a)return 0ll;
	return fact[a]*ifact[b]%MOD*ifact[a-b]%MOD;
}

int n;
vi g1[252521];
vi g2[252521];

set<pii> g2s;

int main(){
	scanf("%d",&n);
	REP(i,n-1){
		int a,b;
		scanf("%d%d",&a,&b);--a;--b;
		g1[a].push_back(b);
		// g1[b].push_back(a);
	}
	REP(i,n-1){
		int a,b;
		scanf("%d%d",&a,&b);--a;--b;
		g2[a].push_back(b);
		g2[b].push_back(a);
		g2s.insert(pii(a,b));
		g2s.insert(pii(b,a));
	}
	if(n==1){
		puts("0");
		return 0;
	}
	// init
	fact[0] = 1;
	FOR(i,1,425252)fact[i] = i*fact[i-1]%MOD;
	ifact[425252-1] = modinv(fact[425252-1]);
	FORR(i,1,425252)ifact[i-1] = i*ifact[i]%MOD;
	// do
	ll ans = 0;
	REP(x,n+1){
		ll prob = comb(n,x) * modinv(modpow(2,n)) % MOD;
		ll add = prob * x % MOD * (n-x) % MOD;
		ans += add;
		ans %= MOD;
	}
	REP(x,n+1){
		ll prob = comb(n,x) * modinv(modpow(2,n)) % MOD;
		ll eprob = comb(n-2, x-2) * modinv(comb(n, x)) % MOD;
		ll trest = (n-1) * eprob % MOD;
		ll add = prob * (n-x) % MOD * trest % MOD;
		// DEBUG(add);
		ans += MOD - add * 2 % MOD;
		ans %= MOD;
	}
	ll inv16 = modinv(16);
	REP(u,n)for(int v : g1[u]){
		ll es = (n-1) - g2[u].size() - g2[v].size() + g2s.count(pii(u,v));
		ans += es * inv16 % MOD;
		ans %= MOD;
	}
	// REP(x,n+1){
	// 	double prob = comb(n, x) / pow(2.0, n);
	// 	double eprob = comb(n-2, x-2) / (double)comb(n, x);
	// 	double trest = (n-1) * eprob;
	// 	double eprob2 = comb(n-2, (n-x)-2) / (double)comb(n, n-x);
	// 	double trest2 = (n-1) * eprob;
	// 	double add = prob * trest * trest2;
	// 	DEBUG(add);
	// 	ans += add;
	// }
	printf("%lld\n",ans);
	return 0;
}



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

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	int n; cin >> n;
	vector<string> S(n);
	rep(i, n)cin >> S[i];

	vector<vector<int>> cnt(n, vector<int>(26, 0));

	rep(i, n) {
		for (auto x : S[i]) {
			cnt[i][x - 'a']++;
		}
	}

	vector<int> tot(26, 0);
	rep(i, 26) {
		tot[i] = cnt[0][i];
		rep(j, n)tot[i] = min(tot[i], cnt[j][i]);
	}

	string ans = "";
	rep(i, 26) {
		while (tot[i] > 0) {
			ans.push_back('a' + i);
			tot[i]--;
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

const int maxn = 1e5 + 5;

int n, x, a[maxn], ans;

inline int read(){
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)){if(ch == '-')f = -1; ch = getchar();}
	while(isdigit(ch)){u = u * 10 + ch - 48; ch = getchar();} return u * f; 
}

inline int gcd(int x, int y){return y == 0 ? x : gcd(y, x % y);}

int main(){
	n = read(); a[0] = read();
	for(register int i = 1; i <= n; i++)
		a[i] = read();
	x = abs(a[1] - a[0]);
	for(register int i = 2; i <= n; i++)
		x = gcd(x, abs(a[i] - a[i - 1]));
	cout << x;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

int main() {
  i64 x, y;
  cin >> x >> y;
  i64 sum = 0;
  if(x <= 3) {
    sum += 100000 * (4 - x);
  }
  if(y <= 3) {
    sum += 100000 * (4 - y);
  }
  if(x == y && x == 1) {
    sum += 400000;
  }
  cout << sum << endl;
}


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

int main() {
    int n;
    vector<int64_t> l(87);
    cin >> n;
    l.at(0) = 2;
    l.at(1) = 1;
    for(int i = 2; i <= n; i++){
        l.at(i) = l.at(i-1) + l.at(i-2);
    }
    cout << l.at(n) << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	public static void main (String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sA = br.readLine().split(" ", n);
		String[] sB = br.readLine().split(" ", n);
		String[] sC = br.readLine().split(" ", n);
		int[] arrA = new int[n];
		int[] arrB = new int[n];
		int[] arrC = new int[n];
		for (int i = 0; i < n; i++) {
			arrA[i] = Integer.parseInt(sA[i]);
			arrB[i] = Integer.parseInt(sB[i]);
			arrC[i] = Integer.parseInt(sC[i]);
		}
		Arrays.sort(arrA);
		Arrays.sort(arrB);
		Arrays.sort(arrC);
		long[] countsA = new long[n];
		int left = 0;
		for (int i = 0; i < n; i++) {
			while (left < n && arrA[left] < arrB[i]) {
				countsA[i] = left + 1;
				left++;
			}
			if (left == n && arrA[n - 1] < arrB[i]) {
				countsA[i] = n;
			}
			if (left > 0) {
				left--;
			}
		}
		long[] countsC = new long[n];
		int right = n - 1;
		for (int i = n - 1; i >= 0; i--) {
			while(right >= 0 && arrB[i] < arrC[right]) {
				countsC[i] = n - right;
				right--;
			}
			if (right < 0 && arrB[i] < arrC[0]) {
				countsC[i] = n;
			}
			if (right < n - 1) {
				right++;
			}
		}
		long total = 0;
		for (int i = 0; i < n; i++) {
			total += countsA[i] * countsC[i];
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 58436
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
int main(){
   //  #ifndef ONLINE_JUDGE
   //      freopen("input.txt","r",stdin);
   //      freopen("output.txt","w",stdout);
   // #endif
	// ios::sync_with_stdio(false);
	// cin.tie(0);
	ll k,x;
    cin>>k>>x;
    k*=500;
    if(k>=x)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

max_score = -10 ** 9 - 1
for i in range(n):
    tmp_score=-10**9 -1
    score = 0
    count = 0
    next_point = p[i] - 1
    while next_point != i and count < k:
        score += c[next_point]
        next_point = p[next_point] - 1
        count += 1
        if tmp_score < score:
            tmp_score = score
            max_count = count
    if count < k:
        score += c[next_point]
        count += 1
    if tmp_score < score:
        tmp_score = score
        max_count = count

    cycle_score = score
    if cycle_score > 0 and count < k:
        score = cycle_score * (k // count)
        tmp_k = k - ((k // count)*count)
        count=0
        next_point=p[i]-1
        under_k_score=-10**9-1
        score2=0
        while next_point != i and count < tmp_k:
            score2 += c[next_point]
            next_point = p[next_point] - 1
            count += 1
            if under_k_score < score2:
                under_k_score = score2
                max_count = count
        if under_k_score+cycle_score > tmp_score:
            score += under_k_score
        else:
            score += -cycle_score + tmp_score
        if max_score < score:
            max_score=score
    else:
        if max_score < tmp_score:
            max_score=tmp_score

print(max_score)


Measured memory_bytes: 68472
n = int(input())
u = list(map(int,input().split()))
l = list(map(int,input().split()))
u_sum = [0]*n
l_sum = [0]*n
s1=0
s2=0
max = 0
for i in range(n):
    s1+=u[i]
    s2+=l[n-i-1]
    u_sum[i]=s1
    l_sum[n-i-1]=s2
for i in range(n):
    sum = u_sum[i]+l_sum[i]
    if sum>max:
        max = sum
print(max)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    int N;
    cin >> N;
    vi A(N);
    in(N,A);
    bool f = true;
    rep(i,N){
        if(A[i]%2==0){
            if(A[i]%3 == 0 || A[i]%5==0) continue;
            else f = false;
        }
    }
    if(f) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
import bisect

N = int(input())
parts = [[] for i in range(3)]
con = [0] * N

ans = 0

for i in range(3):
  t = sorted(list(map(int,input().split())))
  parts[i] = t

under =parts[2]
middle = parts[1]
upper = parts[0]

for i in range(N):
  p = middle[i]
  ans += bisect.bisect_left(upper,p) * (N - bisect.bisect_right(under,p))
    
print(ans)

Measured memory_bytes: 23840
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N = 200000 + 5;
int info[N];
int n;
int main () {
	#ifdef wll
//	freopen ("testdata.in", "r", stdin);
	#endif
	int sum = 0;
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf ("%d", &info[i]);
		sum += info[i];
	}
	sort (info + 1, info + n + 1);
	if (info[2] >= 0) {
		printf ("%d\n", sum - 2 * info[1]);
		int tmp = info[1];
		for (int i = 2; i < n; ++i) {
			printf ("%d %d\n", tmp, info[i]);
			tmp -= info[i];
		}
		printf ("%d %d\n", info[n], tmp);
		return 0;
	}
	else if (info[n - 1] < 0) {
		printf ("%d\n", sum * (- 1) + 2 * info[n]);
		int tmp = info[n];
		for (int i = 1; i < n; ++i) {
			printf ("%d %d\n", tmp, info[i]);
			tmp -= info[i];
		}
		return 0;
	}
	else {
		int u;
		for (int i = 1; i < n; ++i) {
			if (info[i] < 0 && info[i + 1] >= 0) {
				u = i;
				break;
			}
		}
		int tsum = 0;
		for (int i = 1; i <= u; ++i) {
			tsum += info[i];
		}
		printf ("%d\n", sum - 2 * tsum);
		int tmpu = info[u];
		for (int i = u + 1; i < n; ++i) {
			printf ("%d %d\n", tmpu, info[i]);
			tmpu -= info[i];
		}
		int tmpn = info[n];
		for (int i = 1; i <= u - 1; ++i) {
			printf ("%d %d\n", tmpn, info[i]);
			tmpn -= info[i];
		}
		printf ("%d %d\n", tmpn, tmpu);
	}
	return 0;
}
















Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define lli long long int
using namespace std;

string convertToTitle(long long int n)
{
return n == 0 ? "" : convertToTitle(n / 26) + (char) (--n % 26 + 'a');
}
int main() 
{
	long long int n;
	cin >> n;
	cout << convertToTitle(n);
	return 0;
}
   








Measured memory_bytes: 3624
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const double PI = acos(-1);
const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}




int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll R,C,K;
    cin >> R >> C >> K;
    auto a = make_vec(R + 100, C + 100, 0);
    auto dp = make_vec(R + 100, C + 100, 4, 0LL);
    rep(i, K){
        ll r,c,v;
        cin >> r >> c >> v;
        a[r - 1][c - 1] = v;
    }
    rep(i, R) rep(j, C){
        for(int k = 2; k >= 0; k--){
            chmax(dp[i][j][k + 1], dp[i][j][k] + a[i][j]);
        }
        rep(k, 4){
            chmax(dp[i+1][j][0], dp[i][j][k]);
            chmax(dp[i][j+1][k], dp[i][j][k]);
        }
    }
    ll ans = 0;
    rep(k, 4) chmax(ans, dp[R-1][C-1][k]);
    print(ans);


}



Measured memory_bytes: 716880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n, k;
  cin >> n >> k;
  ll cnt = 0;
  ll t = 1;
  while (t <= n) {
    t *= k;
    cnt++;
  }
  cout << cnt << endl;
}


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

using namespace std;

int main()
{
    long long n, i, aux=0, l, r;
    cin >> n;
    for (i=0; i<n; i++)
    {
        cin >> l >> r;
        aux=aux+r-l+1;
    }
    cout << aux << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
using namespace std;

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

#define max_n 100

int N;

long long poww(int a,int n)
{
	if (n == 0)return 1;
	return (a*poww(a,n-1))%998244353;
}

int main() {
vector<int> D;

	cin >> N;

	rep(i, N) {
		int j;
		cin >> j;
		D.push_back(j);
	}

	D.push_back(100001);

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

	sort(D.begin(), D.end());

	long long ans = 1;
	int cu = 1;
	int c = 0;
	int pre = 1;

	for(int i=1;i<N+1;i++)
	{
		if(D.at(i) == cu)
		{
			c++;
		}	
		else if(D.at(i) == cu+1 || D.at(i) == 100001)
		{
			ans = ans * poww(pre, c);
			ans = ans % 998244353;
			pre = c;
			c = 0;
			cu++;
			if (D.at(i) == 100001)break;
			i--;
			continue;
		}
		else { ans = 0; break; }

	}

	cout << ans << endl;
	
	

	return 0;	
}

Measured memory_bytes: 2296
import sys
INF = 1 << 60
MOD = 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r):
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

def resolve():
    n, k = map(int, input().split())
    D = [tuple(map(int, input().split())) for _ in range(k)]
    tree = SegmentTree([0] * n, lambda x, y : (x + y) % MOD, 0)
    tree.update(0, 1)

    for i in range(1, n):
        for l, r in D: # [i - r, i - l]
            if i - l >= 0:
                tree.add(i, tree.sum(max(0, i - r), i - l + 1))

    print(tree[n - 1] % MOD)
resolve()

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  vector<int> amari(n+1);
  int ruiseki=0;
  amari[0]=0;
  for(int i=0;i<n;i++){
    ruiseki=(ruiseki+a[i])%m;
    amari[i+1]=ruiseki;
  }
  sort(amari.begin(),amari.end());
  LL ans=0;
  LL count=1,now=0;
  for(int i=1;i<n+1;i++){
    if(now==amari[i]){
      count++;
    }else{
      ans+=count*(count-1)/2;
      now=amari[i];
      count=1;
    }
  }
  ans+=count*(count-1)/2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int count = 0;
			int[] w = new int[10];
			do{
				w[count] = n % 2;
				n /= 2;
				count++;
			}while(n > 0);
			for(int i = 0;i < count;i++){
				if(w[i] == 1){
					if(i == count-1){
						System.out.println((int)Math.pow(2,i));
					}else{
						System.out.print((int)Math.pow(2,i) + " ");
					}
				}
			}
		}
	}
}

Measured memory_bytes: 12000
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
#define rep0(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(ll kk = l1; kk <= l2; kk++)
#define foritr(itr, A) for(set<ll>::iterator itr = A.begin(); itr != A.end(); itr++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define cr(x) cerr << #x << " = " << x << "\n";
#define crA(x, A) cerr << #x << " = " << A[x] << "\n";
#define spacing if(db)cout << " ";
#define mmst(x, v) memset((x), v, sizeof ((x)));
#define bg(ms) (*ms.begin())
#define ed(ms) (*prev(ms.end(), 1))
#define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c)))
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, a, b;
ll co[3];
int main()
{
	cin >> n >> a >> b;
	FOR(i,0,n)
	{
		ll x; cin >> x;
		if(x <= a) co[0] ++;
		else if(x > a && x <= b) co[1] ++;
		else co[2] ++;
	}
	cout << min({co[0], co[1], co[2]}) << '\n';
}


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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  while(cin>>n,n) {
    vector<int> v;
    REP(i,n) {
      int x;
      cin >> x;
      v.push_back(x);
    }
    sort(ALL(v));
    int f =0;
    int mae = -1;
    REP(i,v.size()) {
      int now = v[i];
      int cnt = 0;
      for(;i<v.size() && v[i]==now;i++)
        cnt++;
      i--;
      if (cnt > v.size()/2) {
        cout << v[i] << endl;
        f++;
        break;
      }
    }
    if (f==0) cout << "NO COLOR" <<endl;
  }
}

Measured memory_bytes: 4948
<?php
$S=trim(fgets(STDIN));
$P=trim(fgets(STDIN));

$Sl=strlen($S);
$Pl=strlen($P);
$p=$P[0];
$S.=$S;
$F='No';
for($i=0;$i<$Sl;$i++){
  if($S[$i]!=$p) continue;
  $f=1;
  for($j=1;$j<$Pl;$j++) if($S[$i+$j]!=$P[$j]){$f=0;break;}
  if($f){$F='Yes';break;}
}
echo $F;
?>

Measured memory_bytes: 15424
import Data.List
import Data.Maybe

main :: IO ()
main = do
  getLine
  [t, a] <- map read . words <$> getLine
  hs <- map read . words <$> getLine
  let mapped = map (\x -> abs $ t - x * 0.006 - a) hs
  print . (1+) . fromJust $ (minimum mapped) `elemIndex` mapped

Measured memory_bytes: 1404
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<int>edges[100009];
int n,k;
int ans=1;
int MOD=(int)1e9+7;
int visit[100009];
void dfs(int s,int level)
{   
    visit[s]=1;
    if(level==0){
        ans*=k;
    }
    int child=0;
    if(level==1)    child++;
    if(level>=2)    child++;
    for(auto x:edges[s])
    {
        if(!visit[x])
        {
            child++;
            dfs(x,level+1);
            ans*=(k-child);
            ans%=MOD;
        }
    }
}
main()
{
    cin>>n>>k;
    for(int i=1;i<=n-1;i++)
    {
        int u,v;
        cin>>u>>v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    dfs(1,0);
    cout<<ans<<"\n";
}



Measured memory_bytes: 9984
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    string S;cin >> S;
    if(S == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }
    char C;
    int index;
    vector<bool> kind(26,false);
    for(int i = 0;i<S.size();i++){
        C = S.at(i);
        index = C-97;
        kind.at(index) = true;
    }
    if(S.size() != 26){
        for(int i = 0;i<26;i++){
            if(!kind.at(i)){
                char plus = i+97;
                cout << S + plus << endl;
                return 0;
            }
        }
    }
    for(int i = S.size()-1;i>=0;i--){
        C = S.at(i);
        index = C-97;
        for(int j = 0;j<26;j++){
            if(!kind.at(j) && j > index){
                S.pop_back();
                char last = j+97;
                S += last;
                cout << S << endl;
                return 0;
            }
        }
        S.pop_back();
        kind.at(index) = false;
    }
}

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

using namespace std;

#define fst first
#define snd second

#define mp make_pair
#define pb push_back

typedef pair<int,int> ii;
typedef long long ll;

int pp[MAX];
bool cont[MAX];
vector<ii> graph[MAX];

void dfs(int x, int p) {
  cont[x] = true;
  pp[x] = p;
  for (auto i : graph[x])
    if (!cont[i.fst])
      dfs(i.fst, p + i.snd);
}

int main() {
  int n, m, l, r, d;
  set<int> S;
  scanf("%d %d", &n, &m);
  vector<pair<ii,int>> vec;
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d", &l, &r, &d);
    graph[l].pb(ii(r, d));
    graph[r].pb(ii(l, -d));
    S.insert(l);
    S.insert(r);
    vec.pb(pair<ii,int>(ii(l, r), d));
  }

  for (auto i : S)
    if (!cont[i])
      dfs(i, 0);

  for (auto i : vec)
    if (abs(pp[i.fst.fst] - pp[i.fst.snd]) != i.snd)
      return printf("No\n"), 0;

  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 18480
suits = %w(S H C D)
cards = (0...52).map do |i|
  suits[i / 13] + ' ' + (i % 13 + 1).to_s
end

n = gets.to_i
n.times do
  cards.delete(gets.chomp)
end

cards.each do |i|
  puts i
end

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


struct union_find{
    vector<ll> parent;
    union_find(ll n){
        parent.resize(n);
        rep(i, 0, n) parent[i] = i;
    }

    ll root(ll x){
        if(parent[x] == x) return x;
        parent[x] = root(parent[x]);
        return parent[x];
    }

    void unite(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx != ry) parent[rx] = ry;
    }

    bool same(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return true;
        return false;
    }
};

int main(){
    
    ll n, m, k;
    cin >> n >> m >> k;
    union_find tree(n);
    vector<ll> a(m), b(m), c(k), d(k);
    
    rep(i, 0, m){
        cin >> a[i] >> b[i];
        tree.unite(a[i]-1, b[i]-1);
    }
    
    vector<ll> vnum(n,0), fnum(n,0), bnum(n,0);
    rep(i, 0, n){
        vnum[tree.root(i)]++;
    }
    rep(i, 0, m){
        fnum[a[i]-1]++;
        fnum[b[i]-1]++;
    }
    rep(i, 0, k){
        cin >> c[i] >> d[i];
        if(tree.same(c[i]-1, d[i]-1)){
            bnum[c[i]-1]++;
            bnum[d[i]-1]++;
        }
    }


    rep(i, 0, n){
        cout << vnum[tree.root(i)] - 1 - fnum[i] - bnum[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 7936
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;

#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i,m,n) for(int i=m; i<=(int)(n); ++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)

int n;

string in[5];

bool nok(int sz){
  rep(i,5)
    rep(j,SZ(in[i]))
    if(sz+j<SZ(in[i]))
      if(in[i][j]=='X' && in[i][sz+j]=='X')
        return true;

  return false;
}

bool nokl[200];
int ans;
int len[10];
void dfs(int ne,int nlen){
  if(ne==10){
    if(nlen+n-1<ans){
      ans = nlen+n-1;
      //cout << ans << endl;
    }
    return;
  }
  
  //cout << ne << ' ' << nlen << endl;

  for(int i=nlen;i<=nlen+n-1;++i){
    //if(i+n>ans) break;
    bool tok = false;
    rep(j,ne) if(nokl[i-len[j]]) tok=true;
    if(tok) continue;
    len[ne] = i;
    dfs(ne+1,i+1);
  }
}

void solve(){
  memset(nokl,0,sizeof(nokl));
  rep(i,5) cin >> in[i];

  
  rep(i,SZ(in[0])){
    nokl[i+1] = nok(i+1);
    //if(nokl[i+1]) cout << i+1 << endl;
  }
  ans = 10*n;
  dfs(0,0);
  cout << ans << endl;
}

main(){
  while(cin >> n,n) solve();
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(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;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

    
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  ll n,k;
  cin >> n >> k;
  ll ans=0;
  exrep(i,k,n+1){
    ans=ans+(i*(n-i+1))%MOD+1;
    ans%=MOD;
  }
  cout << ans << endl;
}


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

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

    static class TaskA
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int n = in.nextInt();
            int[] a = new int[n + 1];
            int[] b = new int[n + 1];
            int[] c = new int[n];

            //Dishes
            for (int i = 1; i <= n; i++)
            {
                a[i] = in.nextInt();
            }
            //Satisfactions
            for (int i = 1; i <= n; i++)
            {
                b[i] = in.nextInt();
            }
            //C
            for (int i = 1; i < n; i++)
            {
                c[i] = in.nextInt();
            }

            //Eating
            int sat = 0;

            sat += b[a[1]];
            int lastEat = a[1];

            for (int i = 2; i <= n; i++)
            {
                sat += b[a[i]];
                if (lastEat + 1 == a[i])
                {
                    sat += c[a[i - 1]];
                }
                lastEat = a[i];
            }
            out.print(sat);
        }

    }
}



Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <complex>
#define rep(i,n) for(int i=0; i<(n); i++)
#define EPS 1e-10
using namespace std;

typedef complex<double> cd;

double s(cd a, cd b){
  return abs( a.real()*b.imag()-a.imag()*b.real() );
}

int main(){
  cd a[4];
  double x1, y1, x2, y2, x3, y3, xp, yp;

  while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp)!=EOF){
    a[0] = cd(x1,y1);
    a[1] = cd(x2,y2);
    a[2] = cd(x3,y3);
    a[3] = cd(xp,yp);
    if(abs(s(a[0]-a[3], a[1]-a[3])
           + s(a[1]-a[3], a[2]-a[3])
           + s(a[2]-a[3], a[0]-a[3])
           - s(a[1]-a[0], a[2]-a[0])) < EPS )
      printf("YES\n");
    else
      printf("NO\n");
  }
  
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep2(i, n) for(ll i = 2; i <=(ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        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 COM(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;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    ll n;
    cin >> n;
    ll a[n+1];
    ll maxa = -1;
    rep1(i, n){
        cin >> a[i];
        maxa = max(maxa, a[i]);
    }
    ll min_divisor[maxa+1]; //1より大きい最小の約数
    rep0(i, maxa) min_divisor[i] = 0;
    for(int i = 2; i <= maxa; i++){
        if(min_divisor[i] == 0){
            min_divisor[i] = i;
            for(ll j = 2*i; j <= maxa; j += i){
                min_divisor[j] = i;
            }
        }   
    }
    ll prime_cnt[maxa+1]; //a[]の素因数の数
    rep0(i, maxa) prime_cnt[i] = 0;
    rep1(i, n){
        set<ll> tmp;
        if(a[i] == 1) continue;
        ll dividend = a[i];
        ll divisor = min_divisor[a[i]];
        tmp.insert(divisor);
        while(divisor != dividend){
            dividend = dividend / divisor;
            divisor = min_divisor[dividend];
            tmp.insert(divisor);
        }
        for(auto x: tmp){
            prime_cnt[x]++;
            //cout << x << " ";
        }
        //cout << endl;
    }
    
    bool pairwise = true;
    bool setwise = true;
    rep2(i, maxa){
        if(prime_cnt[i] >= 2){
            pairwise = false;
            break;
        }
    }
    int gcd_all = gcd(a[1], a[2]);
    rep2(i, n-1) gcd_all = gcd(gcd_all, a[i+1]);
    if(gcd_all != 1)  setwise = false;

    if(pairwise){
        cout << "pairwise coprime" << endl;
    }else if(setwise){
        cout << "setwise coprime" << endl;
    }else{
        cout << "not coprime" << endl;
    }

    return 0;
}

Measured memory_bytes: 26536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Final Examination!
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line);
			if (n == 0) break;

			int max = 0;
			int min = 500;

			for (int i = 0; i < n; i++) {
				StringTokenizer st = new StringTokenizer(br.readLine());
				int sum = 0;
				while (st.hasMoreElements()) {
					sum += parseInt(st.nextToken());
				}
				max = Math.max(max, sum);
				min = Math.min(min, sum);
			}
			System.out.println(max + " " + min);
		} // end while
	} // end main
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

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

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

template <typename T>
inline T gcd(T a, T b) {
    for (; b; a %= b, swap(a, b));
    return a; 
}

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

int dfs(int cur, vvi& graph, vi& visit) {
    visit[cur] = 1;
    for (int nxt : graph[cur]) {
        if (visit[nxt]) continue;
        visit[cur] += dfs(nxt, graph, visit);
    }
    return visit[cur];
}

void dfs2(int cur, vvi& graph, vi& visit, vi& sub) {
    visit[cur] = 1;
    for (int nxt : graph[cur]) {
        if (visit[nxt]) continue;
        if (sub[nxt] > (graph.size()-1)/2) visit[cur] = -1;
        if (sub[nxt] >= (graph.size()-1)/2) dfs2(nxt, graph, visit, sub);
    }
}

ll mod = 1e9 + 7;
ll fastpow(ll a, ll b) {
    if (b == 0) return 1;
    ll sub = fastpow(a, b/2);
    ll rst = sub * sub % mod;
    if (b % 2) rst = rst * a % mod;
    return rst;
}

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

    ll N; cin >> N;
    cout << ((fastpow(10, N) - fastpow(9, N) - fastpow(9, N) + fastpow(8, N)) % mod + mod) % mod;
}

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


int main(){
  int N;
  cin >> N;
  map<string, long long int> S;
  for(int ii=0; ii<N; ii++){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    S[s]++;
  }

  long long int ans = 0;
  for(auto& s : S){
    ans += (s.second * (s.second-1)) / 2;
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
	long long n;
	long long c, k;
	cin >> n >> c >> k;
	vector<long long> t(n);
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}
	sort(t.begin(), t.end());
	int time = 0;
	for (int i = 0; i < n;) {
		long long p = min(i + c - 1, n - 1);
		if (t[p] - t[i] <= k) {
			i += p - i + 1;
		}
		else {
			int l = 0;
			for (int j = i; t[j] <= t[i] + k; j++) {
				l++;
			}
			i += l;
		}
		time++;
	}
	cout << time << endl;
}

Measured memory_bytes: 1024
#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 H, W, K;
  cin >> H >> W >> K;
  vector<string> C(H);
  rep(i, H) cin >> C[i];

  int ans = 0;
  for (int bitH = 0; bitH < (1<<H); bitH++) {
    for (int bitW = 0; bitW < (1<<W); bitW++) {
      vector<string> D(H);
      rep(i, H) D[i] = C[i];
      rep(h, H) if (bitH & (1<<h)) rep(i, W) D[h][i] = 'R';
      rep(w, W) if (bitW & (1<<w)) rep(i, H) D[i][w] = 'R';
      int n_black = 0;
      rep(i, H) rep(j, W) if (D[i][j] == '#') n_black++;
      if (n_black == K) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
//
// Created by Koki Igarashi on 7/28/20.
//

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int, Int> pii;
typedef pair<Int, double> pid;
typedef pair<double, double> pdd;
typedef pair<Int, pii> pip;
typedef pair<pii, Int> ppi;
typedef pair<double, Int> pdp;
typedef vector<Int> veci;
typedef vector<double> vecd;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<pii> vecpii;
typedef vector<ppi> vecppi;
typedef vector<veci> mati;
typedef vector<vecll> matll;
typedef vector<vecd> matd;
#define PB(x) push_back(x)
#define EB(x) emplace_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define REP(i, a, b) for(int i = (a);i <= (b);i++)
#define FORO(i, n) REP(i,0,(int)n-1)
#define FORI(i, n) REP(i,1,(int)n)
#define FORIT(i, t) for(auto i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a, _b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
#define DEBUG 1
#if DEBUG
#define DUMP(a) do { std::cout << #a " = " << (a) << ", "; } while(false)
#define DUMPLN(a) do { std::cout << #a " = " << (a) << std::endl; } while(false)
#else
#define DUMP(a)
#define DUMPLN(a)
#endif
template<typename T, typename U>
inline void getMin(T &a, U b) { if (a > b) a = b; }
template<typename T, typename U>
inline void getMax(T &a, U b) { if (a < b) a = b; }
template<typename T>
vector<T> getVector(const int n) { return vector<T>(n); }
template<typename T>
vector<T> getVector(const int n, const T a) { return vector<T>(n, a); }
template<typename T>
vector<T> getEmptyVector() { return vector<T>(); }
template<typename T>
void appendAll(vector<T> &a, vector<T> b) { a.insert(a.end(), b.begin(), b.end()); }
// #define X first
// #define Y second
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const ll MOD = 1000000007;
const int MAXN = 1 << 17;
const int inf = 1 << 20;
const int NIL = -inf;
int popcount(int x) { return __builtin_popcount(x); }

int N;
mati A;

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

    cin >> N;
    A.resize(N);
    FORO(i, N) {
        A[i].resize(N - 1);
        FORO(j, N - 1) {
            cin >> A[i][j];
        }
    }
    veci idx(N);
    int day = 0;
    int gcnt = 0;
    while(gcnt < N * (N - 1) / 2) {
        day++;
        veci used(N);
        bool no_game = true;
        for(int i = 0;i < N;i++) {
            if(used[i] || idx[i] == N - 1) continue;
            int opp = A[i][idx[i]] - 1;
            if(used[opp]) continue;
            if(A[opp][idx[opp]] == i + 1) {
                idx[opp]++;
                idx[i]++;
                used[i] = used[opp] = 1;
                gcnt++;
                no_game = false;
            }
        }
        if(no_game) break;
    }

    cout << (gcnt == N * (N - 1) / 2 ? day : -1) << endl;

    return 0;
}


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

char exchangeLowerUpper(char);

int main() {
    string oldstr, newstr;
    getline(cin, oldstr);
    // cin >> oldstr;
    
    for (long unsigned int i = 0; i < oldstr.size(); i++) {
        newstr.push_back(exchangeLowerUpper(oldstr[i]));
    }

    // cout << "oldsize = " << oldstr.size() << endl;
    // cout << "newsize = " << newstr.size() << endl;

    // return 0;

    cout << newstr << endl;

    return 0;
}

char exchangeLowerUpper(char oldc) {
    char newc = oldc;
    
    if ('a' <= oldc && oldc <= 'z') {
        newc = oldc + 'A' - 'a';
    } else if ('A' <= oldc && oldc  <= 'Z') {
        newc = oldc + 'a' - 'A';
    }
    
    return newc;
}


Measured memory_bytes: 3236