akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N; cin >> N;
  vector<int> A(N);
  for (auto& a : A) { cin >> a; }
  map<int, int> memo{};
  for (const auto& a : A) {
    ++memo[a-1];
    ++memo[a];
    ++memo[a+1];
  }
  auto ans = boost::accumulate(memo, 0, [](int r, auto p){
    return std::max(r, p.second);
  });
  cout << ans << CRLF;
  
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 5120
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
struct Data{
    char c;
    int n;
};
int main(void){

    int n;
    cin>>n;
    string str;
    string c[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    while(n--){
        cin>>str;
        Data a[1200];
        char ch = 'A';
        int t = -1;
        for(int i = 0;i < str.size();i++){
            if(ch == str[i]){
                a[t].n++;
            }
            else{
                ch = str[i];
                t++;
                a[t].c = ch;
                a[t].n = 1;
            }
        }
        t++;
        for(int i = 0;i < t;i++){
            if(a[i].c == '0')continue;
            cout<<c[a[i].c - '0' - 1][(a[i].n - 1)%c[a[i].c - '0' - 1].size()];
        }
        cout<<endl;
    }


    return 0;
}

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

using namespace std;

int D[101010], P[101010];
int T[101010], K[16];
int n, k, ans, s;

int main()
{
	int i, j, t, a, b, c;
	
	scanf("%d", &n);
	
	for(i=1; i<n; i++){
		scanf("%d%d%d", &a, &b, &c);
		P[a] ^= c;
		P[b] ^= c;
	}
	
	for(i=0; i<n; i++){
		K[P[i]] ++;
	}
	
	for(i=0; i<15; i++){
		ans += K[i + 1] >> 1;
		k |= (1 << i) * (K[i + 1] & 1);
		s += (K[i + 1] & 1);
	}
	
	D[0] = 0;
	
	for(i=1; i<(1<<15); i++){
		for(j=t=0; j<15; j++){
			if(i & (1 << j)) t ^= (j + 1);
		}
		if(t == 0) T[i] = 1;
		
		D[i] = 0;
		
		for(j=i; j; j=j-1&i){
			if(T[j]) D[i] = max(D[i], D[i - j] + 1);
		}
	}
	
	printf("%d\n", ans + s - D[k]);
	
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
using namespace std;
bool a[1000];
int main(){
	int n,m;
	while(true){
	cin>>n>>m;
	if(n==0&&m==0)
		break;
	for(int i=0;i<n;i++)
		a[i]=true;
	int b=0,c=0,count=n;
	while(true){
		if(a[b]==true)
			c++;
		if(c==m){
			a[b]=false;
			c=0;
			count--;
		}
		if(count==0)
			break;
		b++;
		b%=n;
	}
	cout<<b+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int a[101];
int b[101];

int main()
{
 	int n, m, x;
  	cin >> n >> m >> x;
  	for (int i = 1; i <= m; ++i)
    {
      cin >> a[i];
      b[a[i]] = 1;
    }
    int y = x;
    int c = 0;
  	while (y > 0)
    {
     	y -= 1;
      	if (b[y] == 1)
          c++;
    }
  	int d = 0;
  	while (x < n+1)
    {
     	x += 1;
      	if (b[x] == 1)
          d++;
    }
    cout << min(c, d);
}

Measured memory_bytes: 256
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int X;
  cin >> X;
  if (X >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 3632
from collections import deque
N, M, K = map(int, input().split())
F = [[] for _ in range(N)]
B = [[] for _ in range(N)]

# フレンドの隣接リスト
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    F[a].append(b)
    F[b].append(a)

# ブロックの隣接リスト
for _ in range(K):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1
    B[c].append(d)
    B[d].append(c)


# 交友関係グループ（辞書型）
D = {}
# グループの親
parent = [-1] * N
# 訪問管理
visited = [False] * N

for root in range(N):
    cnt = 0
    if visited[root]:
        continue

    # D[root] = set([root])
    # 訪問先のスタック
    stack = [root]
    # 訪問先が無くなるまで
    while stack:
        # 訪問者をポップアップ
        n = stack.pop()
        # 訪問者を訪問済み
        if visited[n]:
            continue
        visited[n] = True
        cnt +=1
        # 訪問者のグループの親を設定
        parent[n] = root

        # root のフレンドをグループと訪問先に追加
        for to in F[n]:
            if visited[to]:
                continue
            # D[root].add(to)
            stack.append(to)
    if cnt!=0:
        D[root]=cnt
# print(D)
ans = [0]*N
for iam in range(N):
    # group = gro[parent[iam]]
    tmp_ans = D[parent[iam]]
    tmp_ans -=1
    tmp_ans -= len(F[iam])
    for block in B[iam]:
        if parent[block]==parent[iam] :
            tmp_ans -=1
    ans[iam]=tmp_ans
print(*ans, sep=' ')

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

int main(){
  int h,w,r,c;
  while(cin>>h>>w>>r>>c,h){
    r--,c--;
    vector<vector<int>> horz(h+1,vector<int>(w));
    vector<vector<int>> vert(h,vector<int>(w+1));
    for(int i=0;i<2*h+1;i++){
      if(i%2==0){
	//horz
	int index=i/2;
	for(int j=0;j<w;j++) cin>>horz[index][j];
      }
      else{
	int index=i/2;
	for(int j=0;j<w+1;j++) cin>>vert[index][j];
      }
    }

    if(h==1){
      bool res=false;
      res|=!(horz[0][0]==horz[1][0] && vert[0][0]==horz[0][0]);
      for(int j=1;j<w-1;j++){
	res|=(horz[0][j]!=horz[1][j]);
      }
      res|=!(horz[0][w-1]==horz[1][w-1] && horz[0][w-1]==vert[0][w]);
      if(res){
	cout<<"Yes"<<endl;
	continue;
      }
    }
    if(w==1){
      bool res=false;
      res|=!(vert[0][0]==vert[0][1] && horz[0][0]==vert[0][0]);
      for(int j=1;j<h-1;j++){
	res|=(vert[j][0]!=vert[j][1]);
      }
      res|=!(vert[h-1][0]==vert[h-1][1] && horz[h][0]==vert[h-1][0]);
      if(res){
	cout<<"Yes"<<endl;
	continue;
      }

    }
    queue<pair<int,int>> que;
    vector<vector<int>> ok_area(h,vector<int>(w,0));
    if(vert[0][0]!=horz[0][0]){
      que.push({0,0});
      ok_area[0][0]=true;
    }
    if(vert[0][w]!=horz[0][w-1]){
      que.push({0,w-1});
      ok_area[0][w-1]=true;
    }
    if(vert[h-1][0]!=horz[h][0]){
      que.push({h-1,0});
      ok_area[h-1][0]=true;
    }
    if(vert[h-1][w]!=horz[h][w-1]){
      que.push({h-1,w-1});
      ok_area[h-1][w-1]=true;
    }
    
    const int dh[]={1,-1,0,0};
    const int dw[]={0,0,1,-1};
    auto isrange=[h,w](int i,int j){return 0<=i && i<h && 0<=j && j<w;};
    
    while(!que.empty()){
      auto st=que.front();

      que.pop();
      for(int i=0;i<4;i++){
	int toh=st.first+dh[i];
	int tow=st.second+dw[i];
	if(!isrange(toh,tow) || ok_area[toh][tow]) continue;
	int cnt[2]={0,0};
	for(int j=0;j<4;j++){
	  int wall;
	  if(dh[j]!=0){
	    wall=horz[toh+(dh[j]+1)/2][tow];
	  }
	  else{
	    wall=vert[toh][tow+(dw[j]+1)/2];
	  }
	  if(!isrange(toh+dh[j],tow+dw[j]) || ok_area[toh+dh[j]][tow+dw[j]]){
	    cnt[wall]++;
	  }
	}
	if(cnt[0]&& cnt[1]){
	  ok_area[toh][tow]=true;
	  que.push({toh,tow});
	}
      }
    }
    bool res=false;
    res|=ok_area[r][c];
    for(int i=0;i<4;i++){
      int toh=r+dh[i];
      int tow=c+dw[i];
      if(isrange(toh,tow)){
	if(dh[i]!=0){
	  if(!horz[r+(dh[i]+1)/2][c]) res|=ok_area[toh][tow];
	}
	else{
	  if(!vert[r][c+(dw[i]+1)/2]) res|=ok_area[toh][tow];
	}
      }
      else{
	if(dh[i]!=0){
	  if(!horz[r+(dh[i]+1)/2][c]) res|=true;
	}
	else{
	  if(!vert[r][c+(dw[i]+1)/2]) res|=true;
	}
      }
    }
    cout<<(res ? "Yes" : "No")<<endl;

  }
  return 0;
}

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

int main() {
    int n;
    cin>>n;
    vector<P> v;
    rep(i,n) {
        int temp1,temp2;
        cin>>temp1>>temp2;
        v.push_back({temp2,temp1});
    }
    sort(v.begin(),v.end());
    ll sum=0;
    for (auto V:v) {
        sum+=V.second;
        if (V.first<sum) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}



Measured memory_bytes: 2420
#include<stdio.h>
#include<algorithm>

using namespace std;

int main(){
	int n,a,b,c;
	int m=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a[3];
		for(int j=0;j<3;j++)scanf("%d",&a[j]);
		std::sort(a,a+3);
		
		m=max(m,a[2]);
		
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2])puts("YES");
		else{
			if(m<100)puts("NO");
			else puts("YES");
		}
	}
}

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

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

	int x = 0,localmax = 0;
	for (int i = 0; i < N; i++) {
		if (S.at(i) == 'I') x++;
		else x--;
		localmax = max(localmax, x);
	}
	cout << localmax <<endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
const ll INF = 1e10;
const ld eps = 1e-9, pi = acos(-1.0);
typedef pair<ll, ll> P;

int main(){
  ll N, H;
  cin >> N >> H;
  vector<ll> v(N);
  ll at = 0;
  for(int i=0;i<N;i++){
    ll a;
    cin >> a >> v[i];
    at = max(at, a);
  }
  for(int i=0;i<N;i++)
    v[i] = -max(v[i], at);
  sort(v.begin(), v.end());
  for(int i=0;i<N;i++)
    v[i] = -v[i];
  for(int i=1;i<N;i++)
    v[i] += v[i-1];
  auto x = lower_bound(v.begin(), v.end(), H);
  if(x != v.end())
    cout << (x - v.begin()) + 1 << endl;
  else
    cout << (H-v.back() + at-1) / at + N << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>

int main() {
    int n;
    std::cin >> n;
    long long tak = 1, aok = 1;
    for (auto i = 0; i < n; i++) {
        long long t, a;
        std::cin >> t >> a;
        long long dt = tak / t,
             da = aok / a;
        if (tak % t) dt++;
        if (aok % a) da++;
        long long use = std::max(da, dt);
        tak = use * t;
        aok = use * a;
    }
    std::cout << (tak + aok) << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
  LL N;
  cin >> N;
  vector<LL> A(N);
  for(auto& i: A) cin >> i;

  auto a = max_element(begin(A), end(A)) - begin(A);
  if(A[a] <= 0) {
    cout << A[a] << endl;
    cout << N-1  << endl;
    for(auto i=N; a+1<i; --i) cout << i << endl;
    for(auto i=1; i<=a;  ++i) cout << 1 << endl;
    return 0;
  }

  LL b = 0, c = 0;
  for(auto i=0; i<N; ++i) {
    if(i&1) b += max(0ll, A[i]);
    else    c += max(0ll, A[i]);
  }
  cout << max(b, c) << endl;

  vector<LL> ans;
  LL i = 0;
  if(b > c) ans.emplace_back(i=1);
  for(;A[i] < 0; i += 2) {
    ans.emplace_back(1);
    ans.emplace_back(1);
  }
  for(;i+2 < N; i += 2) {
    if(A[i+2] < 0) {
      if(i+3 < N) ans.emplace_back(3);
      else        ans.emplace_back(3), ans.emplace_back(2);
    } else {
      ans.emplace_back(2);
    }
  }
  if(i+2 == N) ans.emplace_back(2);
  cout << ans.size() << endl;
  for(auto i: ans) cout << i << endl;
}


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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		long n = sc.nextLong();
		long x = (long)Math.sqrt(n);
		long c = 0l, p = 0l;
		for(long i = x; i > 0; i--) {
			if(n%i == 0) {
				c = i;
				p = n/i;
				break;
			}
		}
		System.out.println(c + p - 2);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, k; cin >> n >> k;
	string s; cin >> s;
	k--;
	if(s.at(k) == 'A') s.at(k) = 'a';
	else if(s.at(k) == 'B') s.at(k) = 'b';
	else s.at(k) = 'c';
	cout << s << endl;
} 

Measured memory_bytes: 256
#C-Streamline
n,m=map(int,input().split())
x=list(map(int,input().split()))
x=sorted(x)
s=[]
for i in range(m-1):
    s.append(x[i+1]-x[i])
s=sorted(s)
k=0
for i in range(m-n):
    k+=s[i]
print(k)

Measured memory_bytes: 58280
#include <cstdio>
#define MOD 1000000007
using namespace std;
long long pow(long long x, long long n) {
	if (n == 0) return 1;
	if (n % 2 == 0) return pow(x * x % MOD, n / 2);
	return pow(x * x % MOD, n / 2) * x % MOD;
}
int main()
{
	long long x, n;
	scanf("%lld%lld", &x, &n);
	printf("%lld\n", pow(x, n));
	return 0;
}


Measured memory_bytes: 2748
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T>inline int bs(int g,int k,T c){while(abs(k-g)>1){int m=(g+k)/2;(c(m)?k:g)=m;}return k;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    int n;
    cin >> n;
    vector<ll> a(n);
    cin >> a;

    map<ll,ll> X, Y;
    for(int i = 0; i < n; ++i){
        X[i+a[i]]++;
        Y[i-a[i]]++;
    }

    ll ans = 0;
    for(auto x : X){
        ans += x.second * Y[x.first]; 
    }
    cout << ans << '\n';
    
    
    
    return 0;
}


Measured memory_bytes: 39040
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
ll x,k,d,mn,ed,ano;
int main(){
	cin>>x>>k>>d;
	mn=abs(x)/d;
	if(mn>k)
	{
		if(x>0)
		{
			cout<<x-k*d<<endl;
		}
		else
		{
			cout<<abs(x+k*d)<<endl;
		}
		return 0;
	}
	if(x>0)
	{
		ed=x-mn*d;
		ano=ed-d;
	}
	else
	{
		ed=x+mn*d;
		ano=ed+d;
	}
	if(k%2==mn%2)
	{
		cout<<abs(ed)<<endl;
	}
	else
	{
		cout<<abs(ano)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
function main(input) {
  var n = input[0]-0;
  var h = input[1].split(" ").map(v=>v-0);
  var ans = 0;
  var start, end;
  for(start=0;start<n;){
    if(h[start]==0) {start++; continue;}
    var min = h[start];
    for(end=start;end<n;end++){
      if(h[end] == 0) break;
      min = Math.min(h[end], min);
    }
    for(var i=start;i<end;i++){
      h[i]-=min;
    }
    ans += min;
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 11468
#include <iostream>
#include <algorithm>
using namespace std;
 
int P, Q, R;
const char *p;
 
int formula() {
   
  p++;
 
  switch( *p ) {
  case '-': return 2 - formula();
  case 'P': return P;
  case 'Q': return Q;
  case 'R': return R;
  case '0': return 0;
  case '1': return 1;
  case '2': return 2;
     
  case '(':
    int form1 = formula();
    int form2;
    p++;
    switch( *p ) {
    case '*':
      form2 = formula();
      p ++;
      return min( form1, form2 );
    case '+':
      form2 = formula();
      p++;
      return max( form1, form2 );
    }
  }
   
  return 0;
}
 
int main() {
  string str;
   
  while(getline(cin, str)) {
    int cnt = 0;
    if( str == "." ) break;
    for(int i=0; i<3; i++) {
      for(int j=0; j<3; j++) {
        for(int k=0; k<3; k++) {
          P = i, Q = j, R = k;
          p = str.c_str()-1;
          if( formula() == 2 ) cnt ++;
        }
      }
    }
     
    cout << cnt << endl;
  }
   
  return 0;
}

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


int main()
{
	int n;
	cin>>n;
	if(n<10 && n>0)
		cout<<n;
	else
		if(n<100 && n>9)
			cout<<9;
		else
			if(n>99 && n<1000)
				cout<<9+(n-99);
			else
				if(n>999 && n<10000)
					cout<<9+900;
				else
					if(n>9999 && n<100000)
						cout<<909+(n-9999);
					else
						cout<<90909;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc087/tasks/arc090_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int N, sum, m, t, a[100], b[100];

  cin >> N;
  sum = 0;
  REP(i, N)
  {
    cin >> t;
    sum += t;
    a[i] = sum;
  }
  sum = 0;
  REP(i, N)
  {
    cin >> t;
    sum += t;
    b[i] = sum;
  }

  m = a[0] + sum;
  FOR(i, 1, N)
  {
    m = max(m, a[i] + sum - b[i - 1]);
  }

  cout << m << '\n';

  return 0;
}


Measured memory_bytes: 256
m = [[[0]*10 for _ in range(3)]for _ in range(4)]
n = int(input())

for i in range(n):
	b, f, r, v = map(int, input().split())
	m[b-1][f-1][r-1] += v

for i in range(4):
	for j in range(3):
		for k in range(10):
			print(' {}'.format(m[i][j][k]), end='')
		print()
	if i != 3:
		for _ in range(20):print('#', end='')
		print()


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

// #include<cstdio>

int main(){
  int card[4][13]={};
  int n, x;
  char s;

  cin >> n;
  for (int i=0; i<n; i++){
    cin >> s >> x;
    if (s=='S') card[0][x-1]=1;
    if (s=='H') card[1][x-1]=1;
    if (s=='C') card[2][x-1]=1;
    if (s=='D') card[3][x-1]=1;
  }

  for (int i=0; i<4; i++){
    for (int j=0; j<13; j++){
      if (card[i][j]==0){
	switch(i){
	case 0:cout << "S " << j+1 << "\n";
	  break;
	case 1:cout << "H " << j+1 << "\n";
	  break;
	case 2:cout << "C " << j+1 << "\n";
	  break;
	case 3:cout << "D " << j+1 << "\n";
	  break;
	}
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){

  int in;
  vector<int> V;

  while(cin >> in){
    V.push_back(in);
  }

  sort(V.begin(), V.end());
  reverse(V.begin(), V.end());

  for(int i = 0; i < 3; i++){
    cout << V[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
  return (int)(*(size_t*)a - *(size_t*)b);
}


int main()
{
  long long *a[3];
  long long *b[2];
  int i, j, n;
  long long ans=0ll;
  
  scanf(" %d", &n);
  for(i=0; i<3; i++){
    a[i] = (long long *)malloc(sizeof(long long) * n);
    if(i<2)
      b[i] = (long long *)malloc(sizeof(long long) * n);
  }

  for(i=0; i<3; i++){
    for(j=0; j<n; j++){
      scanf(" %d", a[i]+j);
    }
    qsort(a[i], n, sizeof(long long), compare_int);
  }
  int k;
  i=j=0;
  for(k=0; k<n; k++){
    while(i<n && a[0][i] < a[1][k]) i++;
    while(j<n && a[1][k] >= a[2][j]) j++;
    b[0][k] = i;
    b[1][k] = n-j;
  }
  for(i=0; i<n; i++){
    ans += b[0][i] * b[1][i];
  }

  printf("%lld\n", ans);

  for(i=0; i<3; i++){
    free(a[i]);
    if(i<2)
      free(b[i]);
  }
  
  return 0;
}

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

int a, b, k;

int main(){
	cin >> k >> a >> b;
	for(int i = 1; i <= 1000; i++){
		int pos = k * i;
		if(a <= pos && pos <= b){
			cout << "OK" << endl;
			return 0;
		} 
	}
	cout << "NG" << endl;
	return 0;
} 

Measured memory_bytes: 3632
S = input()

if S == "SUN":
    print(7)

if S == "MON":
    print(6)

if S == "TUE":
    print(5)

if S == "WED":
    print(4)

if S == "THU":
    print(3)

if S == "FRI":
    print(2)

if S == "SAT":
    print(1)


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

 int main() {
   int N, X, Y, Hans;
   cin >> N;
   vector<pair<int, pair<int, int>>> hxy(N);

   rep(i, 0, N) cin >> hxy.at(i).second.first >> hxy.at(i).second.second >> hxy.at(i).first;
   sort(hxy.begin(), hxy.end(), greater<pair<int, pair<int, int>>>());

   bool done = false;
   rep(x, 0, 101) {
     rep(y, 0, 101) {
       int H;
       H = hxy.at(0).first + abs(x - hxy.at(0).second.first) + abs(y - hxy.at(0).second.second);
       bool ok = true;
       rep(i, 1, N) {
         if (hxy.at(i).first != max(0, H - abs(x - hxy.at(i).second.first) - abs(y - hxy.at(i).second.second))) {
           ok = false;
           break;
         }
       }
       if (ok) {
         X = x;
         Y = y;
         Hans = H;
         done = true;
         break;
       }
     }
     if (done) break;
   }

   cout << X << " " << Y << " " << Hans << endl;
 }


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int h, a;
    cin >> h >> a;
    cout << (h / a) + (h % a > 0);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int ru2(int a){
		int i,r=1;
		for(i=0;i<a;i++)r=r*2;
		return r;
}

int main(){
		char s[11];
		scanf("%s",s);
		int i,gen=0,j;
		long long ans=0;
		while(s[gen]!=0)gen++;
		for(i=0;i<ru2(gen);i++){
				int a[10]={0},tmp=0;
				while(tmp<gen){
		//				printf("%d",i&(1<<tmp));
						if(i&(1<<tmp)){
				//		printf("%d\n",i&(1<<tmp));
								a[tmp]=1;
						}
						tmp++;
				}
		//		puts("");
		//		for(j=0;j<gen;j++)printf("%d",a[j]);
		//		puts("A");
				long long t=0;
				for(j=0;j<gen;j++){
						t=t*10+s[j]-'0';
						if(a[j]==1){
								ans+=t;
								t=0;
						}
				}
				ans+=t;
		}
		printf("%lld\n",ans/2);
		return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
  int x;
  cin >> x;
  if(x == 1) cout << 0 << endl;
  else cout << 1 << endl;
  

}


Measured memory_bytes: 3632
#include <iostream>
    #include <cmath>

    bool isPrime(int readVal){
        bool flg = true;
        int i = 2, lim = std::sqrt(readVal);
        while(flg && i <= lim){
            flg = 0 != readVal % i;
            ++i;
        }

        return flg;
    }

    int main(){
        int n;
        std::cin >> n;

        int count = 0;
        for(int i = 0; i < n; ++i){
            int val;
            std::cin >> val;
            if(isPrime(val)){
                ++count;
            }
        }

        std::cout << count << std::endl;

        return 0;
    }


Measured memory_bytes: 3092
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    int sum = 0;
    for (int i = 0; i < n; ++i){
        cin >> v[i];
        sum += v[i];
    }
    int ms = sum;
    int suf = 0;
    for (int i = 0; i < n; ++i) {
        suf += v[i];
        ms = min(ms, abs(suf - abs(sum-suf)));
    }
    cout << ms << '\n';

    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  long N, M;
  cin >> N >> M;

  long p[M];
  bool s[M];

  for (long i = 0; i < M; i++) {
    cin >> p[i];
    string tempS;
    cin >> tempS;
    s[i] = tempS.compare("AC") == 0 ? true : false;
  }

  long correctAns = 0;
  long totalPenalty = 0;

  long state[N + 1];
  long penalty[N + 1];
  for (long i = 0; i < N + 1; i++) {
    state[i] = 0;
    penalty[i] = 0;
  }

  for (long i = 0; i < M; i++) {
    long P = p[i];
    bool S = s[i];

    if (state[P] == 0) {
      if (!S) {
        penalty[P] += 1;
      } else {
        correctAns += 1;
        totalPenalty += penalty[P];
        state[P] = 1;
      }
    }
  }

  cout << correctAns << " " << totalPenalty << endl;
  return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
int main(){
  int r;cin>>r;
  if(r<1200){
    cout<<"ABC"<<endl;
  }
  else if(1200<=r&&r<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }
  return 0;
}


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

int M, T, P, R;
int m, t, p, j;

int main() {
  while (scanf("%d%d%d%d", &M, &T, &P, &R) != EOF && M) {
    int ac[50][10];
    int wa[50][10];
    bool accepted[50][10];
    fill(&wa[0][0], &wa[0][0]+50*10, 0);	
    fill(&accepted[0][0], &accepted[0][0]+50*10, false);
    for (int i=0; i<R; i++) {
      scanf("%d%d%d%d", &m, &t, &p, &j);
      t--; p--;
      if (j == 0) {
	accepted[t][p] = true;
	ac[t][p] = m;
      } else {
	wa[t][p]++;
      }
    }
    tuple<int,int,int> ans[50];
    for (int i=0; i<T; i++) {
      int count = 0;
      int time = 0;
      for (int j=0; j<P; j++) {
	if (accepted[i][j]) {
	  count++;
	  time += wa[i][j] * 20 + ac[i][j];
	}
      }
      ans[i] = make_tuple(count, -time, i);
    }
    sort(ans, ans+T);
    reverse(ans, ans+T);
    for (int i=0; i<T; i++) {
      if (i != 0) {
	if (get<0>(ans[i-1]) == get<0>(ans[i]) 
	    && get<1>(ans[i-1]) == get<1>(ans[i])) {
	  printf("=");
	} else {
	  printf(",");
	}
      }
      printf("%d", get<2>(ans[i])+1);
    }
    printf("\n");
  }
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
  
namespace std{
  bool operator < (const P &a,const P &b){
    return (a.real()<b.real()||(a.real()==b.real() && a.imag()<b.imag()));
  }
}
  
double eps=1e-10;
  
double Sqrt(double x){
  return sqrt(max(0.0,x));
}
  
struct S{
  P p,q;
  S(P p,P q):p(p),q(q){}
};
  
struct C{
  P p;
  double r;
  C(P p,double r):p(p),r(r){}
  C(double x,double y,double r):p(P(x,y)),r(r){}
};
  
S getInTangent(C a,C b,double flg=1.0){
  P base=b.p-a.p;
  double w=a.r+b.r;
  double h=Sqrt(norm(base)-w*w);
  P k=base*P(w,h*flg)/norm(base);
  return S(a.p+k*a.r,b.p-k*b.r);
}
  
S getOutTangent(C a,C b,double flg=1.0){
  P base=b.p-a.p;
  double h=b.r-a.r;
  double w=Sqrt(norm(base)-h*h);
  P k=base*P(w,h*flg)/norm(base)*P(0,flg);
  return S(a.p+k*a.r,b.p+k*b.r);
}
  
vector<S> getTangent(C a,C b){
  vector<S> res;
  double dist=abs(a.p-b.p);
    
  if(dist>a.r+b.r+eps)
    res.push_back(getInTangent(a,b,1));
  
  if(dist>a.r+b.r-eps)
    res.push_back(getInTangent(a,b,-1));
  
  if(dist>abs(a.r-b.r)+eps)
    res.push_back(getOutTangent(a,b,1));
  
  if(dist>abs(a.r-b.r)-eps)
    res.push_back(getOutTangent(a,b,-1));
  
  return res;
}
  
  
  
void pr(P p){
  printf("%.10f %.10f\n",p.real(),p.imag());
}
  
int main(){
  double ax,ay,ar,bx,by,br;
  cin>>ax>>ay>>ar>>bx>>by>>br;
  vector<S> ans=getTangent(C(ax,ay,ar),C(bx,by,br));
  vector<P> vec;
  for(int i=0;i<(int)ans.size();i++)vec.push_back(ans[i].p);
  sort(vec.begin(),vec.end());
  for(int i=0;i<(int)vec.size();i++)pr(vec[i]);
  return 0;
}

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

typedef long long ll;


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

    int 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};

    int K;

    cin >> K;

    cout << a[K - 1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100;
int n,a[N],b[N],ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n;i++)
		if(a[i]-b[i]>0)
			ans+=a[i]-b[i];
	cout<<ans<<endl;
	return 0;
}

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

#define STRING(str) #str
#define ll long long

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}


int main() {
	ll N, X, M;
	cin >> N >> X >> M;

	set<ll> st;
	ll tmp = X;
	ll cycle = 0LL;
	int cycle_len = 0;
	vector<ll> cycle_val;
	bool last_zero = false;
	int double_ind = -1;
	// while (!st.count(tmp)) {
	while (true) {

		if (st.count(tmp)) {
			for (int i=0;i<cycle_val.size();i++) {
				double_ind = i;
				if (tmp == cycle_val[i]) break;
			}
			break;
		}

		st.insert(tmp);
		if (tmp == 0) last_zero = true;
		cycle_val.push_back(tmp);
		cycle_len++;
		cycle += tmp;
		tmp = tmp*tmp%M;
		if (cycle_len == N) break;
	}

	if (last_zero) {
		cout << cycle << endl;
	} else {
		ll ans = 0LL;
		// ans += cycle*(N/cycle_len);
		// for (int i=0;i<(N%cycle_len);i++) {
		// 	ans += cycle_val[i];
		// }

		ll true_cycle = cycle;
		ll true_cycle_len = cycle_len-double_ind;
		for (int i=0;i<double_ind;i++) {
			ans += cycle_val[i];
			true_cycle -= cycle_val[i];
		}
		ans += true_cycle*((N-double_ind)/true_cycle_len);
		for (int i=0;i<(N-double_ind)%true_cycle_len;i++) {
			ans += cycle_val[i+double_ind];
		}

		cout << ans << endl;
	}
}

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;
  int MAX = -1;
  int num = MAX;
  int ans = 0;
  for(int i = 1; i <= n; i++) {
    int x = i;
    int cnt = 0;
    while(x) {
      if(x % 2 == 0) {
        cnt++;
        x /= 2;
      }
      else x = 0;
    }
    num = max(cnt, num);
    if(num == cnt) ans = i;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdint>
#include <type_traits>
#include <vector>


template<uint32_t mod> class Residue_Field {
public:
    uint32_t num = 0;
    Residue_Field() { }
    Residue_Field(const Residue_Field &x) : num(x.num) { }
    template<class T> Residue_Field(T x) {
        using Int = typename std::conditional<sizeof(T) >= 4, T, int32_t>::type;
        Int y = x;
        y %= static_cast<Int>(mod);
        if(y < 0) y += mod;
        num = static_cast<uint32_t>(y);
    }
    Residue_Field& operator+=(Residue_Field x) {
        num += x.num;
        if(num >= mod) num -= mod;
        return *this;
    }
    Residue_Field& operator-=(Residue_Field x) {
        if(num < x.num) num += mod;
        num -= x.num;
        return *this;
    }
    Residue_Field& operator*=(Residue_Field x) {
        num = static_cast<uint64_t>(num) * x.num % mod;
        return *this;
    }
    Residue_Field& operator/=(Residue_Field x) {
        return *this *= x.inv();
    }
    Residue_Field operator+(Residue_Field x) const { return Residue_Field(*this) += x; }
    Residue_Field operator-(Residue_Field x) const { return Residue_Field(*this) -= x; }
    Residue_Field operator*(Residue_Field x) const { return Residue_Field(*this) *= x; }
    Residue_Field operator/(Residue_Field x) const { return Residue_Field(*this) /= x; }
    Residue_Field pow(uint64_t x) const {
        Residue_Field ans = 1, cnt = *this;
        while(x){
            if(x & 1) ans *= cnt;
            cnt *= cnt;
            x >>= 1;
        }
        return ans;
    }
    Residue_Field inv() const { return pow(mod - 2); }
};

int main(){
    using Mint = Residue_Field<998244353>;
    
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    
    std::vector dp(c + 1, std::vector<Mint>(d + 1));
    dp[a][b] = 1;
    
    for(int i = a; i <= c; i++) for(int j = b; j <= d; j++){
        dp[i][j] += dp[i - 1][j] * j + dp[i][j - 1] * i -  dp[i - 1][j - 1] * (i - 1) * (j - 1);
    }
    
    std::cout << dp[c][d].num << std::endl;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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; }
 

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

    string s;
    cin >> s;

    rep(i, 3)
    {
        cout << s[i];
    }

    



    return 0;
}



Measured memory_bytes: 3652
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
const ll MOD = 1000003;
const int MAX = 1000003;

// fac
ll fac[MAX], finv[MAX], inv[MAX];
void fac_init() {
  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;
  }
}

// pow
ll power(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

int Q;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  fac_init();
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    ll xi, di, ni;
    cin >> xi >> di >> ni;
    if (di == 0) {
      cout << power(xi, ni) << endl;
      continue;
    }

    ll a = xi * inv[di] % MOD;
    if (a + ni - 1 >= MOD) {
      cout << 0 << endl;
      continue;
    }

    ll ans = power(di, ni) * fac[a + ni - 1] % MOD;
    ans *= finv[a - 1];
    ans %= MOD;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 24320
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);

  char s[n][101];
  int t[n];
  for (int i = 0; i < n; i++) {
    scanf("%s %d", s[i], &t[i]);
  }

  char x[101];
  scanf("%s", x);

  int asleep;

  int flag;
  for (int i = 0; i < n; i++) {
    flag = 1;
    for (int j = 0; j < 101; j++) {
      if (x[j] < 'a' || x[j] > 'z') {
        break;
      }
      if (s[i][j] != x[j]) {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      asleep = i;
      break;
    }
  }

  int playtime = 0;
  for (int i = asleep+1; i < n; i++) {
    playtime += t[i];
  }

  printf("%d\n", playtime);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;
 
void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}

const int N=1e6+5,M=5e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;

 
typedef struct node{
    int s, e, val, pos;
    bool operator<(const node& n) const{
        if(e != n.e) return e < n.e;
        return val > n.val;
    }
    node(){};
    node(int ss, int ee, int v, int p){
        s = ss, e = ee, val = v, pos = p;
    }
}node;
 


int freq[N], tree[N], n, ans[N];
 
void update(int x, int val){
    while(x <= n){
        tree[x] += val;
        x += x & -x;
    }
}
 
int query(int x){
    int ret = 0;
    while(x > 0){
        ret += tree[x];
        x -= x & -x;
    }
    return ret;
}
 
int main(){
    int q, s, e;
    vector<node> v;
    scanf("%d %d", &n,&q);
    for(int i = 1; i <= n; i++){
        scanf("%d", &s);
        v.push_back(node(i, i, s, -1));
    }
    for(int i = 0; i < q; i++){
        scanf("%d %d", &s, &e);
        v.push_back(node(s, e, 0, i));
    }
 
    sort(v.begin(), v.end());
 
    for(int i = 0;i < v.size(); i++){
        if(v[i].val == 0){
            ans[v[i].pos] = query(v[i].e) - query(v[i].s - 1);
        }else{
            if(freq[v[i].val] != 0) update(freq[v[i].val], -1);
            update(v[i].s, 1);
            freq[v[i].val] = v[i].s;
        }
    }
 
    for(int i = 0; i < q; i++){
        printf("%d\n", ans[i]);
    }
}

Measured memory_bytes: 25348
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
using namespace std;
int main(){
string s;
int count=0;
cin>>s[0]>>s[1]>>s[2];
if(s[0]=='1')
count++;
if(s[1]=='1')
count++;
if(s[2]=='1')
count++;
cout<<count<<endl;
}


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

using namespace std;

int n;
int a;
set<int> st;

int main(){
  cin >> n;
  int ans = 0;
  for(int i = 0; i < n; ++i){
    cin >> a;
    //cout << st.count(a) << endl;
    if(st.count(a) == 1){
      st.erase(a);
      ans--;
    }else{
      st.insert(a);
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4864
# solve function
def solve(line):
    stack = []

    for i in range(len(line)):
        if line[i] == '(' or line[i] == '[':
            stack.append(line[i])
        elif len(stack) > 0:
            if line[i] == ')' and stack[-1] == '(':
                stack.pop()
            elif line[i] == ']' and stack[-1] == '[':
                stack.pop()
            elif line[i] == ']' or line[i] == ')':
                return 'no'
        elif line[i] == ']' or line[i] == ')':
            return 'no'

    if len(stack) == 0:
        return 'yes'
    else:
        return 'no'



# main function
if __name__ == '__main__':
    while True:
        line = input()

        if line == ".":
            break

        result = solve(line)
        print(result)

Measured memory_bytes: 6720
#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 - 1; 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 ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  ll n;
  cin >> n;
  ll a[n];
  map<ll, ll> mp;
  REP(i, n){
    cin >> a[i];
    mp[i + 1] = a[i];
  }

  ll ans = 0;

  REP(i, n){
    if(mp[a[i]] == i + 1) ans++;
  }

  cout << ans / 2 << endl;

  return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
 
int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<char>> t(h,vector<char>(w));
  rep(i,h)rep(j,w) cin>>t[i][j];
  rep(i,h)rep(j,w){
    if(t[i][j]=='#') continue;
    if(t[i][j]=='.'){
      int cnt=0;
      for(int k=i-1;k<=i+1;k++){
        for(int l=j-1;l<=j+1;l++){
          if(k<0||k>=h||l<0||l>=w) continue;
          if(t[k][l]=='#') cnt++;
        }
      }
      t[i][j]='0'+cnt;
    }
  }
  rep(i,h){
    rep(j,w){
      cout<<t[i][j];
    }
    cout<<endl;
  }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,a,b,temp,ans=0;
	cin>>n>>a>>b;
	vector<long long> x;
	for(int i=0;i!=n;++i){
		cin>>temp;
		x.push_back(temp);
	}
	sort(x.begin(),x.end());
	for(int i=0;i!=n-1;++i){
		if((x[i+1]-x[i])*a<=b)
			ans+=(x[i+1]-x[i])*a;
		else
			ans+=b;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll w,h,x,y;
	cin>>w>>h>>x>>y;
	double ans=w*h/2.0;
	cout<<setprecision(15)<<ans<<endl;
	if(w==2*x && h==2*y){
		cout<<1<<endl;
	}else{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 3808
W,H,N = map(int, raw_input().split())
l = 0
r = W
d = 0
u = H
for i in range(N):
    x,y,a = map(int, raw_input().split())
    if a == 1:
        l = max(l, x)
    elif a == 2:
        r = min(r, x)
    elif a == 3:
        d = max(d, y)
    else:
        u = min(u, y)
if l >= r or d >= u:
    print 0
else:
    print (r-l) * (u-d)


Measured memory_bytes: 2568
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
  
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        {
            long n=sc.nextLong();
        
  
        int ans=0;
        HashSet<Long> hs=new HashSet<>();
        for (int i = 2; i <= Math.sqrt(n); i++) 
        { 
            
            int q=1;
            while (n%(long)Math.pow(i,q) == 0) 
            { 
               
                n /= (long)Math.pow(i,q) ;
                hs.add((long)Math.pow(i,q) );
                q++;
                ans++;
            } 
            while(n%i==0)
            n/=i;
        } 
  
       
        if (n>2&&(hs.contains(n)==false))
        ans++;
            System.out.print(ans); 
        }
            
    }
   
}

Measured memory_bytes: 35860