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

signed main() {
    string x;
    cin >> x;
    for (int i=0; i != x.size(); i++) {
        if (x[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3608
n = int(input())

d1 = n % 10

if d1 == 2 or d1 == 4 or d1 == 5 or d1 == 7 or d1 == 9:
    print("hon")
elif d1 == 0 or d1 == 1 or d1 == 6 or d1 == 8:
    print("pon")
elif d1 == 3:
    print("bon")

Measured memory_bytes: 9112
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  int N;
  int K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += A[i];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N = 100010;
ll ans;
int n,m,x,y;
vector<int> v[N];
bool pd[N],PD;
int dep[N],cnt[2];

void dfs(int x){
	cnt[dep[x]]++;
	pd[x]=true;
	int t;
	for(int i=0;i<v[x].size();i++) {
		t = v[x][i];
		if(!pd[t]){
			dep[t]=dep[x]^1;
			dfs(t);
		} else if(dep[x]==dep[t]){
			PD =false;
		}
	} 
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int tmp = 0,tmp1 = 0,tmp2 = 0;
	for(int i=1;i<=n;i++) if(!pd[i]) {
		//cout<<i<<endl;
		PD =true;
		cnt[0]=cnt[1]=0;	
		dfs(i);
		//cout<<cnt[0]<<' ',k//<
		if(cnt[0]==1 && cnt[1]==0){
			tmp++;
		} else{
			if(PD) tmp1++;
			else tmp2++;
		}
	}
//	cout<<tmp<<' '<<tmp1<<tmp2<<endl;
	ans = 1ll*(tmp1+tmp2)*(tmp1+tmp2);
	ans += 1ll*tmp1*tmp1;
	int tmp3=n-tmp;
	for(int i=1;i<=tmp;i++){
		tmp3++;
		ans += 2*tmp3-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    int H,W,N;
    cin >> H >> W >> N;
    int a = max(H,W);
    if(N%a == 0) out(N/a);
    else out(N/a+1);
    



    return 0;
}


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

signed main() {
  int a, b;
  cin >> a >> b;
  int c = a + b;
  if (c % 2 == 1)
    cout << "IMPOSSIBLE" << endl;
  else
    cout << c / 2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
    double x1,y1,x2,y2,x3,y3;
    int n;

    scanf("%d",&n);

    double a,b,c;
    double ans = 0;
    double xp,yp;
    for(int i = 0;i < n; i++){
        scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);

        a = hypot(x2 - x1,y2 - y1);
        b = hypot(x3 - x1,y3 - y1);
        c = hypot(x3 - x2,y3 - y2);

        ans = (a*b*c) / (sqrt((a+b+c)*(b+c-a)*(a-b+c)*(a+b-c)));
        xp = (((x1*x1)+(y1*y1))*(y2-y3)+((x2*x2)+(y2*y2))*(y3-y1)+((x3*x3)+(y3*y3))*(y1-y2))/(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2;
        yp = (((x1*x1)+(y1*y1))*(x2-x3)+((x2*x2)+(y2*y2))*(x3-x1)+((x3*x3)+(y3*y3))*(x1-x2))/(y1*(x2-x3)+y2*(x3-x1)+y3*(x1-x2))/2;
        printf("%.3lf %.3lf %.3lf\n",xp,yp,ans);
        ans = 0;
    }
    return 0;
}

Measured memory_bytes: 1252
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


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

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

  LL ans=0;
  for(pair<int, int> p: mp){
    ans += p.second -1;
  }
  if(ans%2) ++ans;
  cout<<n-ans<<endl;

  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
using namespace std;
 
int main(){
    int x, y;
 
    while(1){
        cin >> x >> y;
        if(x == 0 && y == 0){
            break;
        }else if(x <= y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }
 
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

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

    int ans=0;

    rep2(i,1,n+1){
        string nn=to_string(i);
        if(nn.size()%2!=0){
            ans++;
        }
    }
    cout<<ans<<endl;
}


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

void dfs(ll cur, ll par,ll par_color,vector<vector<pair<ll,ll>>> &adj,vector<ll> &ans){
  for(auto v:adj[cur]){
  	if(v.first==par && v.second==0)
      ans[cur] = par_color;
    else if(v.first==par && v.second==1)
      ans[cur] = (par_color+1)%2;
  }
  for(auto v:adj[cur]){
  	if(v.first==par)
      continue;
    dfs(v.first,cur,ans[cur],adj,ans);
  }
}

int main(){
  ll n;
  cin>>n;
  vector<vector<pair<ll,ll>>> adj(n+1);
  for(ll i=1;i<=n;i++){
     ll t1,t2,t3;
     cin>>t1>>t2>>t3;
     adj[t1].push_back({t2,t3%2});
     adj[t2].push_back({t1,t3%2});
  }
  vector<ll> ans(n+1);
  dfs(1,0,0,adj,ans);
  for(ll i=1;i<=n;i++)
    cout<<ans[i]<<endl;
}

Measured memory_bytes: 14176
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int hpi,hpm,R,C,T,S,n[1010],P,p[19],x,y,dy[]={0,1,0,-1},dx[]={1,0,-1,0},dp[1<<12];
char a[110][110],d[1010],c;
map<char,int> M,m;
vi v;
int tc;
int main(){
	m['R']=0,m['D']=1,m['L']=2,m['U']=3;
	while(cin>>hpi>>hpm&&hpi){tc++;
		v.clear();
		cin>>R>>C;
		rep(i,R)cin>>a[i];
		cin>>T;
		rep(i,T)cin>>c>>y,M[c]=y;
		cin>>S;
		rep(i,S)cin>>d[i]>>n[i];
		cin>>P;
		rep(i,P)cin>>p[i];
		y=x=0;
		rep(i,S){
			rep(j,n[i]){
				y+=dy[m[d[i]]],x+=dx[m[d[i]]];
				if(M[a[y][x]])v.pb(M[a[y][x]]);
			}
		}
		fill(dp,dp+(1<<P),-INF);
		dp[0]=hpi;
		rep(i,v.sz)rep(j,1<<P)if(dp[j]>0){
			rep(k,P)if(!(j&1<<k)){
				dp[j|1<<k]=max(dp[j|1<<k],min(hpm,dp[j]+p[k]));
			}
			dp[j]-=v[i];
		}
		cout<<(dp[(1<<P)-1]>0||!v.sz?"YES":"NO")<<endl;
	}
}

Measured memory_bytes: 952
a = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
a = a * 2
c = 0
z = input()
for i in range(0,7):
	if z == a[i]:
		for j in range(i + 1, 14):
			if a[j] == "SUN":
				print(j - i )


Measured memory_bytes: 8852
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
// ver1.7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

int sosuu(int a)
{
	for(int i=2;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			return 0;
		}
	}
	return a;
}

signed main() {
  cout << fixed << setprecision(14);
  int n;
  cin >> n;
  int ans = 1;
  int memo=0;
  int ct;
  
  repeq(i,2,n){
    if(sosuu(i)==0) continue;
    memo = i;
    ct = 1;
    while(n/memo > 0){
      ct += n/memo;
      memo *= i;
    }
    ans *= ct;
    ans %= MOD;
  }
  
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int h, w, a[1005][1005], mx[4] = {0, 1, 0, -1}, my[4] = {1, 0, -1, 0}, ans, l, r;
bool vis[10005][1005];

struct node
{
    int x, y, lev;
}q[1000005];

int main()
{
    cin >> h >> w;
    string s;
    for (int i = 1; i <= h; i++)
    {
        cin >> s;
        for (int j = 1; j <= w; j++)
        {
            if (s[j - 1] == '#')
            {
                vis[i][j] = 1;
                q[++r] = {i, j, 0};
            }
        }
    }
    l = 1;
    while (l <= r)
    {
        node x = q[l++];
        ans = max(ans, x.lev);
        for (int i = 0; i < 4; i++)
        {
            int xx = x.x + mx[i], yy = x.y + my[i];
            if (xx > h || xx < 1 || yy > w || yy < 1) continue;
            if (!vis[xx][yy])
            {
                vis[xx][yy] = 1;
                q[++r] = {xx, yy, x.lev + 1};
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16640
import scala.annotation.tailrec
import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._
  val EPS = 0.000000001
  for (_ ← 0 until readInt()) {
    val Array(a, b, c, d) = readLine.trim.split(' ').map(_.toInt)
    val cubic = if (a > 0) CubicEquation(a, b, c, d) else CubicEquation(-a, -b, -c, -d)
    val (positive, negative) = cubic.derivative.root.sorted match {
      case Nil ⇒
        if (cubic(0) == 0) (0, 0)
        else if (cubic(0) < 0) (1, 0)
        else (0, 1)
      case p::Nil ⇒
        if (cubic(0) == 0) (0, 0)
        else if (math.abs(cubic(p)) < EPS) {
          if (p > 0) (3, 0)
          else (0, 3)
        }else {
          if (cubic(0) < 0) (1, 0)
          else (0, 1)
        }
      case l::r::_ ⇒
        val (lp, ln) = binSearch(cubic, -300, l)
        val (mp, mn) = binSearch(cubic, r, l)
        val (rp, rn) = binSearch(cubic, r, 300)
        (lp + mp + rp, ln + mn + rn)
    }
    println(s"$positive $negative")
  }
  def binSearch(cubic: CubicEquation, min: Double, max: Double): (Int, Int) = {
    if (cubic(max) < -EPS || cubic(min) > EPS) (0, 0)
    else if (((min <= 0 && 0 <= max) || (max <= 0 && 0 <= min)) && cubic(0) == 0) (0, 0)
    else {
      var left = min
      var right = max
      while (math.abs(right - left) > EPS) {
        val mid = (left + right) / 2
        if (cubic(mid) >= 0) right = mid
        else left = mid
      }
      if (right > 0) (1, 0)
      else (0, 1)
    }
  }
}
case class CubicEquation(a: Long, b: Long, c: Long, d: Long) {
  def derivative: SquareEquation = SquareEquation(3 * a, 2 * b, c)
  def apply(x: Double): Double = a * x * x * x + b * x * x + c * x + d
}
case class SquareEquation(a: Long, b: Long, c: Long) {
  def root: List[Double] = {
    if (b * b - 4 * a * c < 0) Nil
    else if (b * b == 4 * a * c) List(-b / 2.0 / a)
    else List((-b - math.sqrt(b * b - 4 * a * c)) / 2.0 / a, (-b + math.sqrt(b * b - 4 * a * c)) / 2.0 / a )
  }
}


Measured memory_bytes: 48900
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,d;
  cin >> m >> d;
  int cnt = 0;
  for(int month = 1; month <= m; month++){
    for(int day = 22;day <= d; day++){
      if(day%10 <2) continue;
      if(month == (day%10) * (day/10)){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#define MAX 100
using namespace std ;
 
int main()
{
    int n;
    int t=0,h=0,x=0;
    char tarou[MAX], hanako[MAX];
     
    cin >> n ;
     
    for(;n>0;n--)
	{     
        cin >> tarou >> hanako;

		x = strcmp(tarou,hanako);
         
        if(x>0){
            t+=3;
        }
         
        if(x==0){
            t++;
            h++;
        }
         
        if(x<0){
            h+=3;
        }
    }    
     
    cout << t << ' ' << h << endl ;
     
    return 0;
}

Measured memory_bytes: 1164
L = input()
N = len(L)
MOD = 10**9 + 7
smaller = [0] * N
not_smaller = [0] * N

smaller[0] = 1
not_smaller[0] = 2

for i in range(1, N):
    if L[i] == "1":
        smaller[i] = 3 * smaller[i - 1] + not_smaller[i - 1]
        smaller[i] %= MOD
        not_smaller[i] = 2 * not_smaller[i - 1]
        not_smaller[i] %= MOD
    elif L[i] == "0":
        smaller[i] = 3 * smaller[i - 1]
        smaller[i] %= MOD
        not_smaller[i] = not_smaller[i - 1]
        not_smaller[i] %= MOD

ans = smaller[-1] + not_smaller[-1]
ans %= MOD
print(ans)


Measured memory_bytes: 67668
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#define REP(i, n) for(i = 0; i < n; i++)
using namespace std;
int main()
{
    set<string> D;
    int n, i;
    string str1, str2;
    cin >> n;
    REP(i, n) 
    {
        cin >> str1 >> str2;
        if(str1 == "insert") D.insert(str2);
        else
        {
            if(D.find(str2) == D.end()) cout << "no";
            else cout << "yes";
            cout << endl;
        }
    }
}

Measured memory_bytes: 32540
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=200005;
int A[N],B[N],n;
set<pii> s;
ll ans;

int pre(int x){
	return x==1?n:x-1;
}
int suf(int x){
	return x==n?1:x+1;
}

int main(){
	read(n);
	rep(i,1,n)read(A[i]);
	rep(i,1,n){
		read(B[i]);
		if(B[i]<A[i]){
			puts("-1");
			return 0;
		}
		if(B[i]>A[i])
			s.insert(mp(B[i],i));
	}
	while(!s.empty()){
		int k=(--s.end())->se;
		s.erase(mp(B[k],k));
		int x=B[pre(k)]+B[suf(k)];
		if(B[k]-x<A[k]){
			puts("-1");
			return 0;
		}
		ans+=(B[k]-A[k])/x;
		B[k]-=(B[k]-A[k])/x*x;
		if(B[k]>A[k])
			s.insert(mp(B[k],k));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=16,M=1<<N;
int n,m,x,c[N],a[N][N];
int res[16];
int f[M][N];//压缩方案的枚举
int main()
{
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		for(int j=1;j<=m;j++) cin>>a[i][j];
	}
	int ans=INF;
	for(int i=1;i<(1<<n);i++)
	{
		
		memset(res,0,sizeof res);
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				for(int k=1;k<=m;k++)
					res[k]+=a[j+1][k];
			}
		}
		int f=1;
		int cnt=0;
		for(int j=1;j<=m;j++)
		{
			if(res[j]<x)
			{
				f=0;
				break;
			}
		}
		if(f)
		{
			for(int j=0;j<n;j++)
			{
				if(i&(1<<j))
					cnt+=c[j+1];
			}
			ans=min(ans,cnt);
		}
	}
	if(ans==INF) puts("-1");
	else cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 3640
l_school =[[[0 for i in range(10)] for j in range(3)]for j in range(4)]

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

sw_First=True
for l_b in l_school:
    if sw_First==True:
        sw_First=False
    else:
        print("####################")
    for l_r in l_b:
        print("",*l_r)



Measured memory_bytes: 5628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a < 9 && b < 9) {
			System.out.println("Yay!");
		} else {
			System.out.println(":(");
		}
		

	}
}


Measured memory_bytes: 22100
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a, b;

signed main() {
	cin >> n >> a >> b;
	n++;
	n %= 12;
	if (n == 1)cout << a << " " << b << endl;
	else if (n == 2)cout << a - b << " " << b << endl;
	else if (n == 3)cout << a - b << " " << a << endl;
	else if (n == 4)cout << -b << " " << a << endl;
	else if (n == 5)cout << -b << " " << a - b << endl;
	else if (n == 6)cout << -a << " " << a - b << endl;
	else if (n == 7)cout << -a << " " << -b << endl;
	else if (n == 8)cout << -(a - b) << " " << -b << endl;
	else if (n == 9)cout << -(a - b) << " " << -a << endl;
	else if (n == 10)cout << b << " " << -a << endl;
	else if (n == 11)cout << b << " " << -(a - b) << endl;
	else cout << a << " " << -(a - b) << endl;
}


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

struct UnionFind{
    vector<int> d;
    UnionFind(int n = 0) : d(n, -1){}
    int find(int x){
        if(d[x]<0)
            return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y)
            return false;
        //size(x) < size(y)
        if(d[x] > d[y])
            swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return -d[find(x)];
    }
};

int deg[100005];
vector<int> to[100005];

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i,m){
        int a, b; cin >> a >> b;
        --a, --b;
        deg[a]++;
        deg[b]++;
        uf.unite(a,b);
    }
    rep(i,k){
        int c, d; cin >> c >> d;
        --c, --d;
        to[c].push_back(d);
        to[d].push_back(c);
    }
    rep(i,n){
        int ans = uf.size(i) - deg[i] - 1;
        for(auto u : to[i]){
            if(uf.same(u,i)) ans--;
        }
        printf("%d%c",ans, i==n-1 ? '\n': ' ');
    }
    return 0;
}

Measured memory_bytes: 6784
from heapq import heappush, heappop

comp = [(1, 1), (2, 1), (3, 1),
        (0, 2), (1, 2), (2, 2), (3, 2), (4, 2),
        (1, 3), (2, 3), (3, 3)]
numbers = range(11)
zeros = (11, 12)

def manhattan(v1, v2):
  x1, y1 = v1
  x2, y2 = v2
  return abs(x2 - x1) + abs(y2 - y1)

def heuristic(state):
  return sum([manhattan(state[i], comp[i]) for i in numbers])

def swaped(state, n1, n2):
  new_state = [i for i in state]
  new_state[n1], new_state[n2] = new_state[n2], new_state[n1]
  return tuple(new_state)

def main():
  while True:
    p1 = int(input())
    if p1 == -1:
      break
    l1 = [-1, -1, p1, -1, -1]
    l2 = [-1] + list(map(int, input().split())) + [-1]
    l3 = list(map(int, input().split()))
    l4 = [-1] + list(map(int, input().split())) + [-1]
    l5 = [-1, -1, int(input()), -1, -1]
    mp = [l1, l2, l3, l4, l5]
    init_state = [None] * 13
    for y in range(5):
      for x in range(5):
        if mp[y][x] != -1:
          if mp[y][x] == 0:
            if not init_state[11]:
              init_state[11] = (x, y)
            else:
              init_state[12] = (x, y)
          else:
            init_state[mp[y][x] - 1] = (x, y)
    init_state = tuple(init_state)
    dic = {}
    dic[init_state] = True
    que = []
    heappush(que, (heuristic(init_state) + 0, 0, init_state))
    while que:
      score, count, state = heappop(que)
      if score == count:
        print(count)
        break
  
      for z in zeros:
        for i in numbers:
          if manhattan(state[z], state[i]) == 1:
            new_state = swaped(state, i, z)
            if new_state not in dic:
              dic[new_state] = True
              new_score = heuristic(new_state) + count + 1
              if new_score <= 20:
                heappush(que, (new_score, count + 1, new_state))
    else:
      print("NA")

main()


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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
#define N 100010
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll result(ll a, ll b, ll p){
    ll ans=1;
    if(b==(-1))
        b=p-2;
    while(b){
        if(b&1){
            ans=(ans*a)%p;
        }
        a=(a*a)%p;
        b>>=1;
    }
    return ans;
}

ll T,n,m;

int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    cin >> n;
    string s;
    cin >> s;
    vector<vector<ll> >arr(n,vector<ll>(3,0)),brr(n,vector<ll>(3,0));
    for(int i=0;i<n;i++){
        if(s[i]=='R')
            arr[i][0]++;
        if(s[i]=='G')
            arr[i][1]++;
        if(s[i]=='B')
            arr[i][2]++;
        if(i>0){
            for(int j=0;j<3;j++){
                arr[i][j] += arr[i-1][j];
            }
        }
    }

    for(int i=n-1;i>=0;i--){
        if(s[i]=='R')
            brr[i][0]++;
        if(s[i]=='G')
            brr[i][1]++;
        if(s[i]=='B')
            brr[i][2]++;
        if(i<(n-1)){
            for(int j=0;j<3;j++){
                brr[i][j] += brr[i+1][j];
            }
        }
    }
    ll ans = 0;
    for(int i=1;i<n-1;i++){
        if(s[i]=='R'){
            ans += (arr[i-1][1]*brr[i+1][2]);
            ans += (arr[i-1][2]*brr[i+1][1]);
            for(int j=1;1;j++){
                if((i-j)<0 || (i+j)>=n)
                    break;
                if(s[i-j]=='G' && s[i+j]=='B')
                    ans--;
                if(s[i-j]=='B' && s[i+j]=='G')
                    ans--;
            }
        }
        if(s[i]=='G'){
            ans += (arr[i-1][0]*brr[i+1][2]);
            ans += (arr[i-1][2]*brr[i+1][0]);
            for(int j=1;1;j++){
                if((i-j)<0 || (i+j)>=n)
                    break;
                if(s[i-j]=='R' && s[i+j]=='B')
                    ans--;
                if(s[i-j]=='B' && s[i+j]=='R')
                    ans--;
            }
        }
        if(s[i]=='B'){
            ans += (arr[i-1][1]*brr[i+1][0]);
            ans += (arr[i-1][0]*brr[i+1][1]);
            for(int j=1;1;j++){
                if((i-j)<0 || (i+j)>=n)
                    break;
                if(s[i-j]=='G' && s[i+j]=='R')
                    ans--;
                if(s[i-j]=='R' && s[i+j]=='G')
                    ans--;
            }
        }
        // cout << ans << " ";
    }
    cout << ans;

    return 0;
}


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

char a[100005];
int x=0,y=0;
int ans=0;

int main()
{
	cin>>a;
	for (int i=0;i<sizeof(a);i++)
	{
		if (x==y)//只能出石头
		{
			x++;
			if (a[i]=='p') ans--;
		} 
		else//可以出布
		{
			y++;
			if (a[i]=='g') ans++;
		} 
	}
	printf("%d\n",ans);
	return 0;
}

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

#define int long long

const int N = 3005;

int dp[N][N] , n , m , x , y , mod , P2[N * N] , C[N][N];

void Add(int &x , int y) {
	(x += y) %= mod;
}

int Pow(int x , int y , int mod) {
	int res = 1;
	for(;y;y >>= 1 , x = x * x  % mod) {
		if(y & 1) {
			res = res * x  % mod;
		}
	} 
	return res;
}

main(void) {
	scanf("%lld%lld" , &n , &mod);
	dp[0][0] = 1;
	C[0][0] = 1;
	for(int i = 0;i <= n;++ i) {
		for(int j = 0;j <= n;++ j) {
			Add(dp[i + 1][j] , dp[i][j] * (j + 1) % mod);
			Add(dp[i + 1][j + 1] , dp[i][j]);
		}
	}
	
	for(int i = 1;i <= n;++ i) {
		C[i][0] = 1;
		for(int j = 1;j <= n;++ j) {
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
		}
	}
	
	P2[0] = 1;
	for(int i = 1;i <= n * n;++ i)
	P2[i] = P2[i - 1] * 2 % mod;
		
	int ans = 0;
	for(int i = 0;i <= n;++ i) {
		int now = Pow(2 , Pow(2 , i , mod - 1) , mod) * C[n][i] % mod;
//		cerr << i <<" "<< now << endl;
		if((n - i) & 1) now = mod - now;
		int res = 0;
		for(int j = 0;j <= n - i;++ j) {
			Add(res , dp[n - i][j] * P2[i * j] % mod * now % mod);
		}
//		cerr << i <<" "<< now <<" "<< res * Pow(now , mod - 2 , mod) % mod << endl;
		Add(ans , res);
	}
	cout << ans % mod << endl;
}

Measured memory_bytes: 211840
#ITP1_7_B - How Many Ways?
ns = []
xs = []
while True:
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        break
    ns.append(n)
    xs.append(x)
ans = []
for i in range(len(ns)):
    tmp = 0
    for a in range(1,ns[i]+1):
        for b in range(a,ns[i]+1):
            for c in range(b,ns[i]+1):
                if a+b+c == xs[i]:
                    if a!=b and b!=c and c!= a:
                        tmp += 1
    ans.append(tmp)
print(*ans,sep="\n")


Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>

using namespace std;

int main()
{
  int N,tmp;cin>>N;
  vector<int> A;
  string ret="APPROVED";

  for(int i=0;i<N;i++)
  {
    cin>>tmp;
    if(tmp%2==0) {A.push_back(tmp);}
  }

  int n=A.size();
  for(int j=0;j<n;j++)
  {
    if(A[j]%3!=0 && A[j]%5!=0)
    {
      ret="DENIED";
      break;
    }
  }

  cout<<ret<<endl;

  return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int N; cin>>N;
    map<string,int> M;
    rep(i,N){
        string tmp; cin>>tmp;
        M[tmp]++;
    }
    cout<<"AC x "<<M["AC"]<<endl;
    cout<<"WA x "<<M["WA"]<<endl;
    cout<<"TLE x "<<M["TLE"]<<endl;
    cout<<"RE x "<<M["RE"]<<endl;
}

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

int main(){
  int n, r, p, c, l[50];

  while(cin >> n >> r, n | r){
    for(int i=0;i<n;i++)
      l[i]=n-i;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      rotate(l,l+p-1,l+p+c-1);
    }
    cout<<l[0]<<endl;
  }

  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    string S;
    int K;
    cin >> K >> S;
    
    
    if (S.length()>K){
    	cout<<S.assign(S,0,K)<<"...";
	}
	else{
		cout << S;
	}
    
//    if(num[num.length()-1]=='2' || num[num.length()-1]=='4'|| num[num.length()-1]=='5'|| num[num.length()-1]=='7'|| num[num.length()-1]=='9'){
//    cout <<"hon";	
//	}
//	else if(num[num.length()-1]=='0'||num[num.length()-1]=='1'||num[num.length()-1]=='6'||num[num.length()-1]=='8'){
//		cout <<"pon";
//	}
//	else{
//		cout <<"bon";
//	}
    
}


Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main()
{
    int a, b;
    char op;
    while (true) {
        cin >> a >> op >> b;
        if (op == '?') {
            break;
         }
         if (op == '+') {
             cout << (a + b) << endl;
         }
         if (op == '-') {
             cout << (a - b) << endl;
         }
         if (op == '*') {
             cout << (a * b) << endl;
         }
         if (op == '/') {
             cout << (a / b) << endl;
         }
    } /* end of while */
   
    
}



Measured memory_bytes: 3052
using System;
namespace B_003_58
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            new Logic_A().Start();

        }

        public class Logic_A
        {
            public void Start()
            {
                var str = Console.ReadLine().Split(' ');
                var a = Convert.ToInt32(str[0]);
                var b = Convert.ToInt32(str[1]);
                var c = Convert.ToInt32(str[2]);

                Console.WriteLine(a + c == 2 * b ? "YES" : "NO");
            }
        }
    }
}

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

using namespace std;

int cnt = 0;

void hoge(int h, int w, int k, vector<vector<char>> vec, int s=0) {
  if (s == h + w) {
    int tmp = 0;
    for (int i = 0; i < h; ++i)
      for (int j = 0; j < w; ++j)
        if (vec[i][j] == '#')
          ++tmp;
    cnt += tmp == k;
    return;
  }

  vector<vector<char>> vec1 = vec;
  if (s < h) {
    for (int i = 0; i < w; ++i)
      vec1[s][i] = 'a';
  }
  else {
    for (int i = 0; i < h; ++i)
      vec1[i][s - h] = 'a';
  }

  hoge(h, w, k, vec, s+1);
  hoge(h, w, k, vec1, s+1);
}

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<char>> vec(h, vector<char>(w));
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      cin >> vec[i][j];

  hoge(h, w, k, vec);
  cout << cnt << endl;
}

Measured memory_bytes: 3628
import numpy as np

N, M = list(map(int, input().split()))

brk_stair = np.ones(N+1, dtype = int)
dp = np.zeros(N+1, dtype= int)

for _ in range(M):
    brk_stair[int(input())] = 0

#print(brk_stair)

dp[0] = 1
dp[1] = 1 * brk_stair[1]

for i in range(2, N + 1):
    dp[i] = (dp[i - 1] + dp[i-2]) * brk_stair[i]
    if(dp[i] > 1000000007):
        dp[i] = dp[i] % 1000000007

#print(dp)
print(dp[-1] % 1000000007)


Measured memory_bytes: 15836
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  string S; cin >> S;
  ll dp[100010][4];
  memset(dp, 0, sizeof(dp));
  dp[0][3] = 1;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'A') {
      dp[i+1][0] = (dp[i][0] + dp[i][3]) % MOD;
      dp[i+1][1] = dp[i][1];
      dp[i+1][2] = dp[i][2];
      dp[i+1][3] = dp[i][3];
    } else if (S[i] == 'B') {
      dp[i+1][0] = dp[i][0];
      dp[i+1][1] = (dp[i][1] + dp[i][0]) % MOD;
      dp[i+1][2] = dp[i][2];
      dp[i+1][3] = dp[i][3];
    } else if (S[i] == 'C') {
      dp[i+1][0] = dp[i][0];
      dp[i+1][1] = dp[i][1];
      dp[i+1][2] = (dp[i][2] + dp[i][1]) % MOD;
      dp[i+1][3] = dp[i][3];
    } else {
      dp[i+1][0] = (3 * dp[i][0] + dp[i][3]) % MOD;
      dp[i+1][1] = (3 * dp[i][1] + dp[i][0]) % MOD;
      dp[i+1][2] = (3 * dp[i][2] + dp[i][1]) % MOD;
      dp[i+1][3] = (3 * dp[i][3]) % MOD;
    }
  }
  cout << dp[S.length()][2] << endl;
}




Measured memory_bytes: 3584
from sys import stdin, stdout

s = input()
n = len(s)
P = 2019

# suffix_rems is a list of remainders obtained by dividing the suffix starting at i with P. suffix[i] = s[i:]%P.

suffix_rems = [-1]*n
suffix_rems[-1] = int(s[-1])%P

# Stores the frequency of remainders obtained. We just want number of (i, j) pairs.
rems_d = dict()
rems_d[0] = 1
rems_d[int(s[-1])] = 1

# Those remainders which occur more than once. To pick (i, j) pairs from N, we need N > 1.
special_keys = set()

for i in range(n-1)[::-1]:
    rem = (pow(10, n-i-1, P) * int(s[i]) + suffix_rems[i + 1])%P

    if rem in rems_d:
        rems_d[rem] += 1
        special_keys.add(rem)
    else:
        rems_d[rem] = 1

    suffix_rems[i] = rem

ans = 0
for key in special_keys:
    t = rems_d[key]
    # pick any two of those same remainder indices.
    ans += (t*(t-1))//2

print(ans)

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

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    int now = 0;
    vector<int> visited(60, 0);

    while(1){
        int t = now % 60;
        if(visited[t]){
            cout << -1 << endl;
            return 0;
        }
        if(t <= c && c <= t + a){
            cout << now + c - t << endl;
            return 0;
        }

        visited[t] = 1;
        now = now + a + b;
    }

    return 0;
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;

long long int getMinimumCost(long long int arr[], long long int size, long long int k)
{
    long long int dp[size];
    dp[0] = 0;
    dp[1] = abs(arr[0] - arr[1]);
    for(long long int i = 1 ; i < size ; i++)
    {
        long long int currMin = 1e9;
        for(long long int j = i-1 ; (j >= i - k) && (j >= 0) ; j--)
        {
            currMin = min(currMin, abs(arr[i]-arr[j]) + dp[j]);
        }
        dp[i] = currMin;
    }
    return dp[size-1];
}

int main(int argc, const char * argv[])
{
    long long int size;
    long long int k;
    cin>>size>>k;
    long long int arr[size];
    for(long long int i = 0 ; i < size ; i++)
    {
        cin>>arr[i];
    }
    cout<<getMinimumCost(arr, size, k)<<endl;
    return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES

//#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <vector>
    
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main(){
    int k;
    string s;

    cin>>k;
    cin>>s;

    if(s.length()>k){
        cout<<s.substr(0,k)<<"..."<<endl;
        return 0;
    }else{
        cout<<s<<endl;
        return 0;
    }


} // end of main
    
//実行は、Opt + Ctl + N


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
int main() {
	ll x,y;
	cin >> x >> y;
	ll ans = INF;
	if (x <= y) chmin(ans, y-x);
    if (-x <= y) chmin(ans, y+x+1);
    if (x <= -y) chmin(ans, -y-x+1);
    if (-x <= -y) chmin(ans, -y+x+2);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

#define maxn 100010
bool ac[maxn];
int pen[maxn];
int main()
{
  int n, m, sol = 0, sp = 0; scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i)
  {
    int pid; char state[20]; scanf("%d%s", &pid, state);
    if (state[0] == 'A')
    {
      if (!ac[pid]) ++sol;
      ac[pid] = 1;
    }
    else
    {
      if (!ac[pid]) ++pen[pid];
    }
  }
  for (int i = 1; i <= n; ++i)
    if (ac[i]) sp += pen[i];
  printf("%d %d\n", sol, sp);
  return 0;
}


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


int n,k;
int arr[100005];


int f(){

	int dp[n+1]={0};
	dp[0]=0;
	dp[1] = abs(arr[1]-arr[0]);


	for(int i=2;i<n;i++)
	{
		dp[i] = INT_MAX;
		for(int j=i-1;j>=0&&j>=i-k;j--){
			dp[i] = min(dp[i],(abs(arr[j]-arr[i])+dp[j]));
		}
	}

	return dp[n-1];
}


int main(){

	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>arr[i];


	cout<<f()<<endl;
}




Measured memory_bytes: 1024
N = int(input())

n = int(N**0.5) + 1
A = 0
B = 0
b = 0
for a in range(1, n):
    if N % a == 0:
        b = N // a
        A = a
        B = b
ans = (A - 1) + (B - 1)
print(ans)

Measured memory_bytes: 3060
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    int n;
    scan(n);
    auto a = new int[][](n, n);
    iota(n).each!(i => a[i] = readArr!(int));

    auto dp = new long[](1 << n);
    dp[0] = 1;

    foreach (s ; 1 .. 1<<n) {
        auto i = popcnt(s) - 1;
        foreach (j ; 0 .. n) if ((s & (1 << j)) && a[i][j]) {
            dp[s] += dp[s ^ (1 << j)];
            dp[s] %= mod;
        }
    }

    writeln(dp[(1 << n) - 1]);
}










int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {writeln(b ? "Yes" : "No");}
void YES(bool b) {writeln(b ? "YES" : "NO");}
T[] readArr(T)() {return readln.split.to!(T[]);}
T[] readArrByLines(T)(int n) {return iota(n).map!(i => readln.chomp.to!T).array;}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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


int main() {

  int64_t n;
  cin>>n;

  map<int64_t, int64_t> A;
  for(int i=0;i<n;i++){
    int64_t wk;
    cin>>wk;
    if(A.count(wk))
      A.at(wk)++;
    else
      A[wk]=1;
  }

  int64_t sum=0;
  for (auto p : A) {
  auto key = p.first;
  auto value = p.second;
  sum+=key*value;
}

  int64_t q;
  cin>>q;

  for(int i=0;i<q;i++){
    int64_t b,c;
    cin>>b>>c;

    if(A.count(b)){
      int64_t wk=A.at(b);
      sum = sum-A.at(b)*b+c*A.at(b);
      A.erase(b);
      if(A.count(c))
        A.at(c)+=wk;
      else
        A[c]=wk;
    }
    cout<<sum<<endl;
  }


  return 0;
}




Measured memory_bytes: 7500
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a, b;
int ans;

signed main() {
	cin >> n >> a >> b;
	ans = mod_pow(2, n, mod) - 1;
	ans = (ans + 2 * mod - comb(n, a) - comb(n, b)) % mod;
	cout << ans << endl;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    string s;cin >> s;
    lint ans = 0;
    lint b = 0;
    lint w = 0;

    REP(i,SZ(s)){
        if (s[i] == 'B'){
            b += 1;
            w = 0;
        }else{
                ans += b;
        }
    }

    cout << ans <<"\n";

    return 0;
}

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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<vector<int>> a(h, vector<int>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}

	vector<int> x, y, x_, y_;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w - 1; j++) {
			if (a[i][j] % 2 == 1) {
				x.push_back(i + 1);
				y.push_back(j + 1);
				x_.push_back(i + 1);
				y_.push_back(j + 2);
				a[i][j + 1]++;
			}
		}
		if (i < h - 1 && a[i][w - 1] % 2 == 1) {
			x.push_back(i + 1);
			y.push_back(w);
			x_.push_back(i + 2);
			y_.push_back(w);
			a[i + 1][w - 1]++;
		}
	}

	cout << x.size() << endl;
	for (int i = 0; i < x.size(); i++) {
		cout << x[i] << " " << y[i] << " " << x_[i] << " " << y_[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 5224
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> i_i;
int inf = 1000000000;

int main() {
    int N, M;
    cin >> N >> M;
    int a, b, c, d[1010] = {0}, prev[1010] = {0};
    vector<i_i> g[1010];
    vector<vector<int>> ans(N + 1, vector<int>(N + 1, -1));
    for (int i = 0; i < M; i++) {
        cin >> a >> b >> c;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
        ans[a][b] = 0;
        ans[b][a] = 0;
    }

    for (int s = 1; s <= N; s++) {
        // initialize
        priority_queue<i_i, vector<i_i>, greater<i_i>> q;

        q.push({0, s});
        for (int i = 1; i <= N; i++) {
            if (s != i) {
                d[i] = inf;
            }
        }

        // dijkstra
        while (!q.empty()) {
            int u = q.top().second;
            q.pop();
            for (auto p : g[u]) {
                int v = p.first, l = p.second, alt = d[u] + l;
                if (d[v] > alt) {
                    d[v] = alt;
                    prev[v] = u;
                    q.push({alt, v});
                }
            }
        }
        for (int i = 1; i <= N; i++) {
            if (i != s) {
                ans[i][prev[i]] = 1;
                ans[prev[i]][i] = 1;
            }
        }
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j < i; j++) {
            if (ans[i][j] != -1) M -= ans[i][j];
        }
    }

    cout << M << endl;
    return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define mod 1000000007

int N;
int T[50];
int dp[2][1001][1001];

int main(){
  cin>>N;
  rep(i,N)cin>>T[i];
  int crt=0,nxt=1;
  rep(j,1001)rep(k,1001)dp[crt][j][k]=INF;
  dp[crt][0][0]=0;
  rep(i,N){
    rep(j,1001)rep(k,1001)dp[nxt][j][k]=INF;
    rep(j,1001)rep(k,1001){
      if(j+T[i]<=1000)minch(dp[nxt][j+T[i]][k],dp[crt][j][k]);
      if(k+T[i]<=1000)minch(dp[nxt][j][k+T[i]],dp[crt][j][k]);
      minch(dp[nxt][j][k],dp[crt][j][k]+T[i]);
    }
    swap(crt,nxt);
  }
  int res=INF;
  rep(j,1001)rep(k,1001)minch(res,max(dp[crt][j][k],max(j,k)));
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 10924
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<pair<ll,ll> > a(n);
    REP(i,n){
        cin >> a[i].fi;
        a[i].se = i;
    }
    sort(rALL(a));
    vvll dp(n+1,vll(n+1,0LL));
    REP(i,n){
        REP(j,i+1){
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]+a[i].fi*abs(n-1-(i-j)-a[i].se));
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+a[i].fi*abs(a[i].se-j));
        }
    }
    ll ans = 0;
    REP(i,n+1){
        ans = max(ans,dp[n][i]);
    }
    cout << ans << endl;
    

    return 0;
}

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

using namespace std;
typedef long long ll;
const int inf = 1000000000; // 10^9

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int N;
  cin >> N;
  int arr[N];
  int res = inf;

  // Store X-coordinates. 
  for(int i=0; i<N; i++) {
    cin >> arr[i];
  }

 
  // Brute force for all possible coordinates.
  for(int i=1; i<=100; i++) {
    int cost = 0;
    // Calculate cost (stamina) for meeting a point i.
    for(int j=0; j<N; j++) {
      cost += (arr[j] - i) * (arr[j] - i);
    }
    // Compare the cost to the previous min. cost.
    res = min(res,cost);
  }
  
  cout << res << '\n';
  return 0;
}



Measured memory_bytes: 3624