akhauriyash/Code-Regression huggingface dataset:
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 998244353;

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

struct point{
  ll x, y;
  point(ll x, ll y): x(x), y(y){}
  point(){}
};

template <typename T>
T power(T a, T n, T mod) {
  T res = 1;
  T tmp = n;
  T curr = a;
  while(tmp){
    if(tmp % 2 == 1){
      res = (T)((ll)res * curr % mod);
    }
    curr = (T)((ll)curr * curr % mod);
    tmp >>= 1;
  }
  return res;
}

bool used[201][201];

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<point> p(n);
  rep(i, n)cin >> p[i].x >> p[i].y;
  ll res = power(2, n, mod);
  res = (res - 1 - n + mod) % mod;
  res = (res - n * (n-1) / 2 + mod) % mod;
  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){
      if(used[i][j])continue;
      vector<int> vec;
      vec.pb(i);
      vec.pb(j);
      for(int k = j + 1; k < n; k++){
        ll tmp = (p[k].y - p[i].y) * (p[i].x - p[j].x) - (p[k].x - p[i].x) * (p[i].y - p[j].y);
        if(tmp == 0)vec.pb(k);
      }
      if(sz(vec) == 2)continue;
      ll tmp = (power(2, sz(vec), mod) - 1 - sz(vec) - sz(vec) * (sz(vec) - 1) / 2 + mod) % mod;
      res = (res - tmp + mod) % mod;
      for(int k = 0; k < sz(vec); k++){
        for(int l = 0; l < sz(vec); l++){
          used[vec[k]][vec[l]] = true;
        }
      }
    }
  }
  cout << res << endl;
	return 0;
}


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

prod = 1

A.sort()
if A[0] == 0:
    prod = 0

A.sort(reverse=True)


for i in range(N):
    prod *= A[i]
    if prod > 1e18:
        prod = -1
        break
    if prod == 0:
        break

print(prod)


Measured memory_bytes: 21584
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	int K;
	int i;
	char str1[100000],str2[100000];
 
	fgets(str1, sizeof(str1), stdin);
	K=atoi(strtok(str1," "));
	fgets(str1,sizeof(str1), stdin);

	if(K >= ( (int)strlen(str1) -1) ){
		printf("%s\n",str1);
	}else{
		strncpy( str2, str1,K);
		str2[K] = '\0'; 
		printf("%s...\n",str2);
	}

	return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pr;
const char* color = "RGB";
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int h, w;
vector<string> grid;
bool change[10][10];

bool ok(int i, int j)
{
	return i >= 0 && i < h && j >= 0 && j < w;
}

bool check(vector<string> grid)
{
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (grid[0][0] != grid[i][j]) return false;
		}
	}
	return true;
}

bool search(int d, vector<string> grid)
{
	if (check(grid)) return true;
	if (d == 0) return false;
	
	for (const char *col = color; *col != '\0'; col++){
		if (grid[0][0] == *col) continue;
		vector<string> ngrid = grid;
		fill_n(*change, 100, false);
		change[0][0] = true;
		queue<Pr> que;
		for (que.push(Pr(0, 0)); que.size(); que.pop()){
			Pr p = que.front();
			ngrid[p.first][p.second] = *col;
			for (int dir = 0; dir < 4; dir++){
				int nx = p.first + dx[dir];
				int ny = p.second + dy[dir];
				if (!ok(nx, ny)) continue;
				if (grid[nx][ny] != grid[0][0]) continue;
				if (change[nx][ny]) continue;
				change[nx][ny] = true;
				que.push(Pr(nx, ny));
			}
		}
		
		if (search(d - 1, ngrid)) return true;
	}
	
	return false;
}

int solve()
{
	for (int d = 0; ; d++){
		if (search(d, grid)) return d;
	}
}

int main()
{
	while (scanf("%d %d", &w, &h), w){
		grid = vector<string>(h);
		
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				char c;
				scanf(" %c", &c);
				grid[i] += c;
			}
		}
		
		printf("%d\n", solve());
	}
}

Measured memory_bytes: 1256
#include<cstdio>
#include<iostream>
#include<vector>
#include<math.h>

using namespace std;

int main() {
	int D, N;
	vector<vector<int>> X;
	scanf("%d", &N);//N
	scanf("%d", &D);//D
	int count = 0;
	double powLength = 0;
	vector<int> X_j;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) {
			
			int X_ij;
			scanf("%d", &X_ij);//X_ij
			X_j.push_back(X_ij);
		}
		X.push_back(X_j);
		X_j.clear();
	}

	for (int i1 = 0; i1 < N; i1++) {
		for (int i2 = i1 + 1; i2 < N; i2++) {
			for (int j = 0; j < D; j++) {
				powLength += ( X.at(i1).at(j) - X.at(i2).at(j) ) * ( X.at(i1).at(j) - X.at(i2).at(j) );
			}
			if (sqrt(powLength) == (int)sqrt(powLength)) {
				count++;
			}
			powLength = 0;
		}
	}
	printf("%d\n", count);

	return 0;
}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}


int dsu[100001], ranks[100001];
int find(int node){
    if(dsu[node] == node) return node;
    return dsu[node] = find(dsu[node]);
}
void combine(int a, int b){
    a = find(a); b = find(b);
    if(a == b) return;
    if(ranks[a] < ranks[b]){
        dsu[a] = b;
    } else if(ranks[b] < ranks[a]){
        dsu[b] = a;
    } else {
        dsu[a] = b; ranks[b]++;
    }
}



int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

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

    for(int i = 0; i < n; ++i)
        dsu[i] = i;

    int total = n;
    for(int i = 0; i < m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        if(find(a) != find(b)){
            --total;
            combine(a, b);
        }
    }

    cout << total;

    return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	cout << (a + b + 1) / 2 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#define MAX_DATASET_SIZE 3000

int main() {
  int x, y;

  for(int i = 0; i < MAX_DATASET_SIZE; i++) {
    scanf("%d %d\n", &x, &y);

    if (x == 0 && y == 0) {
      break;
    }

    if (!(x < y)) {
      int temp = x;
      x = y;
      y = temp;
    }

    printf("%d %d\n", x, y);
  }
}



Measured memory_bytes: 2732
from collections import Counter
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
Count=sorted(Counter(A).items())
cnt=0
if n%2==1:
    if Count.pop(0)[1]==1 and len(Count)==n//2:
        point=2
        for v,m in Count:
            if v==point and m==2:
                cnt +=1
                point +=2
        print((2**cnt)%mod)
    else:print(0);exit()
else:
    point=1
    for v,m in Count:
        if v==point and m==2:
            cnt +=1
            point +=2
        else:print(0);exit()
    print((2**cnt)%mod)

Measured memory_bytes: 16096
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	int N, M;
	cin >> N >> M;
	if (abs(N - M) > 1) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = (N == M) ? 2 : 1;
	for (int i = 1; i <= N; i++) (ans *= i) %= MOD;
	for (int i = 1; i <= M; i++) (ans *= i) %= MOD;
	cout << ans << endl;
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  //
  //
  long long n;
  cin >> n;

  ll count = 0;
  for (long long i = 0; i < n; i++) {
    ll c1, c2;
    cin >> c1 >> c2;
    if (c1 == c2) {
      count++;
    } else {
      count = 0;
    }

    if (count == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}


Measured memory_bytes: 3628
"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

N = int(input())
S = input()

#N = int(5e3)
#S = 'a' *N

ans = 0
for circ in range(1, N):
  cnt = 0
  solver = [0]
  for i in range(N-circ):
    if S[i] == S[i+circ]:
      cnt += 1
    else:
      solver.append(cnt)
      cnt = 0
  else:
    solver.append(cnt)
  ans = max(ans, min(circ, max(solver)))

print(ans)




"""
ans = 0
for i in range(N-1):
  if i+1+ans >= N:
    break
  lst = [0]
  for j in range(i+1+ans,N):
    cnt = 0
    if S[i] == S[j]:
      cnt += 1
      for k in range(1,min(j-i, N-j)):
        if S[i+k] == S[j+k]:
          cnt += 1
        else:
          break
    lst.append(cnt)
    #print(i, j, cnt)
  ans = max(ans, max(lst))
  
print(ans)
"""

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

int main() {
  int N;
  cin >> N;
  vector<int> x(N);
  
  for (int i = 0; i < N; i++) {
    cin >> x.at(i);
  }
  
  sort(x.begin(), x.end());
  reverse(x.begin(), x.end());
  int sumx = 0;
  int sumy = 0;
  
  for (int i = 0; i < N; i++) {
    
    if (i % 2 == 0) {
      sumx += x.at(i);
    }
    
    else {
      sumy += x.at(i);
    }
  }
  
  cout << sumx - sumy << endl;
}

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

using namespace std;
typedef long long ll;

int n;

bool C(ll k) {
    return (1 + k) * k / 2 >= n;
}

int main() {
    cin >> n;

    ll ok = n;
    ll ng = 0;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (C(mid)) ok = mid;
        else ng = mid;
    }

    ll d = (1 + ok) * ok / 2 - n;
    for (int i = 1; i <= ok; ++i) {
        if (i == d) continue;
        cout << i << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <numeric>

int main(void) {
	std::string s, t, u;
	int n;

	std::cin >> n >> s >> t >> u;

	int ans = 0;
	for (size_t i = 0; i < s.length(); i++) {
		if (s[i] == t[i]) {
			if (t[i] == u[i]) {
				continue;
			}
			else {
				ans += 1;
			}
		}
		else {
			if (t[i] == u[i]) {
				ans += 1;
			}
			else if (s[i] == u[i]) {
				ans += 1;
			}
			else {
				ans += 2;
			}
		}
	}

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

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

int main(){
  int k, x;
  cin >> k>>x;
  for(int i = x-k+1; i <= x+k-1; i++) cout << i << endl;
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N);
  ll ans = LLONG_MAX;
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    ll cnt = 0;
    while (a % 2 == 0) {
      a /= 2;
      cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const char target[]="AKIHABARA";
char s[1000];

int main() {
    scanf("%s",s);
    int l=strlen(s);
    int p=0;
    if (s[p]=='A') p++;
    if (s[p]=='K' && s[p+1]=='I' && s[p+2]=='H') {
        p=p+3;
        if (s[p]=='A') p++;
        if (s[p]=='B') {
            p++;
            if (s[p]=='A') p++;
            if (s[p]=='R') {
                p++;
                if (s[p]=='A') p++;
                if (p>=l) return puts("YES"),0;
            }
        }
    }
    puts("NO");
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  
  if(s.find("?") == string::npos){
    cout << s;
    //cout << "? ga naiyo\n";
    return 0;
  }
  
  size_t position_Phatena = 0;
  size_t position_2hatena = 0;
  size_t position_hatenaD = 0;
  size_t position_hatena = 0;
  
  while(s.find("?") != string::npos){
//    if((position_Phatena = s.find("P?") ) != string::npos){
//    	s[position_hatenaD+1] = 'D';
//    } 
//  	if( (position_2hatena = s.find("??") ) != string::npos){
//      s[position_2hatena] = 'P';
//      s[position_2hatena+1] = 'D';
//    }
//    if((position_hatenaD = s.find("?D") ) != string::npos){
//    	s[position_hatenaD] = 'P';
//    }
    if( (position_hatena = s.find("?") ) != string::npos){
    	s[position_hatena] = 'D';
    }
  }
  
//  cout << s.find("??") << endl;
  
  cout << s;
  
  return 0;
}

Measured memory_bytes: 3716
import fractions
from functools import reduce

N, X = map(int, input().split())
x = list(map(lambda i: abs(i - X), map(int, input().split())))

# 全てのx - XがDの倍数となるような最大のD
# -> x - Xの最大公約数

print(reduce(fractions.gcd, x))

Measured memory_bytes: 16280
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
	int n;
	while(cin>>n&&n){
		static int dp[50][5][10000];
		rep(i,50)rep(j,5)rep(k,10000)dp[i][j][k] = INF;
		dp[0][0][0] = 0;
		
		int bef = 0;
		bool endf = false;
		int p,t;
		rep(i,n){
			cin>>p>>t;
			if(endf)continue;
			rep(j,3){
				rep(k,10000){
					if(k+abs(p-bef)>=10000)continue;
					int res = dp[i][j][k] + (j+1)*abs(p-bef);
					if(res<=t)
						dp[i+1][j+1][k+abs(p-bef)] = t;
				}
			}
			for(int j=1;j<=3;j++){
				rep(k,10000){
					if(k+bef+p>=10000)continue;
					int res = dp[i][j][k]+(j+1)*bef+p;
					if(res<=t)
						dp[i+1][1][k+bef+p] = t;
				}
			}
			
			bool f=false;
			rep(j,4){
				rep(k,10000){
					if(dp[i+1][j][k]<=t)f=true;
				}
			}
			if(!f){
				cout<<"NG "<<i+1<<endl;
				endf = true;
			}
			
			bef = p;
		}
		if(!endf){
			int ans = INF;
			rep(i,4){
				rep(j,10000){
					if(dp[n][i][j]<=t){
						ans = min<ll>(ans,j+p);
					}
				}
			}
			cout<<"OK "<<ans<<endl;
		}
	}
	
}

Measured memory_bytes: 12780
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string s, t;
	cin>>s>>t;
	cout<<(t+s)<<endl;
	return 0;
}

Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define int long long
using namespace std;
int divisors[10000005]={0};
int solve()
{
	int n;
	cin>>n;
	for (int i = 1; i <= n; ++i){
 		for (int j = i; j <= n; j += i){
  			++divisors[j];
  		}
  	}
  	int sum=0;
  	for(int i=1;i<=n;i++)
  		sum+=i*divisors[i];
  	cout<<sum<<endl;
	return 0;
}
signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	test
		solve();
}






Measured memory_bytes: 81732
import decimal

N = int(input())
a = list(int(i) for i in input().split())

mean = sum(a)/N
min  = float('inf') 

min_id = 0

for i, ai in enumerate(a):
  diff = abs(ai-mean)
  if(diff < min):
    min = diff
    min_id = i
  
print(min_id)

Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,n) for (lint i = 0; i < (n); i++)
#define REP1(i,n) for (lint i = 1; i < (n); i++)

int main(void){
    int N, D;
    cin >> N >> D;
    int mod = N % ((D*2)+1);
    (mod == 0) ? cout << N / ((D*2)+1) << endl : cout << N / ((D*2)+1) + 1 << endl;
    return 0;
}

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

int main(){
        int i,n,k,cnt=0,idx=0,max_val;
        double num=0,ans=0;
        cin >> n >> k;
        vector<int> p(n);
        vector<double> e(1001);
        for(i=1;i<1001;++i){
                num += (double)i;
                e.at(i) = num/i;
        }
        for(i=0;i<n;++i){
                cin >> p.at(i);
                if(i<k) cnt += p.at(i);
        }
        max_val = cnt;
        for(i=0;i<n-k;++i){
                cnt -= p.at(i);
                cnt += p.at(i+k);
                if(cnt>max_val){
                        max_val = cnt;
                        idx = i+1;
                }
        }
        for(i=idx;i<idx+k;++i) ans += e.at(p.at(i));
        printf("%.12f\n", ans);
        return 0;
}

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

int main(){
    string T;
    cin >> T;

    for(int i=0; i<T.size(); i++){
        if(i%2==0 && T.at(i)=='L'){
            cout << "No" << endl;
            return 0;
        }
        if(i%2!=0 && T.at(i)=='R'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
  int N, M;
  
  //青カード配列
  cin >> N;
  vector<string> vecN(N);
  for(int i = 0; i < N; i++){
    cin >> vecN.at(i);
  }
  
  //赤カード配列
  cin >> M;
  vector<string> vecM(M);
  for(int i = 0; i < M; i++){
    cin >> vecM.at(i);
  }
  
  //各点数算出
  int max = 0;
  for(int i = 0; i < N; i++){
    int counter = 0;
    //加算
    for(int j = 0; j < N; j++){
      if(vecN.at(i) == vecN.at(j)){
        counter += 1;
      }
      else{
      }
    }
    //減算
    for(int j = 0; j < M; j++){
      if(vecN.at(i) == vecM.at(j)){
        counter -= 1;
      }
      else{
      }
    }
    //最大値なら更新
    if(counter > max){
      max = counter;
    }
    else{
    }
  }
  
  //表示
  cout << max << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

ll MOD = 1000000007;

int solve(ll n)
{
    ll count = 0;
    for (ll i = 1; i <= n; i++)
    {
        if (n % i == 0)
            count++;

        if (count == 9)
        {
            return count;
        }
    }

    return count;
}

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

    ll ans = 0;

    for (ll i = 1; i <= n; i += 2)
    {
        if (solve(i) == 8)
        {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IN(type, n) type n; cin >> n

int main() {
  IN(string, S);
  IN(string, T);
  int sS = S.size();
  int sT = T.size();
  int min = 1000000;
  for (int i = 0; i < sS - sT + 1; ++i) {
    string tmp = S.substr(i, sT);
    int count = 0;
    for (int j = 0; j < sT; ++j) {
      if (tmp[j] != T[j]) count++;
    }
    if (count < min) min = count;
  }
  cout << min << endl;

  return 0;
}


Measured memory_bytes: 3632
#from math import *
import fractions
import sys
import collections
import itertools
import pprint
from collections import deque
from heapq import *
import copy
N,X,M=map(int,input().split())
l=[0]*(M+1)
l[X]=1
X2=X
ans=0
for i in range(10**5+1):
    #print(X)
    X=pow(X,2,M)
    if l[X]==0:
        l[X]=i+2
    else:
        start=l[X]
        end=i+2
        #print(i+1,l[X])
        break
#print(l)
res=[]
X=X2
loop=[]
#print(start,end)
for i in range(start-1):
    res.append(X)
    X=pow(X,2,M)
for i in range(start,end):
    loop.append(X)
    X=pow(X,2,M)
#print(res,loop)
loopsum=sum(loop)
if N<=len(res):
    for i in range(N):
        ans=ans+res[i]
else:
    for i in range(len(res)):
        ans=ans+res[i]
    loopnum=(N-len(res))//len(loop)
    loopres=(N-len(res))%len(loop)
    for i in range(loopres):
        ans=ans+loop[i]
    ans=ans+loopnum*loopsum
print(ans)

Measured memory_bytes: 76224
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e6+5;
int f[N],a[N],cnt[N],q[N],to[N],sum,h,t,n,m;
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	fp(i,1,n-1)scanf("%d",&a[i]);
	scanf("%d",&m);
	fp(i,3,n-1)sum+=a[i];
	h=1e6+5,t=h-1;
	fp(i,0,1e6)q[++t]=i;
	fp(i,3,n-1)for(R int j=h+1,s=h+a[i];j<=s;++j)q[--h]=q[j];
	fp(i,h,h+1e6)to[i-h]=q[i];
	while(m--){
		scanf("%d",&a[n]);
		printf("%d\n",(a[n]>=sum?a[n]-sum:to[a[n]])+a[1]-a[2]);
	}
	return 0;
}

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

int main()
{
	int k, t, MAXN=INT_MIN;
	cin >> k >> t;
	while(t --) {
		int tmp;cin>>tmp;
		MAXN = max(MAXN, tmp);
	} cout<<max(2*MAXN-1-k,0)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 3*(int)1e5 + 10;

int n;
vector<int> v[N];
#define seen vis
bool vis[N];
int color[N];

void bfs(int s){

   queue<int> q;
   q.push(s);  

   seen[s] = 1;
   while(!q.empty()){
      int x = q.front();
      q.pop();

      for(auto it: v[x]){
         if (!seen[it]){
            seen[it] = 1;
            color[it] = x;
            q.push(it);
         }
      }

   }

}

void solve(){
   int m;
   cin>>n>>m;

   for (int i = 0; i < m; ++i)
   {
      int x, y;
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
   }

   for (int i = 1; i <= n; ++i)
   {
      if (!vis[i]){
         if (i != 1){
            cout<<"No";
            exit(0);         
         }
         else{
            bfs(i);         
         }
      }      
   }

   cout<<"Yes"<<endl;
   for (int i = 2; i <= n; ++i)
   {
      cout<<color[i]<<endl;
   }

}

int32_t main(){_
   
   int t = 1;
   //cin >> t;

   while(t--){
     solve();
     cout << endl;
   }
   

   return 0;
}

Measured memory_bytes: 17724
import math


def law_of_cosine(x, y, angle_between_x_y):
    rad = math.radians(angle_between_x_y)
    z = (x ** 2 + y ** 2 - 2 * x * y * math.cos(rad)) ** (1 / 2)
    return z


def main():
    a, b, h, m = map(int, input().split())

    h_angle = 30 * h + 0.5 * m
    m_angle = 6 * m
    between_angle = abs(h_angle - m_angle)
    angle = min(between_angle, 360 - between_angle)

    cm = law_of_cosine(a, b, angle)
    print(cm)


if __name__ == '__main__':
    main()

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

int main() {
  int n,a,i=0;
  cin >> n;
  for(; i < n; i += 1){
    cin >> a;
    if(a %2 == 0 && (!(a %3 == 0 || a %5 == 0))){
      break;
    }
  }
  if(i == n){
    cout << "APPROVED" << endl;
  }else{
    cout << "DENIED" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
const string YES = "Yes";
const string NO = "No";

int main()
{
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  long long D;
  scanf("%lld", &D);
  for (int i = 0; i < 110; ++i)
  {
    C -= B;
    if (C <= 0)
    {
      cout << YES << endl;
      break;
    }
    A -= D;
    if (A <= 0)
    {
      cout << NO << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 3192
#include <stdio.h>
main()
{
	int H, W, i, j;

	while(1){
		scanf("%d %d", &H, &W);

		if(H == 0 && W == 0) break;
		
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int n,w;
int weight[110];
int value[110];

ll dp[110][100100];

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin >> n >> w;
    rep(i,n) cin >> weight[i] >> value[i];

    rep(i,110){
        rep(j,100100){
            dp[i][j] = 1e9;
        }
    }
    dp[0][0] = 0;

    for(int i=0; i<n; i++){
        for(int sv=0; sv<100100; sv++){
            chmin(dp[i+1][sv + value[i]], dp[i][sv] + weight[i]);
            chmin(dp[i+1][sv], dp[i][sv]);
        }
    }

    ll ans=0;

    for(int i=0; i<100100; i++){
        if(dp[n][i] <= w){
            ans = i;
        }
    }

    ll allw=0;
    ll allv=0;
    rep(i,n){
        allw += weight[i];
        allv += value[i];
    }

    if(allw <= w) ans = allv;

    dunk(ans);
}

Measured memory_bytes: 86400
dataset = []

while True:
    h, w = map(int, input().split())
    if (h >= 1 and h <= 300) and (w >= 1 and w <= 300):
        listed = []
        listed.append(h)
        listed.append(w)
        dataset.append(listed)
    elif h != 0 and w != 0:
        break
    else:
        break

for listed in dataset:
    h = listed[0]
    w = listed[1]

    for i in range(h):
        if i % 2 == 0:
            for j in range(w):
                if j % 2 == 0:
                    print("#", end="")
                elif j % 2 == 1:
                    print(".", end="")
            print()
        elif i % 2 == 1:
            for j in range(w):
                if j % 2 == 0:
                    print(".", end="")
                elif j % 2 == 1:
                    print("#", end="")
            print()
    print()

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

int main(){
    int n;
    cin >> n;
    int A[100];
    int a = 0;
    for (int i = 0; i < n; i++){
        cin >> A[i];
    }
    int flag = 1;
    while(flag){
        flag = 0;
        for (int j = n-1; j >= 1; j--){
            if (A[j] < A[j-1]){
                int v = A[j-1];
                A[j-1] = A[j];
                A[j] = v;
                flag = 1;
                a++;
            }
        }
    }
    for (int i = 0; i < n; i++){
        if (i == n-1) cout << A[i] << endl;
        else cout << A[i] << ' ';
    }
    cout << a << endl;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define L long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
int n,m,x[200010],a[200010];
char s[200010];
L l,r,f[200],g[200];
inline L count(L r,int i)
{
	int j;
	L k=0;
	for(j=1;j<=n;j++)
	  a[j]=a[j-1]+(s[j]=='a'+i);
	if(n%m==0)
	  if(r<=n)
	    return a[r];
	  else
	    return a[n]+(r-n)/m*a[m]+a[(r-n)%m];
	else
	  {
	   f[1]=a[m];
	   g[1]=m;
	   f[2]=a[n];
	   g[2]=n;
	   for(j=3;g[j-1]<r;j++)
	     {
		  f[j]=f[j-1]+f[j-2];
		  g[j]=g[j-1]+g[j-2];
		 }
	   for(j--;j;j--)
	     if(r>=g[j])
	       {
			r-=g[j];
			k+=f[j];
		   }
	   k+=a[r];
	   return k;
	  }
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	scanf("%s%lld%lld",&s[0]+1,&l,&r);
	n=strlen(&s[0]+1);
	for(i=2;i<=n;i++)
	  {
	   for(j=x[i-1];j;j=x[j])
	     if(s[j+1]==s[i])
	       break;
	   if(s[j+1]==s[i])
	     x[i]=j+1;
	  }
	for(i=x[n];i>n/2;i=x[i]);
	n-=i;
	m=n-x[n];
	for(i=0;i<26;i++)
	  printf("%lld ",count(r,i)-count(l-1,i));
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main()
{
int n,k,ans=0;
cin>>n>>k;
VI p(n);
for (int i = 0; i < n; i++)
{
 cin>>p.at(i);   
}
sort(	ALL(p));
for (int i = 0; i < k; i++)
{
    ans=ans+p.at(i);
}
cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
A,B,C,X,Y = map(int, input().split())

res=0

if X>0 and Y>0:
        if A+B > 2*C: # must buy C pizza
                minxy = min(X,Y)
                res += 2 * C * minxy
                X -= minxy
                Y -= minxy

# here, X == 0 or Y == 0




if X > 0: # buy some A pizza
        if A > 2 * C: # buy 2X * AB pizza
                res += C * 2*X
                Y -= X
        else: # buy A pizza
                res += X * A

if Y > 0: # buy some B pizza
        if B > 2 * C:
                res += C*2*Y
        else:
                res+= Y * B

print(res)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>

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

using namespace std;

const int INF=1<<29;

int n,sz1[14],sz2[14];
int sum1[1<<14],sum2[1<<14];

int dp[1<<14];
int dfs(int S,int rem){
	if(S==0) return 0;

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

	int res=INF;
	for(int T=S;T;T=(T-1)&S) if(sum2[T]<=rem) {
		res=min(res,dfs(S-T,rem-sum2[T]+sum1[T])+1);
	}
	return dp[S]=res;
}

int main(){
	for(int m;scanf("%d%d",&n,&m),n;){
		rep(i,n) scanf("%d%d",sz1+i,sz2+i);

		rep(S,1<<n){
			sum1[S]=sum2[S]=0;
			rep(i,n) if(S>>i&1) {
				sum1[S]+=sz1[i];
				sum2[S]+=sz2[i];
			}
		}

		memset(dp,-1,sizeof dp);
		int ans=dfs((1<<n)-1,m);
		if(ans<INF) printf("%d\n",ans); else puts("Impossible");
	}

	return 0;
}

Measured memory_bytes: 1240
#include <cstdio>
#include <cctype>
int main() {
	int n[26] = { 0 };
	char c;
	while (scanf("%c", &c) != EOF)
		n[(int)tolower(c) - 97]++;
	c = 97;
	for (int i = 0; i < 26; i++)
		printf("%c : %d\n", c + i, n[i]);
}

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

template <typename T>
struct SegmentTree {
    using F = function<T(T, T)>;

    const T e;
    const F f;
    size_t sz;
    vector<T> tree;

    SegmentTree(size_t n, const F &f, const T &e = 0) : f(f), e(e) {
        sz = 1;
        while(sz < n) sz <<= 1;
        tree.assign(2*sz, e);
    }

    void set(typename vector<T>::iterator begin, typename vector<T>::iterator end) {
        copy(begin, end, tree.begin() + sz);
        for(size_t k=sz-1; k>0; k--)
            tree[k] = f(tree[2*k+0], tree[2*k+1]);
    }

    void update(size_t k, const T &x) {
        k += sz;
        tree[k] = x;
        while(k >>= 1)
            tree[k] = f(tree[2*k+0], tree[2*k+1]);
    }

    T query(size_t a, size_t b) const {
        b = min(b, sz);
        a = max((size_t)0, a);
        T l = e, r = e;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) l = f(l, tree[a++]);
            if(b & 1) r = f(tree[--b], r);
        }
        return f(l, r);
    }

    T operator[](const size_t k) const {
        return tree[sz + k];
    }
};

int main(void) {
    constexpr ll MOD = 998244353;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n, q;
    cin >> n >> q;

    set<ll> sx, sy;
    sx.insert(-0);
    sy.insert(-0);
    SegmentTree<ll> stx(n+5, [&](ll a, ll b){return min(a, b);}, n-1);
    SegmentTree<ll> sty(n+5, [&](ll a, ll b){return min(a, b);}, n-1);

    ll res = 0;
    while(q--) {
        ll t, x;
        cin >> t >> x;
        x--;
        if(t == 1) {
            ll stop = stx.query(x, n) - 1;
            res += stop;
            sty.update(stop, min(sty.query(stop, n), x));
        } else {
            ll stop = sty.query(x, n) - 1;
            res += stop;
            stx.update(stop, min(stx.query(stop, n), x));
        }
    }
    cout << (n-2)*(n-2) - res << endl;
}

Measured memory_bytes: 11380
class BIT():
    def __init__(self,n):
        self.BIT=[0]*(n+1)
        self.num=n

    def query(self,idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def update(self,idx,x):
        while idx <= self.num:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return

import sys

input = sys.stdin.readline

N,Q = map(int,input().split())
a = list(map(int,input().split()))
bit = BIT(N)

for i in range(N):
    bit.update(i+1,a[i])

for i in range(Q):
    q,l,r = map(int,input().split())
    if q == 0:
        bit.update(l+1,r)
    else:
        res = bit.query(r) - bit.query(l)
        print(res)


Measured memory_bytes: 127372
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		for(int i = 1; i <= n; i++){
			if(sc.nextInt() != i) count++;
		}
		if(count <= 2) System.out.println("YES");
		else System.out.println("NO");
	}
}


Measured memory_bytes: 23764
n,k = map(int, input().split())
square = [[0]*k*2 for _ in range(k*2)]

for i in range(n):
    x, y, c = input().split()
    x = int(x)
    y = int(y)
    if c=='W':
        y += k
    x = x%(k*2)
    y = y%(k*2)
    square[x][y] += 1

class CumulativeSum2d():
    def __init__(self, collection_2d):
        yl = len(collection_2d)
        xl = len(collection_2d[0])
        self.data = [[0] * (xl+1) for _ in range(yl+1)]
        for y in range(1, yl+1):
            for x in range(1, xl+1):
                top_sum         = self.data[y-1][x]
                left_sum        = self.data[y][x-1]
                dup_sum         = self.data[y-1][x-1]
                self.data[y][x] = top_sum + left_sum - dup_sum
                self.data[y][x] += collection_2d[y-1][x-1]

    def query(self, x, y, x1, y1):
        return self.data[y1][x1] - self.data[y-1][x1] - self.data[y1][x-1] + self.data[y-1][x-1]

cs = CumulativeSum2d(square)

"""
xxxxxx
xxxxxx
xxxxxx
xxxxxx
xxxxxx
xxxxxx

oxxxoo
oxxxoo
oxxxoo
xoooxx
xoooxx
xoooxx

0xxxoo
x000xx
x000xx
x000xx
0xxxoo
0xxxoo

xoooxx
oxxxoo
oxxxoo
oxxxoo
xoooxx
xoooxx

1 k  2k
xxxooo
xxxooo
xxxooo
000xxx
000xxx
000xxx

          1xk  2k
         10xxxoo
         yx000xx
         kx000xx
          x000xx
          0xxxoo
        2k0xxxoo

left top position determine everything
"""
ans = 0
# for x in range(1,k*2+1):
#     for y in range(1,k*2+1):
#         sumd = 0
#         ## main area
#         # center_area
#         sumd += cs.query(x, y, min(k*2, x+k-1), min(k*2, y+k-1))
#         if x-k>1:
#             # left_area
#             sumd += cs.query(1, y, x-k-1, min(k*2, y+k-1))
#         if y-k>1:
#             # top_area
#             sumd += cs.query(x, 1, min(k*2, x+k-1), y-k-1)
#         if x>1 and y>1:
#             # left_top_area
#             sumd += cs.query(max(1, x-k), max(1, y-k), x-1, y-1)
#         if x>1 and y-k<1:
#             # left_bottom_area
#             sumd += cs.query(max(1, x-k), y+k, x-1, k*2)
#         if x-k<1 and y>1:
#             # right_top_area
#             sumd += cs.query(x+k, max(1, y-k), k*2, y-1)
#         if x-k<1 and y-k<1:
#             # right_bottom_area
#             sumd += cs.query(x+k, y+k, k*2, k*2)

#         ans = max(sumd, ans)

s = cs.data
for y in range(k, k*2+1):
    for x in range(k, k*2+1):
        d = cs.query(x-k+1, y-k+1, x, y)
        d += s[y-k][x-k]
        d += s[k*2][x-k] - s[y][x-k]
        d += s[y-k][k*2] - s[y-k][x]
        d += cs.query(x+1,y+1,k*2,k*2)
        ans = max(ans, d, n-d)

print(ans , flush=True)


Measured memory_bytes: 139284
#include <stdio.h>
#define N 8
#define NOT_FREE 1
#define FREE -1
void putQueen(int);
void printBoard(void);
int row[N],col[N],dpos[2*N-1],dneg[2*N-1],A[N][N];
int main ()
{
  int i,j,n,b,c;
  scanf("%d",&n);
  
  for(i=0;i<N;i++)
    {
      row[i]=col[i]=FREE;
      for(j=0;j<N;j++)
	{
	  A[i][j]=0;
	}
    }
  for(i=0;i<2*N-1;i++)
    {
      dpos[i]=dneg[i]=FREE;
    }
  for(i=0;i<n;i++)
    {
      scanf("%d%d",&b,&c);
      A[b][c]=2;
    }
  putQueen(0);
  return 0;
}

void putQueen(int i)
{
  int j;
  if(i==N)
    {
      printBoard();
      return;
    }
  
  for(j=0;j<N;j++)
    {
      if(col[j]==NOT_FREE||dpos[i+j]==NOT_FREE||dneg[i-j+N-1]==NOT_FREE) continue;
      
      row[i]=j;
      col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
      putQueen(i+1);
      col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
    }
}

void printBoard(void)
{
  int i,j;
  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  if(A[i][j])
	    {
	      if(row[i]!=j) return;
	    }
	}
    }
  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  if(row[i]==j) printf("Q");
	  else printf(".");
	}
      printf("\n");
    }
}

Measured memory_bytes: 572
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
int main(void){
    int n,m,i,j,a,b,y,t,c,ans,tmp;
    double p;
    m=in();
    while(m--){
        a=in();
        y=in();
        n=in();
        ans=0;
        rep(i,n){
            t=in();
            p=din();
            c=in();
            b=0;
            tmp=a;
            rep(j,y){
                if(t){
                    b=(int)(double)tmp*p;
                    tmp=tmp+b-c;
                }
                else{
                    b+=(int)(double)tmp*p;
                    tmp-=c;
                }
            }
            if(!t)tmp+=b;
            ans=max(ans,tmp);
        }
        print(ans);
    }
    return 0;
}



Measured memory_bytes: 2052
n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=[]
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
#define PI 3.14159265358979323846
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int a,b,h,m;
	cin>>a>>b>>h>>m;
	double min=(double)m*6;
	double hou=(double)h*30+m*(0.500000);
	// double mind= min*3.14159/180;
	  double minc,mins;
	  minc=cos ( min * PI / 180.0 );
	  mins=sin(min * PI / 180.0);
	  //cout<<minc<<" "<<mins<<endl;
	  double houc= cos ( hou * PI / 180.0 );
	  double hous;
	  //houc=cos(houd);
	  hous=sin(hou * PI / 180.0);
	//  cout<<hou<<endl;
	  //cout<<ps(houc,5)<<" "<<hous<<endl;
	  double x1,y1;
	  x1=a*houc; y1=a*hous;
	  double x2,y2;
	  x2=b*minc;  y2=b*mins;
	  //cout<<x1<<" "<<y1<<endl;
	  //cout<<x2<<" "<<y2<<endl;
	  double ans=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	  ans=sqrt(ans);
	  cout<<ps(ans,16)<<endl;

	return 0;
}

Measured memory_bytes: 3992
def sol():
    n=int(input())
    w=[[] for i in range(n)]
    for i in range(n):
        a=int(input())
        for j in range(a):
            x,y=map(int,input().split())
            w[i].append((x,y))
    #print(w)
    ans=0
    for i in range(1<<n):
        x="0"*15+bin(i)[2:]
        x=x[-n:]
        f=1
        z=list(x)
        f=1
        for p,q in enumerate(w):
            #print(p,q)
            #break
            if z[p]=='1':
                for r in q:
                    if (x[r[0]-1]=='1' and r[1]==1) or (x[r[0]-1]=='0' and r[1]==0):
                        pass
                    else:
                        f=0
        if f:
            ans=max(ans,z.count('1'))
    print(ans)

if __name__=="__main__":
    sol()


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

using namespace std;

int main() {
  // input
  int n,l;
  cin >> n >> l;
  vector<string> word(n);
  for (int i=0; i<n; i++) cin >> word[i]; 

  // solve
  sort(word.begin(), word.end());
  string ans;
  for (int i=0; i<n; i++){
    ans += word[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
int n;
vector<int> t(N),v(N);

bool canUp(double speed,int i,int j){
  if(speed > v[i]) return 0;
  for(int k=j+1;k<t[i];k++) speed--;
  
  for(++i;i<n;i++)
    for(int j=0;j<t[i];j++)
      if(speed-- > v[i]) return 0;
  return speed <= 0;
  
}

double calc(double v0,double a,double t){return v0*t + a*t*t/2.0;}

signed main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>t[i];
  for(int i=0;i<n;i++) cin>>v[i];
  
  
  double dis = 0,speed = 0;
  int sum = 0;
  for(int i=0;i<n;i++)
    for(int j=0;j<t[i];j++){
      string a;
      if(canUp(speed+1,i,j)) dis += calc(speed++,1,1),a = "up";
      else if(!canUp(speed,i,j)) dis += calc(speed--,-1,1), a = "down";
      else if(speed < v[i])dis += calc(speed,1,0.5) + calc(speed+0.5,-1,0.5),a="up->down";
      else dis += calc(speed,0,1), a = "not change";
      //cout<<sum++<<" speed="<<speed<<" dis="<<dis<<" "<<a<<endl;
    }
  printf("%Lf\n",dis);
  
  return 0;
}


Measured memory_bytes: 1920
def main():
  import sys
  n=int(input())
  h=map(int,sys.stdin.readline().split())
  g=list(h)[::-1]
  j=g[0]
  for i in g:
    if i>j+1:
      print("No")
      exit()
    elif i==j+1:
      pass
    else:
      j=i
  print("Yes")
  
if __name__=="__main__":
  main()

Measured memory_bytes: 14168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int n; cin >> n ;
	string s; cin >> s;
	char now = s[0];
	int ans = 1;
	rep2(i,1,n){
		if(now!=s[i]){
			ans++;
			now = s[i];
		}
	}
	out(ans);
}




Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		// abc155_a();
		abc155_b();

	}

	static void abc155_a() {

		Scanner sc = new Scanner(System.in);
		// 数値
		int n1 = sc.nextInt();
		int n2 = sc.nextInt();
		int n3 = sc.nextInt();

		if ((n1 == n2 && n2 == n3) || (n1 != n2 && n1 != n3 && n2 != n3)) {

			System.out.println("No");
		} else {
			System.out.println("Yes");
		}

	}

	static void abc155_b() {

		Scanner sc = new Scanner(System.in);
		// 数値
		int n1 = sc.nextInt();
		boolean flg = false;
		for (int i = 1; i <= n1; i++) {
			int n = sc.nextInt();
			if (n % 2 == 0) {
				if (!(n % 3 == 0 || n % 5 == 0)) {
					flg = true;
					break;
				}
			}
		}

		if (flg) {
			System.out.println("DENIED");
		} else {
			System.out.println("APPROVED");
		}

		//

	}
}


Measured memory_bytes: 23764
#include<cstdio>
using namespace std;
int main(){
  char s[3][11];
  for(int i=0;i<3;i++)
    scanf("%s",s[i]);
  printf("%c%c%c\n",s[0][0]-'a'+'A',s[1][0]-'a'+'A',s[2][0]-'a'+'A');
}

Measured memory_bytes: 128
//arc059_c.cpp
//Fri Nov  2 22:35:31 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

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

	int ans = INTINF;
	for (int i=-100;i<=100;i++){
		int temp = 0;
		for (int j=0;j<n;j++){
			temp += (i-a[j])*(i-a[j]);
		}
		if (temp < ans){
			ans = temp;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256