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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,p[105];
    int ans=0;
    cin >> a;
    rep(i,0,a){
        cin >> p[i];
        ans+=p[i];
    }
    int m;
    cin >> m;
    rep(i,0,m){
        int y,x;
        cin >> y >> x;
        cout << ans-p[y-1]+x << endl;
    }
    return 0;
}




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

pn_num=0
WA_list=[0]*N
AC_list=[0]*N

for _ in range(M):
    pi,Si=input().split()
    pi=int(pi)
        
    if Si=='AC':
        if AC_list[pi-1]==0:
            pn_num+=WA_list[pi-1]
            AC_list[pi-1]=1
    
    else:
        WA_list[pi-1]+=1
    
print(sum(AC_list),pn_num)

Measured memory_bytes: 4596
//https://atcoder.jp/contests/caddi2018b/tasks/caddi2018b_b
//B - AtCoder Alloy
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    ll N,H,W; cin>>N>>H>>W;
    ll ans=0;
    REP(i,N){
        ll a,b; cin>>a>>b;
        if(H<=a&&W<=b)++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())

diff = abs(abs(x) - abs(y))
if x < 0 and y < 0 and x < y:
    print(diff)
    exit()
elif x == y:
    print(diff)
    exit()
elif (x > y and x > 0 and y == 0) or (x > y and x == 0 and y < 0):
    print(diff + 1)
    exit()
elif x > y and x > 0 and y > 0:
    print(diff + 2)
    exit()
elif x == 0 or y == 0:
    print(diff)
    exit()

if x < 0:
    diff += 1
if y < 0:
    diff += 1

print(diff)


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

int main(){
  int N, X;
  cin >> N >> X;
  int m[N];
  int sum = 0;
  for(int i = 0; i < N; i++){
    cin >> m[i];
    sum += m[i];
  }
  int plus = 0;
  sort(m, m + N);
  int Q = X;
  while(1){
    if(m[0] * (plus + 1) + sum > X) break;
    plus++;
  }
  cout << N + plus << endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    cin >> q;
    int lim=1e5+5;
    vector<bool> chk(lim,false);
    for(int i = 3; i < lim; i++) {
        if(i%2==0) continue;
        int n=i;
        int m=(i+1)/2;
        bool flag=true;
        int d=2;
        while(d*d<=n) {
            if(n%d==0) flag=false;
            d++;
        }
        d=2;
        while(d*d<=m) {
            if(m%d==0) flag=false;
            d++;
        }
        if(flag) chk[i]=true;
    }

//    for(int i = 0; i < 10; i++) {
//        cout << i << " " << chk[i] << "\n";
//    }

    vector<int> cnt(lim,0);
    for(int i = 0; i < lim; i++) {
        cnt[i]=cnt[i-1]+chk[i];
    }

    for(int i = 0; i < q; i++) {
        int l,r;
        cin >> l >> r;
        l--;
        cout << cnt[r]-cnt[l] << "\n";
    }

    return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<i64> A(N + 2, 0);
    for(int i = 0; i < N; i++) {
        cin >> A[i + 1];
    }
    i64 S = 0;
    for(int i = 1; i <= N + 1; i++) {
        S += abs(A[i] - A[i - 1]);
    }
    for(int i = 1; i <= N; i++) {
        i64 ans = S - abs(A[i] - A[i - 1]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 10000

int main(){
    int n,i,a[MAX];
    cin>>n;
    long max=-10000001,min=10000000,add=0;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        if(max<a[i]){
            max=a[i];
        }
        if(min>a[i]){
            min=a[i];
        }
        add+=a[i];
    }
    cout<<min<<" "<<max<<" "<<add<<endl;
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    string s, t;
    cin >> s >> t;

    reverse(t.begin(), t.end());

    if (s == t) puts("YES");
    else puts("NO");
}

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

int main(){

  int i,n,sum;
  double a,u;

 
 
  while(1){

 scanf("%d",&n);
 int num[n];
 sum=0;

 if(n==0)
   break;

 for(i=0;i<n;i++){
   scanf("%d",&num[i]);
   sum +=num[i];
 }
 a=(double)sum/n;
 u=0;
 for(i=0;i<n;i++)
   u+=(num[i]-a)*(num[i]-a);  
 
 printf("%f\n", sqrt(u/n));

  }

  return 0;
}

Measured memory_bytes: 1836
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);

typedef vector<double> vd;
const int INF = INT_MAX/2-1;

struct state {
	int p;
	double c;
	state(int p, double c) : p(p), c(c) {};
	bool operator<(const state &o)const {
		return c>o.c;
	}
};

int main() {
	int n;
	while(cin >> n, n) {
		vector<vd> cell(n, vd(4));
		REP(i, n) {
			cin >> cell[i][0] >> cell[i][1] >> cell[i][2] >> cell[i][3];
		}
		
		vector<vd> dist(n, vd(n, INF));
		REP(i, n) {
			FOR(j, i+1, n-1) {
				double d2 = 0;
				REP(k, 3) {
					d2 += (cell[i][k]-cell[j][k])*(cell[i][k]-cell[j][k]);
				}
				double d = sqrt(d2)-cell[i][3]-cell[j][3];
				if(d < EPS) {
					dist[i][j] = dist[j][i] = 0;
				} else {
					dist[i][j] = dist[j][i] = d;
				}
			}
		}

		vi used(n, 0);
		priority_queue<state> Q;
		Q.push(state(0,  0));
		double ans = 0;
		while(!Q.empty()) {
			state st = Q.top();
			Q.pop();
			
			if(used[st.p]) {
				continue;
			}

			used[st.p] = true;
			ans += st.c;

			REP(i, n) {
				if(dist[st.p][i] != INF && st.p != i) {
					Q.push(state(i, dist[st.p][i]));
				}
			}
		}

		printf("%.3f\n", ans);
	}

	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
struct point
{
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll x,a;
    cin>>x>>a;
    if (x<a)
    {
        cout<<"0\n";
    }
    else
    {
        cout<<"10\n";
    }
    
}


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

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <climits>
#include <iomanip>

using namespace std;

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

	if (s == "ABC")cout << "ARC" << endl;

	if (s == "ARC")cout << "ABC" << endl;

	return 0;
}

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

int main(){
    int N, K , X, Y;
    cin >> N >> K >> X >> Y;
    int sum = 0;
    if (N - K > 0){
        sum = K * X + (N - K) * Y;
    }
    else{
        sum = N * X;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
// AOJ 2008: Dragon Fantasy
// 2017.11.22 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <math.h>

int cx[22], cy[22], n;
double dc[22][22], dd[22];

double dist(int x1, int y1, int x2, int y2)
{
	return hypot(x1-x2, y1-y2);
}

int rec(int i, int s, double d)
{
	int j, jj;

	if (s == (1<<n) - 1) return 1;
	for (jj = 1, j = 0; j < n; j++, jj <<= 1) {
		if (s & jj) continue;
		if (dd[j] < d + dc[i][j]) return 0;
	}
	for (jj = 1, j = 0; j < n; j++, jj <<= 1) {
		if (s & jj) continue;
		if (dd[j] > d + dc[i][j] && rec(j, s | jj, d + dc[i][j])) return 1;
	}
	return 0;
}

int main()
{
	int i, j, dx, dy;

	while (scanf("%d%d%d%d%d", &n, cx, cy, &dx, &dy) && n > 0) {
		n++;
		for (i = 1; i < n; i++) scanf("%d%d", cx+i, cy+i);
		for (i = 0; i < n; i++) {
			dd[i] = dist(cx[i], cy[i], dx, dy);
			dc[i][i] = 0;
			for (j = i+1; j < n; j++) {
				dc[i][j] = dc[j][i] = dist(cx[i], cy[i], cx[j], cy[j]);
			}
		}
		puts(rec(0, 0, 0) ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 1756
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int money = scan.nextInt();
        int sum = (money / 500) * 1000 + (money % 500) / 5 * 5;
        System.out.println(sum);    
    }
}


Measured memory_bytes: 22996
n = int(input())
X=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
print(X[n-1])

Measured memory_bytes: 38256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format, std.datetime;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long H, W;
    scan(H, W);
    auto S = new string[](H);
    foreach (i; 0 .. H)
        S[i] = sread();
    long black;
    foreach (i; 0 .. H)
        foreach (j; 0 .. W)
            if (S[i][j] == '#')
                black++;
    DList!(Tuple!(long, long)) Q;
    Q.insert(Tuple!(long, long)(0, 0));
    auto dist = new long[][](H, W);
    foreach (i; 0 .. H)
        foreach (j; 0 .. W)
            dist[i][j] = -1;
    dist[0][0] = 1;
    while (!Q.empty)
    {
        auto t = Q.front;
        Q.removeFront();
        if (S[t[0]][t[1]] == '#')
            continue;
        if (t[0] != 0 && dist[t[0] - 1][t[1]] == -1)
        {
            dist[t[0] - 1][t[1]] = dist[t[0]][t[1]] + 1;
            Q.insert(Tuple!(long, long)(t[0] - 1, t[1]));
        }
        if (t[1] != 0 && dist[t[0]][t[1] - 1] == -1)
        {
            dist[t[0]][t[1] - 1] = dist[t[0]][t[1]] + 1;
            Q.insert(Tuple!(long, long)(t[0], t[1] - 1));
        }
        if (t[0] != H - 1 && dist[t[0] + 1][t[1]] == -1)
        {
            dist[t[0] + 1][t[1]] = dist[t[0]][t[1]] + 1;
            Q.insert(Tuple!(long, long)(t[0] + 1, t[1]));
        }
        if (t[1] != W - 1 && dist[t[0]][t[1] + 1] == -1)
        {
            dist[t[0]][t[1] + 1] = dist[t[0]][t[1]] + 1;
            Q.insert(Tuple!(long, long)(t[0], t[1] + 1));
        }
    }
    if (dist[H - 1][W - 1] == -1)
    {
        writeln(-1);
        return;
    }
    writeln(H * W - dist[H - 1][W - 1] - black);
}


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define fori(i,a,n) for(i=a;i<=n;i++)
#define ford(i,n,a) for(i=n;i>=a;i--)
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
int n;
int main()
{
	cin>>n;
	if (n%10==7||n/100==7||n/10%10==7) puts("Yes");
	else puts("No");
}

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

#define all(a) a.begin(), a.end()
#define ff first
#define ss second
#define pb push_back

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

template<typename T> using V = vector<T>;

// dist(a, b) = D(a) + D(b) - 2 * D(L)
// Traverse the tree using a DFS. For current node store the following values:
// freq_till[i] - denotes the frequency of color i from root till current node
// sum_till[i] - denotes the sum of weights of color i from root till current node

const int MAXN = 1e5 + 10, LOG = log2(MAXN) + 2;

typedef struct {
	int x, y, u, v;
} Query;

vector< pair<int, pii> > adj[MAXN];
vector<int> qry_idx[MAXN];
Query qrs[MAXN];
ll sum_till[MAXN], freq_till[MAXN], ans[MAXN];
int dep[MAXN], up[LOG][MAXN];
int N, Q;

void dfslca(int cur, int par) {
    up[0][cur] = par;
    for (int i = 1; i < LOG; ++i)
        up[i][cur] = up[i - 1][up[i - 1][cur]];

    for (auto nxt : adj[cur]) if (nxt.ff != par) {
        dep[nxt.ff] = dep[cur] + 1;
        dfslca(nxt.ff, cur);
    }
}

int getlca(int u, int v) {
    if (dep[u] > dep[v]) swap(u, v);
    for (int i = LOG - 1; i >= 0; --i)
        if (dep[v] - (1 << i) >= dep[u])
            v = up[i][v];
    if (u == v) return u;
    for (int i = LOG - 1; i >= 0; --i)
        if (up[i][u] != up[i][v])
            u = up[i][u], v = up[i][v];
    return up[0][u];
}


void dfs(int cur, int par, ll tsum) {
	for(int i : qry_idx[cur]) {
		ll add = 1;
		if(i < 0)
			add = -2; 
		i = abs(i);
		ll sum = tsum - sum_till[qrs[i].x] + (freq_till[qrs[i].x] * qrs[i].y);
		ans[i] += add * sum;
	}
	for(auto nxt : adj[cur]) {
		if(nxt.ff == par)
			continue;
		++freq_till[nxt.ss.ff];
		sum_till[nxt.ss.ff] += nxt.ss.ss;
		dfs(nxt.ff, cur, tsum + nxt.ss.ss);
		sum_till[nxt.ss.ff] -= nxt.ss.ss;
		--freq_till[nxt.ss.ff];
	}
}

int main() {
	ios::sync_with_stdio(false);cin.tie(nullptr);
	cin >> N >> Q;
	for(int i = 1; i < N; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		adj[a].pb({b, {c, d}});
		adj[b].pb({a, {c, d}});
	}
	dfslca(1, 0);
	for(int i = 1; i <= Q; ++i) {
		cin >> qrs[i].x >> qrs[i].y >> qrs[i].u >> qrs[i].v;
		int L = getlca(qrs[i].u, qrs[i].v);
		//cerr << L << '\n';
		qry_idx[qrs[i].u].pb(i);
		qry_idx[qrs[i].v].pb(i);
		qry_idx[L].pb(-i);
	}
	dfs(1, 0, 0LL);
	for(int i = 1; i <= Q; ++i) {
		cout << ans[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 28924
#include <stdio.h>
#include <stdlib.h>
int main(){
  int flag,i,j,size,n,tmp,c=0;
  int *A;
  scanf("%d",&size);
  A = (int *)malloc(size * sizeof(int));
  flag = 1;
  for(i=0;i<size;i++){
    scanf("%d",&A[i]);
  }
  while(flag==1){
    flag = 0;
    for(j=size-1; j>=1; j--){
      if(A[j] < A[j-1]){
	tmp = A[j-1];
	A[j-1] = A[j];
	A[j] = tmp;
	flag = 1;
	c++;
      }
    }
  }
  if(size != 1){
  for(i=0;i<size-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  printf("%d\n",c);
    }
  
  if(size ==1){
    printf("%d\n%d\n",A[0],c);
  }
  return 0;
}



Measured memory_bytes: 2068
#include <iostream>
#include <fstream>
#include <string>

using namespace std;
//        tmp = stoi(S.substr(i,3));

int main(){

    string S;

    cin >> S;


    char tmp;

    if(S.size() == 3)
    {
        swap(S[0],S[2]);
    }

    cout << S << endl;
    return 0;
}



Measured memory_bytes: 256
mod = 10**9+7

n,a,b = map(int,input().split())

# 全ての場合の数
ans = pow(2,n,mod)-1

# a本の場合の数(nCa = a1/a2)
# a1 = n*(n-1)*...*(n-(a-1))の計算
a1 = 1
for i in range(a) :
  a1 = a1*(n-i)%mod
# 1/a2 = (1/a)*(1/(a-1))*...*(1/1)の計算
a2 = 1
for i in range(a) :
  a2 = a2*pow(a-i,mod-2,mod)%mod
  
# b本の場合の数(nCb = b1/b2)
# b1 = n*(n-1)*...*(n-(b-1))の計算
b1 = 1
for i in range(b) :
  b1 = b1*(n-i)%mod
# 1/b2 = (1/b)*(1/(b-1))*...*(1/1)の計算
b2 = 1
for i in range(b) :
  b2 = b2*pow(b-i,mod-2,mod)%mod

print((ans-a1*a2-b1*b2)%mod)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const LL L_INF = LLONG_MAX;
static const int MOD = (1000000000 + 7);

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

    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;
    for( int i = 100; i >= 1; --i ) {
        if( a % i == 0 && b % i == 0 ) ++cnt;
        if( cnt == k ) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int pri[1100000];

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

int main(){
    int n,m;
    int i,j,k;
    int a,b,c;
    for(i=2;i<=1e3;i++){
        if(pri[i])continue;
        for(j=i*i;j<=1e6;j+=i){
            if(pri[j]==0)pri[j]=i;
        }
    }
    cin>>n;
    set<int> s1;
    bool flag=false;
    b=0;
    for(i=0;i<n;i++){
        cin>>a;
        b=gcd(a,b);
        while(pri[a]){
            if(s1.find(pri[a])!=s1.end())flag=true;
            else s1.insert(pri[a]);
            c=pri[a];
            while(a%c==0)a/=c;
        }
        if(a>1){
            if(s1.find(a)!=s1.end())flag=true;
            else s1.insert(a);
        }
    }
    if(!flag)cout<<"pairwise coprime"<<endl;
    else if(b==1)cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
}

Measured memory_bytes: 11188
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    int n,m;cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[50][50];
int ans=0,v[50][50],run[4]= {0,1,0,-1},run1[4]= {1,0,-1,0},sum[50][50],n,m;
void solve(int x,int y,int xx,int yy)
{
    memset(v,0,sizeof(v));
    memset(sum,0,sizeof(sum));
    v[x][y]=1;
    queue<pair<int,int> >q;
    q.push(make_pair(x,y));
    while(!q.empty())
    {
        int qq=q.front().first;
        int ee=q.front().second;
        q.pop();
        for(int i=0; i<4; i++)
        {
            int tmp=qq+run[i];
            int tmp1=ee+run1[i];
            if(v[tmp][tmp1]||a[tmp][tmp1]=='#'||tmp<0||tmp>=n||tmp1<0||tmp1>=m)
                continue;
            v[tmp][tmp1]=1;
            sum[tmp][tmp1]=sum[qq][ee]+1;
            q.push(make_pair(tmp,tmp1));
        }
    }
    ans=max(ans,sum[xx][yy]);
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0; i<n; i++)
        scanf("%s",a[i]);
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            for(int k=0; k<n; k++)
                for(int l=0; l<m; l++)
                    if(a[i][j]!='#'&&a[k][l]!='#')
                        solve(i,j,k,l);
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

LL X;

int main(void) {
    cin >> X;

    unordered_map<LL, LL> cand;
    REP(i, INF) {
        const auto tmp = 1LL * i * i * i * i * i;
        if (tmp > LLINF) {
            // DEBUG(tmp)
            break;
        }
        cand[tmp] = i;
        cand[-tmp] = -i;
    }

    FORE(a, cand) {
        const auto b = X - a.first;
        if (cand.count(b)) {
            cout << a.second << " " << -cand[b] << endl;
            return 0;
        }
    }
    assert(false);
}


Measured memory_bytes: 3924
n = gets.to_i
arr = gets.split(" ")

hash = {}
arr.each { |num|
  if hash[num]
    hash[num] += 1
  else
    hash[num] = 1
  end
}

cmbs = hash.keys.combination(3).map {|arr| arr.map(&:to_i) }

count = 0

cmbs.each do |c|
  if c[0]+c[1] > c[2] && c[1]+c[2] > c[0] && c[0]+c[2] > c[1]
    count = count + hash[c[0].to_s] * hash[c[1].to_s] * hash[c[2].to_s]
  end
end

p count



Measured memory_bytes: 26900
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		double s[]=new double[1000],t1,t2;
		int n,i;
		while(true) {
			n=scan.nextInt();
			if(n==0) break;
			t1=0;
			for(i=0;i<n;i++) {
				s[i]=scan.nextDouble();
				t1+=s[i];
			}
			t1/=n;
			t2=0;
			for(i=0;i<n;i++) t2+=Math.pow(s[i]-t1, 2);
			System.out.println(Math.sqrt(t2/n));
		}
		scan.close();
	}
}


Measured memory_bytes: 39764
var
  n:string;
  i,s1,s2:longint;
begin
  readln(n);
  readln(n);
  for i:=1 to length(n) do
    if n[i]='(' then inc(s1) else
      if n[i]=')' then begin dec(s1);if s1<0 then begin inc(s2);s1:=0;end;end;
  for i:=1 to s2 do write('(');
  for i:=1 to length(n) do write(n[i]);
  for i:=1 to s1 do write(')');
  writeln;
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set


int main() 
{
	string s;
	cin>>s;
	REP(i,0,s.size()){
		if(s[i] == '7'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}  


Measured memory_bytes: 3620
import math

a, b, x = map(int, input().split())

# if x >= a*a*b/2
#   x = a*a*b - a*a*(a*sin(theta))/2
#   sin(theta) = 2*(a*a*b - x) / (a**3)
# else
#   x = a*(b*tan(theta))*b/2
#   tan(theta) = 2*x / (a*b*b)

if x >= a*a*b/2:
  theta = math.atan(2*(a*a*b-x)/(a**3))
  ans = math.degrees(theta)
else:
  theta = math.atan(2*x/(a*b*b))
  ans = 90.0 - math.degrees(theta)

print(ans)


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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		long N = nextLong();
		String S=nextString();

		long[] alph = disassemblyAlph(S);

		long ans = 1;
		for(int i=0;i<alph.length;i++){
			ans=ans*(alph[i]+1)%MOD;
		}
		ans--;

		System.out.println(ans);
	}


	public static long[] disassemblyAlph(String s) {
		long[] alph = new long['z' - 'a' + 1];
		Arrays.fill(alph, 0);
		for (int i = 0; i < s.length(); i++) {
			alph[s.charAt(i) - 'a']++;
		}
		return alph;
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

Measured memory_bytes: 23636
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;
#define START 0
#define FORWARD 1
#define BACK 2
using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;
bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
ll gcd(ll a, ll b)
{
	ll tmp, r;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
	//// 引数に０がある場合は０を返す
	//if ((0 == m) || (0 == n))
	//	return 0;

	//// ユークリッドの方法
	//while (m != n)
	//{
	//	if (m > n) m = m - n;
	//	else         n = n - m;
	//}
	//return m;
}//gcd
int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll x[100004] = {};
	ll y[100004] = {};
	ll z[100004] = {};
	ll x2[100004] = {};
	string s[1000];
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	//cout << LLONG_MAX<< endl;

	cin >> a;
	cin >> b;
	
	cout << (a*3+b)/2 << endl;
	//cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//sort(x, x + a, std::greater<ll>());

//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得
//
//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}
//
//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え


/*vector<pair<ll, ll> > hoges(a);
for (int i = 0; i < a; i++)
{
cin >> x[i];
cin >> y[i];
hoges[i] = make_pair(x[i], y[i]);
}
sort(hoges.begin(),hoges.end(),comp);
for (int i = 0; i < a; i++)
{
if (hoges[i].second>=b)
{
ans += hoges[i].first*b;
break;
}
else
{
ans += hoges[i].first*hoges[i].second;
b -= hoges[i].second;

}
}*/

Measured memory_bytes: 256
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int n,m;
V z;

main(){
	int i,j,a,b,c,t;
	for(;scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),n;){
		V x(n*n);
		V e(n*n);
		z.resize(n*n);

		x[0]=b;
		x[1]=c;
		e[0]=1;
		for(i=1;i<n-1;i++){
			x[i*n+i-1]=a;
			x[i*n+i]=b;
			x[i*n+i+1]=c;
			e[i*n+i]=1;
		}
		x[i*n+i-1]=a;
		x[i*n+i]=b;
		e[i*n+i]=1;
		for(;t;t>>=1){
			const V &_x=e;
			const V &_y=x;
			if(t&1){
				for(i=0;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(_x[slice(i*n,n,1)]*_y[slice(j,n,n)]).sum()%m;
				e=z;
			}
			for(i=0;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(_y[slice(i*n,n,1)]*_y[slice(j,n,n)]).sum()%m;
			x=z;
		}
		V s(n);
		for(i=0;i<n;i++)scanf("%d",&s[i]);
		const V &r=e;
		for(i=0;i<n-1;i++)printf("%d ",(r[slice(i*n,n,1)]*s).sum()%m);
		printf("%d\n",(r[slice(i*n,n,1)]*s).sum()%m);
	}
}

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

int main(){
    int n,m = 0;
    std::cin >> n >> m;
    
    std::vector<int> b;
    b.resize(m);
    for(auto &x : b){ x = 0;}
    
    std::vector< std::vector< int > > A;
    A.resize(m);
    for(auto &x : A){
        x.resize(n);
        for(auto &y : x){ y = 0;}
    }
    
    std::vector<int> c;
    c.resize(n);
    for(auto &x : c){ x = 0;}
    
    int tmp;
    for(int i=0;i<n; i++){
        for(int j=0; j<m; j++){
            std::cin >> tmp;
            A[j][i] = tmp;
        }
    }
    for(int i=0;i<m; i++){
        std::cin >> b[i];
    }
    
    
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            c[i] += A[j][i] * b[j];
        }
    }
    
    for(auto x : c){
        std::cout << x << std::endl;
    }
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long S){
    if(S == 1000000000000000000) {
        cout << "0 0 0 1000000000 1000000000 0" << endl;
        return;
    }

    // |x1y2 - x2y1| / 2 = 面積
    // x1 != 0
    // https://mathwords.net/x1y2hikux2y1#i
    LL x1 = 1;
    LL y1 = 1000000000;

    LL x2 = S / y1 + 1;
    LL y2 = y1 - S % y1;

    cout << "0 0 " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
}

int main(){
    long long S;
    scanf("%lld",&S);
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#define rep(i,N) for(int i=0;i<(N);i++)
#define PI 3.1415926535897932
using namespace std;

int main(){
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long ac=a*c, ad=a*d, bc=b*c, bd=b*d;
	long long CONST[]={ac,ad,bc,bd};

	long long max=CONST[0];
	for(int i=1;i<4;i++){
		if(CONST[i]>max)max=CONST[i];
	}
	cout<<max<<endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 2020

int s[SIZE][SIZE];
int sumc[SIZE][SIZE];
int suma[SIZE][SIZE];
int sumb[SIZE][SIZE];

void calc_sum(int v[SIZE][SIZE]){

  for(int i=0;i<SIZE-1;i++){
    for(int j=0;j<SIZE-1;j++){
      v[i][j+1] += v[i][j];
    }
  }

  for(int i=0;i<SIZE-1;i++){
    for(int j=0;j<SIZE-1;j++){
      v[i+1][j] += v[i][j];
    }
  }
  
}

int sum(int v[SIZE][SIZE], int y1, int x1, int y2, int x2){
  return v[y1-1][x1-1] + v[y2][x2] - v[y1-1][x2] - v[y2][x1-1];
}

int main(){
  int n,m,q;
  
  scanf("%d%d%d",&n,&m,&q);

  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      scanf("%1d",s[i]+j);
      sumc[i][j] += s[i][j];

      if(j>0 && s[i][j-1] && s[i][j]){
        suma[i][j-1]++;
      }
      if(i>0 && s[i-1][j] && s[i][j]){
        sumb[i-1][j]++;
      }
    }
  }

  calc_sum(suma);
  calc_sum(sumb);
  calc_sum(sumc);

  for(int i=0;i<q;i++){
    int xa,ya,xb,yb;
    
    scanf("%d%d%d%d",&xa,&ya,&xb,&yb);

    ll ans = 0;

    ans = sum(sumc,xa,ya,xb,yb);

    ans -= sum(sumb, xa,ya,xb-1,yb) + sum(suma, xa,ya,xb,yb-1);

    printf("%lld\n",ans);
  }
  
  
  return 0;
}


Measured memory_bytes: 65408
n = int(input())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))
    
sum_b = sum(list_b)

sum_c = 0
for i in range(0,len(list_a)-1,1):
  if list_a[i+1] == list_a[i] + 1:
    sum_c += list_c[list_a[i]-1]

print( sum_b + sum_c)
  

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#pragma warning(disable:4996)
#ifdef _MSC_VER
#  define __builtin_popcount __builtin_popcountll
#  define __builtin_popcountll __popcnt
#endif
#define int long long
using namespace std;
using ll = long long;
using ld = long double;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
inline void my_io() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << fixed << setprecision(10);
}
class BIT{
private:
	int N;
	vector<int>node;
public:
	BIT(vector<int>v) {
		N = v.size();
		node.resize(N + 1,0);
		//for (int i = 1; i <= N; i++) add(i, v[i-1]);
		
	}
	void add(int a, int w) {
		for (int x = a; x <= N; x += x & -x) node[x] += w;
	}
	int sum(int a) {
		int ret = 0;
		for (int x = a; x > 0; x -= x & -x) ret += node[x];
		return ret;
	}

};
signed main() {
	my_io();
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int>a_v(n);
	for (int i = 0; i < n; i++) {
		a_v[i] = a[i];
	}
	sort(a_v.begin(), a_v.end());
	map<int, int>b;
	for (int i = 0; i<n; i++) b[a_v[i]] = i + 1;//BITは1-indexedなので配列bのindexを1-indexedにしておく
	vector<int>v(n, 0);
	BIT bit(v);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += i - bit.sum(b[a[i]]);
		bit.add(b[a[i]], 1);

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




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

using namespace std;

const int N = 3e3+5;

const int mod = 1e9+7;

int n , m , k;
int grid[N][N];

long long mem[N][N][4];

long long go(int r , int c , int tk){
    if(r > n || c > m)
        return -1e12;
    if(r == n && c == m){
        if(tk + 1 <= 3 && grid[r][c])
            return grid[r][c];
        return 0;
    }
    long long &ret = mem[r][c][tk];
    if(~ret)
        return ret;
    ret = 0;
    if(tk + 1 <= 3 && grid[r][c]){
        ret = grid[r][c]
        + max(go(r + 1 , c , 0) , go(r , c + 1 , tk + 1 ));
    }
    ret = max(ret , max(go(r + 1 , c , 0) , go(r , c + 1 , tk)));
    return ret;
}

int main(){
    scanf("%d%d%d" , &n , &m , &k);
    for(int i = 1; i <= k; i++){
        int r , c , v;
        scanf("%d%d%d" , &r , &c , &v);
        grid[r][c] = max(grid[r][c] , v);
    }
    memset(mem , -1 , sizeof mem);
    printf("%lld\n" , go(1 , 1 , 0));
}


Measured memory_bytes: 321820
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
cntA = Counter(A)

S = 0
for c in cntA.values():
    S += c * (c - 1) // 2

ans = []
for a in A:
    ans.append(S - (cntA[a] - 1))

print(*ans, sep='\n')

Measured memory_bytes: 30004
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to,cap,rev; 
	edge (int from, int to, int cap, int rev){
		this->from=from; this->to=to; this->cap=cap; this->rev=rev;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;



int main(){
	int n, k;
	cin >> n >> k;
	int x=1;
	FORI(0, n) {
		x = min(x * 2, x + k);
	}
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
//Subhash Suman
//Date: 14/02/19 ; Day: Thursday ; Time: 17::14::46 
//Description : 

#include<bits/stdc++.h>
#define ll long long int
#define MAX INT_MAX
#define MIN INT_MIN
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>

using namespace std;
const int N = 1e5+5;
const ll mod = 1e9 + 7;
ll dp[N][2];
int n;
vector<vector<int>> g(N);
bool visited[N];

ll func(int i,bool b){
    //cout<<i<<b<<endl;
    if(dp[i][b]==0){
        ll ans = 1;
        if(b){
            for(int j = 0; j < g[i].size(); j++){
                if(visited[g[i][j]]==0){
                    visited[g[i][j]]=1;
                    ans = (ans*func(g[i][j],0))%mod;
                    visited[g[i][j]]=0;
                }
            }
        }
        else{
            for(int j = 0; j < g[i].size(); j++){
                if(visited[g[i][j]]==0){
                    visited[g[i][j]]=1;
                    ans = (ans*(func(g[i][j],0)+func(g[i][j],1)))%mod;
                    visited[g[i][j]]=0;
                }
            }
        }
        dp[i][b] = ans;
        //cout<<i<<'-'<<b<<'-'<<dp[i][b]<<'\n';
        return ans;
    }
    else{
        //cout<<i<<'-'<<b<<'-'<<dp[i][b]<<'\n';
        return dp[i][b];
    }
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    cin>>n;
    for(int i = 0; i < n-1; i++){
        int a,b;
        cin>>a>>b;
        visited[a] = 0;
        visited[b] = 0;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    visited[1] = 1;
    ll a1 = func(1,0);
    ll a2 = func(1,1);
    ll ans = (a1 + a2)%mod;
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 12928
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<utility>
#include<algorithm>
#include<bitset>
using namespace std;

int n,t[100005],x[100005],y[100005];
int main(){
  cin>>n;
  for(int i=1;i<=n;i++)cin>>t[i]>>x[i]>>y[i];
  for(int i=1;i<=n;i++){
    int a=((t[i]-t[i-1])-(x[i]-x[i-1]+y[i]-y[i-1]));
    if(a<0 || a%2!=0){
      cout<<"No"<<endl;return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}



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

int main() {
  int k,s,x,y,z,cnt=0;
  cin>>k>>s;
  for(x=0;x<=k;x++){
    for(y=0;y<=k;y++){
        if(s-x-y>=0&&s-x-y<=k){
          cnt++;
        }
      }
    }

  cout<<cnt<<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 < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const long long INF = 1LL<<60;

int main() {
    int n,k;
    cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll ans=0;
    for(int i=1;i<n;i++){
        if(a[i-1]+a[i]>k){
            int tmp=min(a[i-1]+a[i]-k,a[i]);
            ans+=tmp;
            a[i]-=tmp;
            if(a[i-1]+a[i]>k){
                ans+=a[i-1]-k;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, M = Scanner.map_int()
    G = [[] for _ in range(N)]
    for _ in range(M):
        a, b = Scanner.map_int()
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    q = []
    q.append(0)
    ans = [-1 for _ in range(N)]
    visited = [False for _ in range(N)]
    visited[0] = True
    while q != []:
        p = q.pop(0)
        for g in G[p]:
            if visited[g]:
                continue
            visited[g] = True
            ans[g] = p
            q.append(g)
    ans = [a + 1 for a in ans]
    print('Yes')
    print(*ans[1:], sep='\n')


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 40748