akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("First");}else{puts("Second");}
#define MAX_N 200005

// long version
long long int GCD(long long int x, long long int y){
    if(x == 0 && y == 0) return 0;
    if(x>y){
        long long int swap = x;
        x = y;
        y = swap;
    }
    while(true){
        if(y%x==0){
            return x;
        }else{
            long long int amari = y%x;
            y = x;
            x = amari;
        }
    }
}

int main() {
    ll n;
    cin >> n;
    ll a[n];
    rep(i,n){
        cin >> a[i];
    }
    int loop = 0;
    while(true){
        ll sum = 0;
        rep(i,n){
            sum += a[i];
        }
        if(n == 1){
            if(n%2==0)yn;
            return 0;
        }
        if(n == 2){
            if(sum%2==1)yn;
            return 0;
        }
        ll flag = (sum - n) % 2;
        int odd = 0;
        rep(i,n)odd += a[i]%2;
        if(odd>=2){
            if((flag+loop)%2) yn;
            return 0;
        }
        if(odd == 0){
            if(flag==0){
                if(loop)yn;
                return 0;
            }
            rep(i,n){
                if(a[i]==2){
                    if((loop+1)%2)yn;
                    return 0;
                }
            }
            a[0]--;
        }
        if(odd == 1){
            if(flag){
                if((loop+1)%2)yn;
                return 0;
            }
            rep(i,n){
                if(a[i]%2==1){
                    if(a[i]==1){
                        if(loop)yn;
                        return 0;
                    }
                    a[i]--;
                }
            }
            int g = a[0];
            srep(i,1,n){
                g = GCD(g,a[i]);
            }
            rep(i,n){
                a[i] /= g;
            }
        }
        loop = (loop+1)%2;
    }
    return 0;
}




Measured memory_bytes: 4428
data_list = list()
while True:
    data = list(map(int,input().split()))
    if data == [0,0]:
        break
    data_list.append(data)

for data in data_list:
    cnt = 0
    for a in range(1,data[0]):
        for b in range(a+1,data[0]):
            c = data[1] - a - b
            if c > 0 and c != a and c != b and c > b and c < data[0]+1:
                cnt += 1
    print(cnt)



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

int n, m, q, a[55], b[55], c[55], d[55], A[15], ans;


void dfs(const int now, const int lim) {
    if(now == n + 1) {
        int res = 0;
        for(int i = 1; i <= q; ++ i)
            if(A[b[i]] - A[a[i]] == c[i]) res += d[i];
        ans = max(ans, res);
        return;
    }
    for(int i = lim; i <= m; ++ i)
        A[now] = i, dfs(now + 1, i);
}

int main() {
    cin>>n>>m>>q;
    for(int i = 1; i <= q; ++ i) cin>>a[i]>>b[i]>>c[i]>>d[i];
    dfs(1, 1);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3760
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll a, b;
    cin >> a >> b;
    cout << a * b;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define BUF (100005)
#define INF (1000000005)
typedef long long ll;


int N,Q,K;
int a[BUF];
int b[BUF];
ll c[BUF];

typedef struct {
	int a;
	int b;
	ll  c;
} LIST;

typedef struct {
	int to;
	ll cst;
} EDGE;

typedef struct {
	int x;
	int y;
} QUERY;

LIST l[2*BUF];
QUERY q[BUF];
vector<EDGE> v[BUF];

void input(void){
	cin >> N;
	for(int i=0; i<N-1;i++){
		int a,b,c;
		cin >> a >> b >> c;
		EDGE tmp;
		tmp.to = b;
		tmp.cst =c;
		v[a].push_back(tmp);
		tmp.to = a;
		v[b].push_back(tmp);
	}
	cin >> Q >> K;

	for(int i=0;i<Q;i++) cin >> q[i].x >> q[i].y ;
}

ll  cs[BUF];

void dfs(int k,ll p){
	if(cs[k]!=INF) return ;
	cs[k] = p;

	if(v[k].size()==0){
		return;
	}
	for (vector<EDGE>::const_iterator i = v[k].begin ();i != v[k].end (); i++){ 
	//	cout << i->to << " " << i->cst << endl;
		dfs( i->to , p+ (ll)i->cst );
	}
	return;	
}

int main(void){
	input();

	for(int i=0;i<=N;i++) cs[i]=INF;

	dfs(K,0);

//	for(int i=1;i<=N;i++) cout << cs[i] << endl;

	for(int i=0;i<Q;i++){
		cout << cs[q[i].x]+cs[q[i].y] << endl;
	}

	return 0;
}

Measured memory_bytes: 13696
#include <iostream>
#include <vector>
#include <set>
#include <functional>
#include <algorithm>
#include <cmath>
#define REP(i,N) for(int i=0;i<N;i++)
using namespace std;
using vi=vector<int>;

int main() {
	int n[5] = { 0 };
	for (int i = 0; i < 6; i++) {
		int x; cin >> x;
		n[x]++;
	}

	for (int i = 1; i < 5; i++) {
		if (n[i] == 0) { cout << "NO"; return 0; }
		if (n[i] == 3) { cout << "NO"; return 0; }

	}
	cout << "YES"; return 0;
}

Measured memory_bytes: 256
def solve(n, t, t_list):
    total = t
    prev = t_list[0]
    for i in t_list[1:]:
        total += min(t, (i - prev))
        prev = i
    return total

if __name__ == "__main__":
    n, t = [int(i) for i in input().split()]
    t_list = [int(i) for i in input().split()]
    print(solve(n, t, t_list))


Measured memory_bytes: 25196
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;


int main(){

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

	int L[n],length = 0;

	for(int i=0; i < n; i++){
		scanf("%d",&tmp);

		if(i == 0){
			L[0] = tmp;
		}else{
			if(L[length] < tmp){
				length++;
				L[length] = tmp;
			}else{
				for(int k = 0; k <= length; k++){
					if(L[k] >= tmp){
						L[k] = tmp;
						break;
					}
				}
			}
		}
	}

	printf("%d\n",length+1);

    return 0;
}

Measured memory_bytes: 3052
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int x = n / 100;
    n %= 100;
    if(n<=x*5){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int s = 0, g = n - 1;
    string info;
    cout << n - 1 << "\n";
    cout.flush();
    cin >> info;
    if(info == "Vacant"){
        return 0;
    }
    while(true){
        int mid = (s + g) / 2;
        cout << mid << "\n";
        cout.flush();
        string res;
        cin >> res;
        if(res == "Vacant"){
            return 0;
        }
        if(res == info && mid % 2 == (n - 1) % 2){
            g = mid;
        }else if(res != info && mid % 2 != (n - 1) % 2){
            g = mid;
        }else{
            s = mid;
        }
    }
}

Measured memory_bytes: 852
#include<stdio.h>
int x;
int d[11];
int i,j;
int main(){
	while(scanf("%d,",&x)!=EOF){
		d[0]=0;
		d[1]=d[0]+x;
		for(i=0;i<9;i++){
			scanf("%d,",&x);
			d[i+2]=d[i+1]+x;
		}
		int v1,v2;
		scanf("%d,%d",&v1,&v2);
		double p;
		int ans;
		p=(double)(d[10]*v1)/(v1+v2);
		for(i=0;i<10;i++){
			if(p>d[i]&&p<=d[i+1]){
				ans=i;
				break;
			}
		}
		printf("%d\n",ans+1);
	}
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

ll mm[10010];
int n;
vector<int> a,b;

int main(){
  int h;
  cin >> h >> n;
  a.resize(n);
  b.resize(n);
  for(int i = 0; i < n; ++i)cin >> a[i] >> b[i];
  Fill(mm, 1001001001);
  mm[h] = 0;
  for(int j = h; j >= 0; --j){
    for(int i = 0; i < n; ++i){
      ChangeMin(mm[max(0,j-a[i])], mm[j] + b[i]);
    }
  }
  cout << mm[0] << endl;
  return 0;
}


Measured memory_bytes: 384
from collections import deque
s = input()
n = int(input())
d = deque(s)

now_reverse = False

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    d.append(c)
  elif f == '1' and not now_reverse:
    d.appendleft(c)
  elif f == '2' and now_reverse:
    d.appendleft(c)
  else:
    d.append(c)
  
if now_reverse:
  d = reversed(list(d))
else:
  d =list(d)

for c in d:
  print(c,end='')
print()

Measured memory_bytes: 8688
#include<stdio.h>
#define N 200

int main(void){
  int n, i, j, u, k, c, A[N][N];

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);

    for(j=0; j<k; j++){
      scanf("%d", &c);
      A[u-1][c-1] = 1;
    }
    
  }
  
  for(i=0; i<n; i++){
    
    for(j=0; j <n; j++){
      printf("%d", A[i][j]);
  if(j < n-1)printf(" ");
  
    }

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

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

using namespace std;

#define FAST_IO ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
typedef long long ll;
 
int main(){ 
	
	FAST_IO;
   
	ll n,W;
	cin>>n>>W;

	ll w[n],v[n];
	for(ll i=0; i<n; i++){
		cin>>w[i]>>v[i];
	}

	ll dp[n+1][W+1] ={0};

	for(ll i=0; i<=n; i++){
		for(ll j=0; j<=W; j++){
			if(i==0 || j==0)
				dp[i][j] = 0;
			else if(w[i-1]>j)
				dp[i][j] = dp[i-1][j];
			else
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
		}
	}

	/*
	for(ll i=0; i<=n; i++){
		for(ll j=0; j<=W; j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	*/	

	cout<<dp[n][W]<<endl;
}
 

Measured memory_bytes: 79232
package main
import "fmt"
func main() {
  var s string
  fmt.Scan(&s)
  var l,r,k int = 0,len(s)-1,0
  for l < r {
    if s[l:l+1] == s[r:r+1] {
      l++
      r--
      continue
    }
    if s[l:l+1] == "x" {
      l++
      k++
      continue
    }
    if s[r:r+1] == "x" {
      r--
      k++
      continue
    }
    fmt.Println(-1)
    return
  }
  fmt.Println(k)
}

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

int main()
{
    int r;

    scanf("%d", &r);

    if( r < 1200 ) puts("ABC");
    else if( 1200 <= r && r < 2800 ) puts("ARC");
    else puts("AGC");

    return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())

A = []
for i in range(N):
    a, b = map(int, input().split())
    A.append((a, b))

A.sort(key = lambda x: x[0])
num = M
idx = 0
ans = 0
while num != 0:
    n = min(num, A[idx][1])
    ans += n * A[idx][0]
    num -= n
    idx += 1

print(ans)


Measured memory_bytes: 18184
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    for(int i = 0; i < n; i++) {
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;

    int id;
    for(id = 0; id < n; id++) {
        if(s[id] == x) {
            break;
        }
    }
    int ans = 0;
    for(int i = id + 1; i < n; i++) {
        if(i >= n) {
            break;
        }
        ans += t[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 5e5 + 10;
const ll mod = 1e9 + 7;

ll fact[N], inv[N];

ll Pow(ll a, ll b){
    ll res = 1;
    for (; b; b = b >> 1)
        res = res * (b & 1 ? a : 1) % mod, a = a * a % mod;
    return res;
}

ll C(ll n, ll m){
    if (m < 0 || n < m)
        return 0;
    return fact[n] * inv[m] % mod * inv[n - m] % mod;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, m;
    cin >> n >> m;
    fact[0] = inv[0] = 1;
    for (ll i = 1; i < N; i ++)
        fact[i] = fact[i - 1] * i % mod, inv[i] = Pow(fact[i], mod - 2);
    ll ans = 0;
    for (ll i = 0; i <= n; i ++)
        ans = (ans + 1LL * (i & 1 ? -1 : 1) * C(n, i) * C(m, i) % mod * fact[i] % mod * C(m - i, n - i) % mod * C(m - i, n - i) % mod * fact[n - i] % mod * fact[n - i] % mod) % mod;
    ans = (ans + mod) % mod;
    cout << ans;
    return 0;
}


Measured memory_bytes: 11384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		if(i%3!=0&&i%5!=0)ans+=i;
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int s;
  cin >> s;
  vi dp(s + 1);
  dp[0] = 1;
  for(int i = 3; i <= s; i++){
    rep(j, i - 2){
      dp[i] += dp[j];
      dp[i] %= mod;
    }
  }
  cout << dp[s] << endl;
}//むずかった

Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>

int main(void)
{
    int n, i;
    float x[100], y[100];
    float abs[100];
    double p[4] = {0, 0, 0, 0};
    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%f", &x[i]);
    }
    for(i = 0; i < n; i++){
        scanf("%f", &y[i]);
        abs[i] = sqrt(pow(x[i] - y[i], 2));
    }
    
    for(i = 0; i < n; i++){
        p[0] += abs[i];
    }

    for(i = 0; i < n; i++){
        p[1] += pow(abs[i], 2);
    }
    p[1] = sqrt(p[1]);

    for(i = 0; i < n; i++){
        p[2] += pow(abs[i], 3);
    }
    p[2] = pow(p[2], (1.0 / 3.0));

    p[3] = abs[0];
    for(i = 0; i < n; i++){
        if(abs[i] > p[3])    p[3] = abs[i];
    }

    for(i = 0; i < 4; i++){
        printf("%lf\n", p[i]);
    }

    return (0);
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N; 

    vector<string> W(N);
    REP(i, N){
        cin >> W[i];
    }

    for(ll i=1; i<N; i++){
        ll last = W[i-1].length();
        if(W[i][0] != W[i-1][last-1]){
            cout << "No" << endl;
            return 0;
        }
    }

    map<string, ll> T;

    REP(i, N){
        if(T.count(W[i])){
            cout << "No" << endl;
            return 0;
        }
        T[W[i]]++;
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main(){
    int n;cin>>n;
    ll ans=0;
    int count=0;
    ll MIN=10000000000;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        ans+=abs(a[i]);
        MIN=min(MIN,abs(a[i]));
        if(a[i]<0) count++;
    }
    if(count%2==0) cout<<ans<<endl;
    else cout<<ans-MIN*2<<endl;
}

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


int main() {
    int n;
    cin >> n;
    vector<int> L(n);
    rep(i,n) cin >> L[i];
    sort(L.begin(), L.end());
    ll ans = 0;
    for (int b = 0; b < n; b++) {
        for (int a = 0; a < b; a++) {
            int ab = L[a]+L[b];
            int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
            int l = b + 1;
            ans += r-l;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

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

	cout << (n-1)*(m-1) << endl;
	return 0;
}

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

int main(){
  int i,j,num;
  int judge=1;
  int count=0;

  scanf("%d",&num);
  int A[num];

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

  for(i=0; i<num; i++){
    judge = 0;
    //printf("\n");
    if(A[i]==2) {
      judge=0;
    }

    else if(A[i]%2==0) judge=1;

    else if(A[i]%2!=0){
      for(j=3; j<=sqrt(A[i]); j+=2){
        if(A[i]%j==0){
        judge = 1;
        break;
        }
      }
    }

    if(judge==0) count++;


  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2144
#include <stdio.h>

main(void){

int n;
int c = 0;
int max = 0;
int q=0;
int sum=0;
scanf("%d",&n);
int L[10];
while(c != n){

scanf("%d",&L[c]);
c++;

}

for(int s=0;s < n;s++){
	if(max<L[s]){
		max=L[s];
		q=s;
	}
}
for(int s=0;s < n;s++){
	if(s!=q){
		sum+=L[s];
	}
}

if(max<sum){
	printf("Yes\n");
}else{
	printf("No\n");
	}
}

Measured memory_bytes: 128
x,k,d=map(int,input().split())
if k*d<abs(x):
    print(abs(x)-k*d)
    exit()
n=abs(x)-abs(x)//d*d # 残りの距離
m=k-abs(x)//d  # 余った回数
if m%2==0:
    print(n)
else:
    print(abs(n-d))


Measured memory_bytes: 9180
#include<stdio.h>

 main() 
{
int n,m,i,j;
int a[101][101];
int b[101];
int c[101];

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


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

for(j=0;j<m;j++){
                 scanf("%d",&b[j]);
                 }
  


for(i=0;i<n;i++){
                 c[i]=0;
                 for(j=0;j<m;j++){
                                 c[i]+=a[i][j]*b[j];
                                  }
                 }

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




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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 1;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll dp[410][410];
ll sum[410];
ll a[410];

ll rec(ll l,ll r){
	//範囲[l,r)のコスト
	if(dp[l][r]!=-1) return dp[l][r];
	if(l+1==r) return dp[l][r]=0;
	
	ll ret=INF;
	rep(i,l+1,r){
		chmin(ret, rec(l,i) + rec(i,r));
	}
	ret+=sum[r]-sum[l];
	return dp[l][r]=ret;
}

void solve(){
	ll n;
	cin>>n;
	REP(i,n) cin>>a[i];
	memset(dp,-1,sizeof(dp));
	REP(i,n) sum[i+1]=sum[i]+a[i];
	cout<<rec(0,n)<<en;
}

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

    solve();
    return 0;
}

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

int main()
{
    #define int long long int
	int n,flag=1,t1,t2,minm=INT_MAX,t=0,p=0;
	vector<int>v;
	cin>>n;

    
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            if (n/i == i) v.push_back(i);  
            else {v.push_back(i);v.push_back(n/i);}
        } 
    } 
 
	int s=v.size();
	for(int i=0;i<s;i++)
    {
        for(int j=0;j<s;j++)
        {
         if(v[i]*v[j]==n){t1=v[i];t2=v[j];}
         if(t1-t2<minm){minm=fabs(t1-t2);t=t1;p=t2;}


        }
    }
      cout<<(t-1)+(p-1)<<endl;
	return 0;
}


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

using namespace std;

#define all(x) begin(x), end(x)

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

struct modint {
    static constexpr int MOD = 998244353;
    int v;

    bool operator==(const modint& other) const {
        return v == other.v;
    }

    modint& operator+=(const modint& other) {
        v += other.v;
        if (v >= MOD)
            v -= MOD;
        return *this;
    }

    modint& operator-=(const modint& other) {
        v -= other.v;
        if (v < 0)
            v += MOD;
        return *this;
    }

    modint& operator*=(const modint& other) {
        v = 1LL * v * other.v % MOD;
        return *this;
    }

    modint& operator/=(const modint& other) {
        *this *= other.inv();
        return *this;
    }

    modint operator+(const modint& other) const {
        return modint { v } += other;
    }

    modint operator-(const modint& other) const {
        return modint { v } -= other;
    }

    modint operator*(const modint& other) const {
        return modint { v } *= other;
    }

    modint operator/(const modint& other) const {
        return modint { v } /= other;
    }

    static modint pow(modint b, ll e) {
        modint res { 1 };
        for (ll p = 1; p <= e; p <<= 1) {
            if (p & e)
                res *= b;
            b *= b;
        }

        return res;
    }

    modint pow(ll e) const {
        return pow(*this, e);
    }

    modint inv() const {
        return pow(MOD - 2);
    }

    friend ostream& operator<<(ostream& os, modint m) {
        return os << m.v;
    }
};

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

    int n;
    cin >> n;

    modint ans = modint::pow(modint { 3 }, n);
    modint cur = { 0 };
    modint term = { 1 };
    modint p = { 2 };
    // n choose k * 2^k for k in range()
    for (int k = n; k > n / 2; --k) {
        cur += term * p;
        // going from n!/k!(n-k)! to n!/(k-1)!(n-k+1)!
        // multiply by k/(n-k+1)
        term /= modint { n - k + 1 };
        term *= modint { k };
        p += p;
    }

    cout << ans - cur << '\n';
 
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#define int long long
#define iris 1000000007
using namespace std;

int arr[100010];
int aoi[100010]={1};

inline int sana(int a)
{
	int res=1,b=iris-2;
	while(b)
	{
		if(b&1)
			res=(res*a)%iris;
		a=(a*a)%iris;
		b>>=1;
	}
	return res;
}

inline int akari(int n,int m)
{
	int res=aoi[n]*sana(aoi[m])%iris;
	res=res*sana(aoi[n-m])%iris;
	return res;
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n,m,i,j,k,ans=0;
	cin>>n>>k;
	
	for(i=1;i<=n;i++)
	{
		aoi[i]=(aoi[i-1]*i)%iris;
	}
	
	for(i=1;i<=n;i++)
	{
		cin>>arr[i];
	}
	sort(arr+1,arr+n+1);
	
	for(i=k;i<=n;i++)
	{
		ans+=(akari(i-1,k-1)*((arr[i]+iris)%iris)%iris);
		ans%=iris;
	}
	
	for(i=1;i<=n-k+1;i++)
	{
		ans-=(akari(n-i,k-1)*((arr[i]+iris)%iris)%iris);
		ans=(ans+iris)%iris;
	}
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 1792
N = int(input())
numbers = list(map(int,input().split()))
numOfOperation = int(input())
dic = {}

for num in numbers:
    if num in dic : dic[num] += 1
    else: dic[num] = 1
    

sums = sum(numbers)
for i in range(numOfOperation):
    B,C = map(int,input().split())
    if (B in dic) : 
        cnt = dic[B]
        dic[B] = 0
        if (C not in dic) : dic[C] = cnt
        else : dic[C] += cnt
        sums += cnt * (C - B)
    print(sums)


Measured memory_bytes: 20728
#include<iostream>

using namespace std;

int A[1000000];
int cnt=0;

void insertionSort(int *A, int n, int g) {
	for(int i=g; i<n; i++) {
		int v=A[i];
		int j=i-g;
		while(j>=0 && A[j]>v) {
			A[j+g] = A[j];
			j-=g;
			cnt++;
		}
		A[j+g]=v;
	}
}

void shellSort(int *A, int n) {
	int m;
	static const int G[] = {1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161, 2391484};
	for(m=1; G[m]<n; m++);
	
	for(int i=m-1; i>=0; i--) {
		insertionSort(A, n, G[i]);
	}
	cout<<m<<'\n'<<G[m-1];
	for(int i=m-2; i>=0; i--) cout<<' '<<G[i];
	cout<<'\n';
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, A[1000000];
	cin>>n;
	for(int i=0; i<n; i++) cin>>A[i];
	shellSort(A, n);
	cout<<cnt<<'\n';
	for(int i=0; i<n; i++) cout<<A[i]<<'\n';
	return 0;
}



Measured memory_bytes: 7112
#include <bits/stdc++.h>
#define IO std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
#define FIN freopen("entrada.txt", "r", stdin);
#define FOUT freopen("saida.sol", "w", stdout);

#define MOD 1000000007
#define ull unsigned long long int
#define ll  long long int
#define pii pair<int, int>
#define pb push_back
#define MAX int(10e5+2)

const int INF = 0x3f3f3f3f;
using namespace std;

string a, b;
bool solve() {
   for(int i=0; i<a.size(); i++)
      if(a[i]!=b[i] || a.size()>b.size())
         return false;
   return true;
}

int main() {

   //IO

   cin >> a >> b;

   puts(solve() ? "Yes" : "No");

   return 0;
}


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


using namespace std;

int a[200001] = {};
long long b[200001] = {};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, q, s, t;
  cin >> n >> q >> s >> t;
  for(int i = 0; i < n + 1; i++){
    cin >> a[i];
  }
  long long add = 0, behind = 0;
  for(int i = 0; i < n; i++){
    b[i] = a[i + 1] - a[i];
    if(b[i] > 0){
      add += b[i];
    }
    else{
      behind -= b[i];
    }
  }
  
  for(int i = 0; i < q; i++){
    int l, r, x;
    cin >> l >> r >> x;
    if(b[l - 1] <= 0){
      if(b[l - 1] + x >= 0){
        add += b[l - 1] + x;
        behind += b[l - 1];
      }
      else{
        behind -= x;
      }
    }
    else{
      if(b[l - 1] + x <= 0){
        add -= b[l - 1];
        behind -= b[l - 1] + x;
      }
      else{
        add += x;
      }
    }
    b[l - 1] += x;
    if(b[r] <= 0){
      if(b[r] - x >= 0){
        if(r < n){
          add += b[r] - x;
          behind += b[r];
        }
      }
      else{
        if(r < n){
          behind += x;
        }
      }
    }
    else{
      if(b[r] - x <= 0){
        if(r < n){
          add -= b[r];
          behind -= b[r] - x;
        }
      }
      else{
        if(r < n){
          add -= x;
        }
      }
    }
    b[r] -= x;
    int now = 0;
    long long ans = behind * t - add * s;
    cout << ans << "\n"; 
  }
}

Measured memory_bytes: 5512
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<cmath>

const int INF = 1 << 30;

int l;
std::string s;	
double d[12][12], dp[1 << 12][12];

int main()
{
	while( std::getline( std::cin, s ) )
	{
		for( int S = 0; S < 1 << 12; ++S )
				std::fill( dp[S], dp[S] + 12, INF );

		std::istringstream iss( s );

		iss >> l;

		int r;
		std::vector<int> rs;

		while( iss >> r )
			rs.push_back( r );

		int n = rs.size();

		for( int i = 0; i != n; ++i )
			for( int j = 0; j != n; ++j )
				d[i][j] = 2 * sqrt( rs[i] * rs[j] );

		double ans = INF;

		for( int i = 0; i != n; ++i )
			dp[( 1 << n ) - 1 - ( 1 << i )][i] = rs[i];
			
		for( int S = ( 1 << n ) - 2; S >= 0; --S )
			for( int v = 0; v != n; ++v )
				if( !( S >> v & 1 ) )
					for( int u = 0; u != n; ++u )
						dp[S][v] = std::min( dp[S][v], dp[S | ( 1 << v )][u] + d[v][u] );

		for( int j = 0; j != n; ++j )
			ans = std::min( ans, dp[0][j] + rs[j] );

		if( ans <= l )
			std::cout << "OK" << std::endl;
		else
			std::cout << "NA" << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1616
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  writeln(n < 1000 ? "ABC" : "ABD");
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = a; i <= b; i++) {
        string s = to_string(i);
        if (s[0] == s[4] && s[1] == s[3]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll H,W;
  cin>>H>>W;
  vector<vector<pair<char,int>>> v = vector<vector<pair<char,int>>> (H+2,vector<pair<char,int>>(W+2,make_pair('#',0)));

  ll x=0;
  string s;
  FOR(i,1,H+1){
    cin>>s;
    FOR(j,1,W+1){
      if(s[j-1]=='.') x++;
      v[i][j].first=s[j-1];
    }
  }

  queue<P> q;
  q.push(P(1,1));
  v[1][1].second = 1;
  ll a,b;
  while(!q.empty()){
    a = q.front().first;
    b = q.front().second;
    q.pop();
    if(v[a+1][b] == make_pair('.',0) ) {
      q.push(P(a+1,b));
      v[a+1][b].second=v[a][b].second+1;
    }
    if(v[a-1][b] == make_pair('.',0) ) {
      q.push(P(a-1,b));
      v[a-1][b].second=v[a][b].second+1;
    }
    if(v[a][b+1] == make_pair('.',0) ) {
      q.push(P(a,b+1));
      v[a][b+1].second=v[a][b].second+1;
    }
    if(v[a][b-1] == make_pair('.',0) ) {
      q.push(P(a,b-1));
      v[a][b-1].second=v[a][b].second+1;
    }
    //cout<<a<<" "<<b<<endl;
  }
  ll res=v[H][W].second;
  if(res==0) res=-1;
  else res=x-res;
  /*
  FOR(i,0,H+2){
    FOR(j,0,W+2){
      cout<<v[i][j].first;
    }
    cout<<endl;
  }
  FOR(i,0,H+2){
    FOR(j,0,W+2){
      cout<<v[i][j].second;
    }
    cout<<endl;
  }*/


  cout<<res<<endl;




}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

//Traveling by Stagecoach
public class Main{

	static double[][] dist;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int p = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			if((n|m|p|a|b)==0)break;
			int[] h = new int[n];
			for(int i=0;i<n;i++)h[i]=sc.nextInt();
			int[][] cost = new int[m+1][m+1];
			while(p--!=0){
				int s = sc.nextInt();
				int t = sc.nextInt();
				int d = sc.nextInt();
				cost[s][t] = cost[t][s] = d;
			}
			dist = new double[m+1][1<<n];
			for(double i[]:dist)Arrays.fill(i, Integer.MAX_VALUE);
			PriorityQueue<int[]> q = new PriorityQueue<int[]>(m+1, new Comparator<int[]>() {
				public int compare(int[] o1, int[] o2) {
					return dist[o1[0]][o1[1]]-dist[o2[0]][o2[1]]<0?-1:dist[o1[0]][o1[1]]-dist[o2[0]][o2[1]]>0?1:0;
				}
			});
			dist[a][(1<<n)-1] = 0;
			q.add(new int[]{a, (1<<n)-1});
			while(!q.isEmpty()){
				int[] v = q.poll();
				if(v[0]==b)break;
				for(int j=0;j<n;j++){
					if((v[1]&(1<<j))==0)continue;
					for(int t=1;t<=m;t++){
						if(cost[v[0]][t]==0)continue;
						double w = dist[v[0]][v[1]] + cost[v[0]][t]*1.0/h[j];
						if(w < dist[t][v[1]-(1<<j)]){
							dist[t][v[1]-(1<<j)] = w;
							q.add(new int[]{t, v[1]-(1<<j)});
						}
					}
				}
			}
			double min = Integer.MAX_VALUE;
			for(int i=0;i<1<<n;i++)min=Math.min(min, dist[b][i]);
			System.out.println(min==Integer.MAX_VALUE?"Impossible":min);
		}
	}
}

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

using namespace std;

typedef long long llint;

const int MAXN = 100005;

int n, d;
llint a[MAXN], lef[MAXN], rig[MAXN];
set <int> st, pos;
vector <int> v;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> d;
    for (int i=1; i<=n; i++) {
        cin >> a[i];
        if (i > 1) {
            pos.insert(i-1);
            lef[i-1] = a[i-1]; rig[i-1] = a[i];
            if (lef[i-1] + rig[i-1] >= d) st.insert(i-1);
        }
    }
    while (!st.empty()) {
        auto it = st.begin();
        v.push_back(*it);
        auto p = pos.find(*it);
        if (p != pos.begin()) {
            p--;
            rig[*p] += rig[*it];
            if (lef[*p] + rig[*p] >= d) st.insert(*p);
        }
        p = pos.find(*it); p++;
        if (p != pos.end()) {
            lef[*p] += lef[*it];
            if (lef[*p] + rig[*p] >= d) st.insert(*p);
        }
        pos.erase(*it);
        st.erase(*it);
    }
    if (v.size() == n-1) {
        cout << "Possible\n";
        for (int i = (int)v.size()-1; i >= 0; i--) {
            cout << v[i] << '\n';
        }
    } else {
        cout << "Impossible";
    }
    return 0;
}


Measured memory_bytes: 12544
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}


long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

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

//ここまでライブラリ
//ここから本文

long long int tpimin(vector<int> a) {
	int MIN = 1000000000;
	int number = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
		number = i;
	}
	return number;
}


int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	if (a > 0) cout << (b / c) - (a - 1) / c << endl; else cout << (b / c) + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long INF = 1LL<<60;
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; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    cout << n * n<< 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)

#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;

const D PI = acos(-1);

int n;
P p[100];

D solve(D theta) {
  vector<D> xx;
  D st = sin(theta), ct = cos(theta);
  rep (i, n) xx.push_back(p[i].X * st + p[i].Y * ct);
  sort(xx.begin(), xx.end());
  D res = 2;
  rep (i, xx.size() - 1) res += min((D)2, xx[i + 1] - xx[i]);
  return res;
}

pair<D, D> solve2(D theta) {
  vector<pair<D, pair<D, D> > > xx;
  D st = sin(theta), ct = cos(theta);
  rep (i, n) xx.push_back(make_pair(p[i].X * st + p[i].Y * ct, make_pair(p[i].X, p[i].Y)));
  sort(xx.begin(), xx.end());
  D sx = 0, sy = 0;
  rep (i, xx.size() - 1) if (xx[i + 1].first - xx[i].first < 2) {
    sx += xx[i].second.first;
    sy += xx[i].second.second;
    sx -= xx[i + 1].second.first;
    sy -= xx[i + 1].second.second;
  }
  return make_pair(solve(atan2(sx, sy)), atan2(sx, sy));
}

int main() {
  while (true) {
    cin >> n;
    if (n == 0) break;
    rep (i, n) {
      D x, y;
      cin >> x >> y;
      p[i] = P(x, y);
    }
    vector<D> t;
    t.push_back(PI);
    t.push_back(0);
    rep (i, n) rep (j, i) {
      D t1 = -arg(p[i] - p[j]);
      D dt = asin((D)2 / abs(p[i] - p[j]));
      t.push_back(t1);
      t.push_back(t1 + dt);
      t.push_back(t1 - dt);
    }
    rep (i, t.size()) while (t[i] < 0) t[i] += PI;
    rep (i, t.size()) while (t[i] > PI) t[i] -= PI;
    sort(t.begin(), t.end());
    D ans = 1e9, theta = -1;
    rep (i, t.size()) {
      D s = solve(t[i]);
      if (s < ans) {
	ans = s;
	theta = t[i];
      }
    }
    rep (i, t.size() - 1) {
      pair<D, D> s = solve2((t[i] + t[i + 1]) / 2);
      if (s.first < ans) {
	ans = s.first;
	theta = s.second;
      }
    }
    while (theta < 0) theta += PI;
    while (theta > PI) theta -= PI;
    cout << fixed << setprecision(15) << theta << endl;
    ans = 0, theta = -1;
    rep (i, t.size()) {
      D s = solve(t[i]);
      if (s > ans) {
	ans = s;
	theta = t[i];
      }
    }
    rep (i, t.size() - 1) {
      pair<D, D> s = solve2((t[i] + t[i + 1]) / 2);
      if (s.first > ans) {
	ans = s.first;
	theta = s.second;
      }
    }
    while (theta < 0) theta += PI;
    while (theta > PI) theta -= PI;
    cout << fixed << setprecision(15) << theta << endl;
  }
}

Measured memory_bytes: 1732
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>

int main(){

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector<int> h(n);
    for(int i = 0 ; i < n ; ++i){
        std::cin >> h[i];
    }

    std::vector<int> dp(n);
    dp[0] = 0;
    dp[1] = std::abs(h[0] - h[1]);

    for(int i = 2 ; i < n ; ++i){
        dp[i] = std::min(std::abs(h[i] - h[i - 1]) + dp[i - 1] , std::abs(h[i] - h[i - 2]) + dp[i - 2]);
    }

    std::cout << dp[n - 1] << '\n';

}

Measured memory_bytes: 1024
n = int(input())
links = {u: {} for u in range(1, n + 1)}
for i in range(n - 1):
	x, y, z = map(int, input().split())
	links[x][y] = z
	links[y][x] = z
vis = [0] * (n + 1)
col = [0] * (n + 1)

now = 0
q = [(1, 0)]
while now < len(q):
	u = q[now][0]
	c = q[now][1]
	now += 1
	vis[u] = 1
	col[u] = c
	for v, l in links[u].items():
		if vis[v] == 0:
			if l & 1:
				q.append((v, c ^ 1))
			else:
				q.append((v, c))

for u in range(1, n + 1):
	print(col[u])

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

int main(){
  int N; cin >> N;
  string s,t; cin >> s >> t;
  int check=0;
  for(int p=0;p<N;p++){
    check=0;
    for(int i=p;i<N;i++){
      if(s[i]!=t[i-p]){
        check=1;
      }
    }
    if(check==0){
      cout << N+p << endl;
      return 0;
    }
  }
  cout << N*2 << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	a, b, c := nextInt(), nextInt(), nextInt()

	if a < b && b < c {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}



Measured memory_bytes: 1188
import sys
input = sys.stdin.readline
import math

N = int(input())
ans = 0

def count_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return len(divisors)

for i in range(1, N+1):
    if i % 2 == 0:
        continue
    if count_divisors(i) == 8:
        ans += 1
print(ans)

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

int main(){
int N;
cin >> N;
vector<int> p(N);
int count = 0;
for (int i = 0; i < N; i++) {
    cin >> p.at(i);
    if (p.at(i) != i + 1) {
        count++;
    }
}
if (count <= 2) {
    cout << "YES" << endl;
} else {
    cout << "NO" << endl;
}
}

Measured memory_bytes: 256
//  ^_^
#include<bits/stdc++.h>
using namespace std;
#define Om ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
const ll mod = 1e9+7;
ll bigMod(ll x, ll n)
{
    ll res = 1LL;
    while(n)
    {
        if(n&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    Om;
    ll n;
    cin>>n;
    ll all = bigMod(10, n)%mod;
    ll extra = bigMod(9, n)%mod;
    ll common = bigMod(8, n)%mod;
    cout<< (all-2LL*extra+common+mod+mod)%mod <<endl;
    return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum[ohara],pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll sei[ohara];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>k;
    rep(i,n)cin>>a[i];

    rep(i,n){
        if(a[i]>0)sei[i+1]=a[i];
        sum[i+1]=a[i];
    }

    rrep(i,1,n+5){
        sei[i]+=sei[i-1];
        sum[i]+=sum[i-1];
    }

    rrep(i,1,n-k+2){
        ans=max(sum[i+k-1]-sum[i-1],0LL);
        ans+=sei[i-1]+sei[n]-sei[i+k-1];
        tmp=max(ans,tmp);
    }
    Cout(tmp);
    return 0;
}


Measured memory_bytes: 9344
import java.util.*;
import java.io.*;
import java.math.*;
class Main{
	static int mod = (int)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
		
		int n = sc.nextInt();
		int ans = (int)Math.pow(n,3);
		System.out.println(ans);
		
		
		
		
		
		
		
		
		out.close();
	}
	
	
	
	
	
	//static HashMap<Integer,Integer> visited = new HashMap<>();
		
	
	/*public static int compute(int root, int n, int m, Tree[] edge, int values[]){
			
			LinkedList<Integer> ll = 	new LinkedList<>();
			ll.add(root);
				
			while(ll.size()>0){
				int val = ll.removeFirst();
				visited.put(val,0);
				ArrayList<Integer> al = edge[val].al;
				int length = al.size();
				for(int i=0;i<length;i++){
					ll.addLast(al.get(i));
					int hold = edge[val].weight+values[root];
					values[al.get(i)] = Math.min(hold,values[al.get(i)]);
				}
			}
			return values[n];
			
	}*/
	
	
	public static class Tree{
		int weight;
		int destination;
	}
	
	
	
	public static int partition(int [] arr, int s, int e){
		
		int index=s;
		int pivot = arr[e];
		for(int i=s;i<=e-1;i++){
			if(arr[i]<=pivot){
				arr = swap(arr, index, i);
				index++;
			}
		}
		swap(arr,index,e);
		print(arr);
		return index;
	}
	
	public static int[] swap(int[] arr, int low, int high){
		int temp = arr[low];
		arr[low]=arr[high];
		arr[high]=temp;
		return arr;
	}
	
	
	public static long gcd(long a, long b){
		if(a==0)
			return b;
		
		return gcd(b%a,a);
	}
	
	public static void print(int[] arr){
		for(int i=0;i<arr.length;i++)
			System.out.print(arr[i]+" ");
		System.out.println();
	}
	
	public static class pair{
		int ai;
		int bi;
	}
	
	public static class comp implements Comparator<pair>{
		public int compare(pair o1, pair o2){
			return o1.bi-o2.bi;
		}
	}
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
}

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str=sc.next();
        int red;
        int blue;
        red=str.length()-str.replaceAll("1", "").length();
        blue=str.length()-str.replaceAll("0", "").length();
        System.out.println(Math.min(red,blue)*2);
        
    }
        
}

Measured memory_bytes: 34920