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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n, m;cin >> n >> m;

	vector<P> mp;
	REP(i, n){
		ll a;cin >> a;
		mp.EB(a, 1);
	}
	REP(i, m){
		ll a, b;cin >> a >> b;
		mp.EB(b, a);
	}

	sort(ALL(mp), greater<P>());

	ll ans = 0;
	ll cou = 0;

	REP(i, mp.size()){
		int now = min((n - cou), mp[i].SE);
		cou += now;
		ans += now * mp[i].FI;
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    int x = 0;
    ll ans = 0;
    for(int l = 0, r = 0; l < N; l++) {
        while(r < N && (x ^ A[r]) == (x + A[r])) {
            x ^= A[r];
            r++;
        }
        ans += r - l;
        x ^= A[l];
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007
int ans[1100][1100];

int main()
{

	int H, W;
	cin >> H>> W;

	queue<pair<int, int>> wheres;


	fx(H) {
		string field;
		cin >> field;
		fy(W) {
			if (field[y] == '.') {
				ans[x + 1][y + 1] = INT_MAX-1;
			}
			else {
				wheres.push(make_pair(x+1, y+1));
			}

		}
	}

	while (!wheres.empty()) {
		int x = wheres.front().first;
		int y = wheres.front().second;
		wheres.pop();

		if (ans[x - 1][y]>ans[x][y] + 1) {
			ans[x - 1][y] = ans[x][y] + 1;
			wheres.push(make_pair(x - 1, y));
		}
		if (ans[x + 1][y]>ans[x][y] + 1) {
			ans[x + 1][y] = ans[x][y] + 1;
			wheres.push(make_pair(x + 1, y));
		}
		if (ans[x][y + 1]>ans[x][y] + 1) {
			ans[x][y + 1] = ans[x][y] + 1;
			wheres.push(make_pair(x, y + 1));
		}
		if (ans[x][y - 1]>ans[x][y] + 1) {
			ans[x][y - 1] = ans[x][y] + 1;
			wheres.push(make_pair(x, y - 1));
		}
	}

	int anser = 0;
	fx(H) {
		fy(W) {
			anser = max(anser, ans[x + 1][y + 1]);
		}
	}
	ce(anser)
    return 0;
}



Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll func(ll x) {
  return x * (x - 1) / 2;
}

void solve() {
  int n;
  cin >> n;
  map<string, ll> mp;
  rep(i,n) {
    string s;
    cin >> s;
    sort(ALL(s));
    mp[s]++;
  }
  ll ans = 0;
  for (auto p: mp) {
    if (p.second == 1) continue;
    ans += func(p.second);
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 11320
while True:    
    n, k = map(int, raw_input().split())
    if n==0: break
    t = [0]*(n+2)
    for i in xrange(k):
        t[input()] += 1
    for i in xrange(2,n+1):
        if t[i] > 0: t[i] += t[i-1]
    ans = 0
    if t[0]==0:
        for x in t:
            if ans < x: ans = x
    else:    
        nt = []
        for i in xrange(2,n+2):
            if t[i]==0:
                t[i-t[i-1]] = t[i-1]
        for i in xrange(2,n+1):
            if t[i]==0:
                nt.append(t[i-1]+1+t[i+1])
            else: nt.append(t[i])
        for x in nt:
            if ans < x: ans = x
    print ans

Measured memory_bytes: 7884
S = list(input())

ans = 0
if len(S)%2 == 0:
    mid = len(S)//2 - 1
    mid2 = mid + 1
    for i in range(len(S)//2):
        if S[mid-i] != S[mid2+i]:
            ans += 1
    print(ans)
    
else:
    mid = len(S)//2
    for i in range(len(S)//2):
        if S[mid-i-1] != S[mid+i+1]:
            ans += 1
    print(ans)
    

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    int k,q;
    cin>>k>>q;
    LL D[k];
    LL d[k];
    LL s[k+1];
    s[0]=0;
    for(int i=0;i<k;i++){
        cin>>D[i];
    }

    LL N[q];
    LL X[q];
    LL M[q];
    LL ans[q];
    for(int i=0;i<q;i++){
        cin>>N[i]>>X[i]>>M[i];
    }

    for(int Q=0;Q<q;Q++){
        LL n,x,m;
        n=N[Q];x=X[Q];m=M[Q];
        for(int i=0;i<k;i++){
            d[i]=D[i]%m;
            if(d[i]==0){d[i]=m;}
        }
        for(int i=1;i<=k;i++){
            s[i]=s[i-1]+d[i-1];
        }
        LL a=(n-1)/k;
        LL b=(n-1)%k;
        LL c=a*s[k]+s[b]+(x%m);
        ans[Q]=n-(c/m)-1;
    }
    for(int i=0;i<q;i++){cout<<ans[i]<<endl;}
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<map>
#include<stack>
using namespace std;
int dx[] = { -1,0,0,1,-1,-1,1,1,0 };
int dy[] = { 0,1,-1,0,1,-1,1,-1,0 };
/*
int main()
{
	int r, c;
	cin >> r >> c;
	int sy, sx, gy, gx;
	vector<vector<char>>field(r,vector<char>(c));
	sy--, sx--, gy--, gx--;
	for (int i = 0; i < r; i++)
	{
		for (int j = 0; j < c; j++)
		{
			cin >> field[i][j];
		}
	}
	queue<pair<int,int>>q;
	q.push({ sx,sy });
	vector<vector<int>>d(c, vector<int> (r, -1));
	d[sx][sy] = 0;

	while (!q.empty())
	{
		pair<int, int>p = q.front;
		q.pop();
		for (int i = 0; i < 4; i++)
		{
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (nx < 0 || ny < 0 || nx >= c || ny >= r || d[nx][ny] != -1 || field[nx][ny] == '#')continue;
			q.push({ nx,ny });
			d[nx][ny] = d[p.first][p.second] + 1;
		}
	}

	cout << d[gx][gy] << endl;
}*/


int main() 
{
	int n, k;
	cin >> n >> k;
	vector<int>x(n);
	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
	}

	int ans = 0;
	int de = 0;

	for (int i = 0; i < n; i++)
	{
		if (x[i] <= (k - x[i]))
		{
			ans += x[i] * 2;
		}

		else if ((k - x[i]) < x[i])
		{
			ans += (k - x[i]) * 2;
		}



	}

	cout << ans  << endl;


}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int a, b; cin >> a >> b;
    if(a != 1 and b != 1) cout << 1 << endl;
    else if(a != 2 and b != 2) cout << 2 << endl;
    else if(a != 3 and b != 3) cout << 3 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a[13],c,b,i,d=0;
double e,x,y,z,w;
while(scanf("%d,",&a[0])!=EOF){
b=a[0];
for(i=1;i<11;i++){
scanf("%d,",&a[i]);
b=b+a[i];
}
b=b-a[10];
scanf("%d\n",&a[11]);
x=a[10]+a[11];
y=a[10];
z=b;
e=z*(y/x);
for(i=0;i<10;i++){
d=d+a[i];
w=d;
if(w>=e){
break;
}
}
d=0;
printf("%d\n",i+1);
}
return 0;
}


Measured memory_bytes: 2024
#include<stdio.h>
unsigned int N,i,A[9],S,ans,j,C,t;

int main()
{
	scanf("%d\n",&N);
	for(;N--;)
	{
		for(i=S=C=0;i<9;i++)
		{
			scanf("%x",&A[i]);
			if(i<8)
				S+=A[i];
		}
		if((A[8]&1)!=(S&1))
		{
			t=0;
			ans=1;
			for(j=0;j<8;j++)t+=(A[j]^1)&1;
			C+=t;
		}
		else
		{
			t=0;
			ans=0;
			for(j=0;j<8;j++)
				t+=(A[j]^0)&1;
			C+=t;
		}
		for(i=1;i<32;i++)
		{
			t=0;
			for(j=0;j<8;j++)
				t+=((A[j]^0)>>i)&1;
			if(C>>i&1)
				t++;
			if((t&1)==(((A[8]^0)>>i)&1))
			{
				C+=(t&0xffffffe)<<i;
				continue;
			}
			else
			{
				t=0;
				for(j=0;j<8;j++)
				{
					t+=((A[j]^0xffffffff)>>i)&1;
				}
				if(C>>i&1)
					t++;
				ans+=1<<i;
				C+=(t&0xffffffe)<<i;
			}
		}
		printf("%x\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1032
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    base=[1, 2, 4, 7, 12, 20, 29, 38, 52, 73]

    ans=[[0]*n for _ in range(n)]
    ans[1][0]=ans[0][1]=1

    for vn in range(3,n+1):
        mx=0
        for path in permutations(range(vn-1)):
            cur=sum(ans[v0][v1] for v0,v1 in zip(path,path[1:]))
            if cur>mx:mx=cur

        ans[vn - 1][0] = ans[0][vn - 1] = base[vn-2] * (mx + 1)
        ans[vn - 1][vn-2] = ans[vn-2][vn - 1] = base[vn-3] * (mx + 1)
        for j in range(1,vn-2):
            ans[vn-1][j]=ans[j][vn-1]=base[j-1]*(mx+1)

    for row in ans:print(*row)

main()

Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			ArrayList<Integer> list = new ArrayList<Integer>();
			for (int i = 0; i < n; i++) {
				list.add(sc.nextInt());
			}
			Collections.sort(list);
			long[] a = new long[n];
			long ans = 0;
			long v = list.get(0);
			a[0] = 0;
			for (int i = 1; i < n; i++) {
				a[i] = v;
				v += list.get(i);
				ans += a[i];
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 53120
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	const int a = pow(10,9) + 7;
	int n;
	unsigned long long int ret=1;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		ret = ret*i%a;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
p = gets.split.map(&:to_i)

count = 0
1.upto(n-2) do |x|
  count += 1 if (p[x-1]<p[x] && p[x]<p[x+1]) || (p[x+1]<p[x] && p[x]<p[x-1])
end
p count


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define y1 yy
#define ll long long
ll x1,y1,x2,y2,s;
ll cross()
{
    return x1*y2-x2*y1;
}
int main()
{
    cin>>s;
    y2=1000000000;
    x1=(s+y2-1)/y2;
    ll d=x1*y2-s;
    x2=d;
    y1=1;
    //printf("%lld\n",cross());
    printf("0 0 %lld %lld %lld %lld\n",x1,y1,x2,y2);
    return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    vector<int> H(N);
    for(int i=0; i<N; ++i) cin >> H[i];
    vector<vector<int>> G(N);
    for(int i=0; i<M; ++i) {
        int a, b; cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }

    int res = 0;
    for(int i=0; i<N; ++i) {
        bool good = true;
        for(int neighbor : G[i]) {
            if(H[i] <= H[neighbor]) good = false;
        }
        if(good) ++res;
    }

    cout << res << '\n';
}

Measured memory_bytes: 8804
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc158_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var N = CIn.ReadLong();
      var A = CIn.ReadLong();
      var B = CIn.ReadLong();

      var ans = N / (A + B) * A + Math.Min(N % (A + B), A);

      Console.WriteLine(ans);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


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

using namespace std;

typedef long long ll;

const ll INF = 1e17;

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

  vector<vector<ll> > vec1(N, vector<ll>(N, INF));

  for(int i=0;i<M;i++) {
    int node1;
    int node2;
    int length;

    cin >> node1 >> node2 >> length;

    vec1[node1-1][node2-1] = length;
    vec1[node2-1][node1-1] = length;
  }

  for(int i=0;i<N;i++) {
    for(int j=0;j<N;j++) {
      if(i == j) {
        vec1[i][j] = 0;
      }
    }
  }

  for(int k=0;k<N;k++) {
    for(int i=0;i<N;i++) {
      for(int j=0;j<N;j++) {
        if (vec1[i][j] > vec1[i][k] + vec1[k][j]) {
          vec1[i][j] = vec1[i][k] + vec1[k][j];
        }
      }
    }
  }

  vector<vector<ll> > vec2(N, vector<ll>(N, INF));

  for(int i=0;i<N;i++) {
    for(int j=0;j<N;j++) {
      if(vec1[i][j] <= L) {
        vec2[i][j] = 1LL;
      }
      if(i == j) {
        vec2[i][j] = 0;
      }
    }
  }

  for(int k=0;k<N;k++) {
    for(int i=0;i<N;i++) {
      for(int j=0;j<N;j++) {
        if (vec2[i][j] > vec2[i][k] + vec2[k][j]) {
          vec2[i][j] = vec2[i][k] + vec2[k][j];
        }
      }
    }
  }

  int Q;
  cin >> Q;

  for(int k=0;k<Q;k++) {
    int i, j;
    cin >> i >> j;

    if(vec2[i-1][j-1] < INF) {
      cout << vec2[i-1][j-1] - 1 << endl;
    } else {
      cout << -1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
  class Point
  {
    public double X { get; private set; }
    public double Y { get; private set; }
    public Point(double x, double y)
    {
      X = x;
      Y = y;
    }

    public static Point operator+ (Point p1, Point p2)
    {
      return new Point(p1.X + p2.X, p1.Y + p2.Y);
    }

    public static Point operator- (Point p1, Point p2)
    {
      return new Point(p1.X - p2.X, p1.Y - p2.Y);
    }
  }

  class Program
  {
    public static void Main()
    {
      var n = int.Parse(Console.ReadLine());
      foreach (var points in ReadPoints().Take(n))
        if (Cross(points[0] - points[1], points[2] - points[3]) == 0.0)
          Console.WriteLine("YES");
        else
          Console.WriteLine("NO");
    }

    public static double Cross(Point p1, Point p2)
    {
      return p1.X * p2.Y - p1.Y * p2.X;
    }

    static IEnumerable<Point[]> ReadPoints()
    {
      string line;
      while ((line = Console.ReadLine()) != null)
        yield return line.Split(' ').Select((s, i) => new { Index = i, Value = double.Parse(s) })
                                    .GroupBy(x => x.Index / 2)
                                    .Select(x => x.Select(v => v.Value))
                                    .Select(x => new Point(x.First(), x.Skip(1).First()))
                                    .ToArray();
    }
  }
}

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

typedef long long ll;
const int MAX_N = 100030;    // Change as necessary
const ll  MODD = 1000000009; //

int A[MAX_N];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n; cin >> n;
  string s,t; cin >> s >> t;
  
  for(int i=0;i<=n;i++){
    string r = s + t.substr(n-i);
    if(r.substr(r.length()-n) == t){
      cout << r.length() << endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock(); 

    str s; cin >> s;
    int ca = 0, cb = 0;

    repa(i, sz(s)){
    	ca += (s[i] == 'A');
    	cb += (s[i] == 'B');
    }
    
    if (ca == 0 || cb == 0) 
    	cout << "No" << endl;
    else
       	cout << "Yes" << endl;

    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl; 
    return 0; 
}

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

int q[100001];

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

    int n, p;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> p;
        q[p] = i;
    }

    set <int> myset;
    myset.insert(-1); myset.insert(0); myset.insert(n+1); myset.insert(n+2);

    set <int> :: iterator it;
    int i, j;
    long long a, b, c, d, x, y;
    long long ans = 0;
    for (i = n; i > 0; i--){
        j = q[i];
        it = myset.insert(j).first;
        b = *(--it); a = *(--it);
        ++it; ++it;
        c = *(++it); d = *(++it);
        x = (a == -1) ? 0 : (c - j)*(b - a);
        y = (d == n+2) ? 0 : (d - c)*(j - b);
        ans += (x + y) * i;
    }
    cout << ans << '\n';

}


Measured memory_bytes: 5376
'use strict'

const main = (input) => {
    input = input.split('\n');
    const As = input[1].split(' ').map((A) => Number(A));

    let reverseAs = 0;
    for (const A of As) {
        const reverseA = 1 / A;
        reverseAs += reverseA;
    }

    const ans = 1 / reverseAs;
    console.log(ans);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		BigInteger x = new BigInteger(sc.next());
		BigInteger k = new BigInteger(sc.next());
		BigInteger d = new BigInteger(sc.next());
		BigInteger abs = x.abs();
		BigInteger goal = null;
		
		BigInteger div = abs.divide(d);
		if (div.compareTo(k) > 0) {
			goal = abs.subtract(d.multiply(k));
		} else if (div.compareTo(k) == 0) {
			goal = abs.subtract(d.multiply(k));
		} else {
			// 距離縮める
			abs = abs.subtract(d.multiply(div));
			// 残り試行が奇数か偶数か
			BigInteger exa = k.subtract(div).mod(BigInteger.TWO);
			if (exa.equals(BigInteger.ZERO)) {
				// 偶数回
				goal = abs;
			} else {
				goal = abs.subtract(d).abs();
			}
		}
		System.out.println(goal);
	}
}


Measured memory_bytes: 35788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (register int i = a; i <= b; i++)

int x, y;

inline void solve(int T) {
    cin >> x >> y;
    rep(i, 0, x) {
        if(i * 2 + (x - i) * 4 == y) {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";

}   
int main()
{
//     ios_base::sync_with_stdio(0);
//     cin.tie(0);
//     cout.tie(0);
 
    // freopen("in.txt", "r", stdin);
    // freopen("out2.txt", "w", stdout);
 
    int T = 1;
    // cin >> T;
    rep(i, 1, T) solve(i);
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e5+10;
int n,m,a[N],ans[N],c[N],x[N],y[N];
pa b[N];
vector<pa>e[N];

int cnt,vis[N];
bool flag[N];
inline void dfs(int u){
	vis[u]=cnt;
	for (auto v:e[u]) if (!vis[v.fi]&&a[v.fi]==a[u]) flag[v.se]=1,ans[v.se]=a[u],dfs(v.fi);
}

vector<int>vec;
bool _vis[N];
inline void Dfs1(int u){
	vec.pb(u),_vis[u]=1;
	for (auto v:e[u]) if (!_vis[v.fi]&&flag[v.se]&&a[v.fi]==a[u]) Dfs1(v.fi);
}
inline void Dfs2(int u){
	for (auto v:e[u]) if (c[v.fi]==-1&&flag[v.se]&&a[v.fi]==a[u]) c[v.fi]=c[u]^1,Dfs2(v.fi);
}

int main(){
	n=read(),m=read();
	For(i,1,n) a[i]=read(),b[i]=mp(a[i],i);
	For(i,1,m){
		int x=read(),y=read();
		e[x].ep(y,i),e[y].ep(x,i);
		::x[i]=x,::y[i]=y;
	}
	For(i,1,n) if (!vis[i]){
		++cnt,dfs(i);
	}
	fil(c,-1);
	For(i,1,m) if (vis[x[i]]!=vis[y[i]]){
		ans[i]=max(a[x[i]],a[y[i]]),flag[i]=1;
	}
	sort(b+1,b+1+n);
	For(i,1,n) if (!_vis[b[i].se]){
		vec.clear(),Dfs1(b[i].se);
		bool Flag=0;
		for (auto j:vec){
			bool flag=0;
			for (auto v:e[j]) if (a[v.fi]<a[j]){
				c[j]=c[v.fi]^1,Dfs2(j);
				flag=Flag=1;break;
			}
			if (flag) break;
		}
		if (!Flag) c[b[i].se]=0,Dfs2(b[i].se);
	}
	For(i,1,n){
		bool flag=0;
		for (auto v:e[i]) if (ans[v.se]==a[i]&&c[v.fi]!=c[i]){
			flag=1;break;
		}
		if (!flag) return puts("-1"),0;
	}
	For(i,1,n) printf("%c",c[i]==0?'W':'B');puts("");
	For(i,1,m) printf("%d\n",ans[i]==0?1000000000:ans[i]);
}

Measured memory_bytes: 19872
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define rrep(i , n , a) for (int i = n - 1 ; i >= a ; i--)
#define ms(arr , val) memset(arr , val , sizeof(arr))
#define siz(temp) temp.size()
#define len(temp) temp.length()
#define timepass 1073741824
#define int ll

signed main()
{
    int n;
    cin >> n;
    int arr[n][3];
    rep(i , 0 , n)
        rep(j , 0 , 3)
            cin >> arr[i][j];
    int dp[n][3];
    ms(dp , 0);
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];
    for (int i = 1 ; i < n ; i++)
    {
        dp[i][0] = max(dp[i - 1][1] , dp[i - 1][2]) + arr[i][0];
        dp[i][1] = max(dp[i - 1][0] , dp[i - 1][2]) + arr[i][1];
        dp[i][2] = max(dp[i - 1][1] , dp[i - 1][0]) + arr[i][2];
    }
    cout << max(dp[n - 1][0] , max(dp[n - 1][1] , dp[n - 1][2])) << endl;
    return 0;
}

Measured memory_bytes: 4992
data = [list(map(int, input().split())) for i in range(3)]

for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            b1 = data[0][0] - a1
            b2 = data[0][1] - a1
            b3 = data[0][2] - a1

            if (
                b1 + a2 == data[1][0]
                and b2 + a2 == data[1][1]
                and b3 + a2 == data[1][2]
                and b1 + a3 == data[2][0]
                and b2 + a3 == data[2][1]
                and b3 + a3 == data[2][2]
            ):
                print("Yes")
                exit(0)

print("No")

Measured memory_bytes: 3064
#AC済み
x,y,z,k=map(int,input().split())
a=sorted([int(i) for i in input().split()])
b=sorted([int(i) for i in input().split()])
c=sorted([int(i) for i in input().split()])
a.sort()
b.sort()
c.sort()
ab=[a[i]+b[j] for j in range(y) for i in range(x)]
ab.sort(reverse=True)
ab=ab[:k]
l=len(ab)
abc=[ab[i]+c[j] for j in range(z) for i in range(l)]
abc.sort(reverse=True)
for i in range(k):
    print(abc[i])


Measured memory_bytes: 161208
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

void printV(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    // input
    int x;
    cin >> x;

    if(x == 3 || x == 5 || x == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N (3009)
#define MOD (1000000007)
using namespace std;

int n,m,x,y,R[N],sum[N],f[N][N];
char s[N];

int main()
{
	cin>>n>>m>>s+1; s[n+1]='0';
	for (int i=1; i<=n+1; ++i)
		R[i]=i, sum[i]=sum[i-1]+s[i]-'0';
	for (int i=1; i<=m; ++i)
		cin>>x>>y, R[x]=max(R[x],y);
	for (int i=2; i<=n+1; ++i)
		R[i]=max(R[i],R[i-1]);
	f[1][sum[R[1]]]=1;
	for (int i=1; i<=n; ++i)
		for (int j=0; j<=n; ++j)
		{
			int k=sum[R[i+1]]-sum[R[i]];
			if (j) (f[i+1][j+k-1]+=f[i][j])%=MOD;
			if (R[i]-i>=j) (f[i+1][j+k]+=f[i][j])%=MOD;
		}
	cout<<f[n+1][0]<<endl;
}

Measured memory_bytes: 35584
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())

    node = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        node[u].append((v, w))
        node[v].append((u, w))

    state = [0 for _ in range(N)]
    visit = [False for _ in range(N)]
    que = queue.Queue()
    que.put((0, 0))
    while not que.empty():
        c, d = que.get()
        if d % 2 == 0:
            state[c] = 1
        visit[c] = True
        for pos, w in node[c]:
            if not visit[pos]:
                que.put((pos, d + w))

    for s in state:
        print(s)


if __name__ == '__main__':
    main()


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

typedef long long ll;
ll n, s, x;
multiset<ll> v;
int main()
{
	ll i, t;
	multiset<ll>::iterator it;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf ("%lld", &t);
		v.insert(t);
	}
	while (!v.empty()) {
		x = *v.rbegin();
		v.erase(v.find(x));
		for (i = 1; i <= x; i *= 2);
		it = v.find(i - x);
		if (it != v.end()) {
			s++;
			v.erase(it);
		}
	}
	cout << s;
    return 0;
}


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

using namespace std;

constexpr int MAXS = 100000, MAXQ = 200000;

char _s[MAXS + MAXQ + 2], _t[MAXQ + 2], *s = _s, *t = _t;

int main() {
	cin >> s;
	int si = strlen(s), ti = 0;
	int Q;
	cin >> Q;
	do {
		char T;
		cin >> T;
		if(T == '1') {
			swap(s, t);
			swap(si, ti);
		} else {
			char F, C;
			cin >> F >> C;
			if(F == '1') t[ti++] = C;
			else s[si++] = C;
		}
	} while(--Q);
	reverse(t, t + ti);
	cout << t << s << '\n';
}


Measured memory_bytes: 768
using System;


class helloworld
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        var a = int.Parse(s[0]);
        var b = int.Parse(s[1]);

           if (a < b)
           {
                Console.WriteLine("a < b");
            }
            if (a > b)
            {
                Console.WriteLine("a > b");
            }
            if (a == b)
            {
                Console.WriteLine("a == b");
            }

    }
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<char>P(N),Q(N);
  for(int i=0;i<N;i++)cin>>P[i];
  for(int i=0;i<N;i++)cin>>Q[i];

  string P_="";
  for(auto it:P)P_+=it;
  string Q_="";
  for(auto it:Q)Q_+=it;

  vector<string>PP;
  sort(rng(P));
  do{
    string p="";
    for(auto it:P)p+=it;
    PP.push_back(p);
  }while(next_permutation(rng(P)));
  int pc,qc;
  for(int i=0;i<PP.size();i++){
    if(P_==PP[i])pc=i;
    if(Q_==PP[i])qc=i;
  }
  cout<<abs(pc-qc)<<endl;
  return 0;
}


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

int main() {
  string u;
  char h,j;
  int len,deff = 0;
  cin >> u;
  h = 'h';
  j = 'i';
  len = u.length();
  if (len % 2 == 1)
  {
    deff = 1;
  }
  for (int i = 0; i < len; ++i)
  {
    if (i % 2 == 0) {
      if (u[i] != h) {
        deff = 1;
      } 
    } else {
      if (u[i] != j) {
        deff = 1;
      } 
    }
  }
  if (deff == 0)
  {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair

#define all(x) (x).begin(),(x).end()
#define FOR(x) for(ll i = 0;i < x;++i)

using namespace std;
typedef long long ll;

int main() {
  ll N,M;
  cin>>N>>M;
  ll *A = new ll[N];
  for(ll i = 0;i < N;++i)cin>>A[i];
  vector<pair<ll,ll> > CB(M);
  for(ll i = 0;i < M;++i){
    cin>>CB[i].second;
    cin>>CB[i].first;
  }
  
  sort(all(CB),greater<pair<ll,ll> >());
  sort(A,A+N);
  bool isBigger = true;
  ll counter = 0; 
  for(ll i = 0;i < N;++i){
    for(ll j = 0;j < CB[i].second;++j){
      if(counter + j >= N)break;
      if(A[counter+j] < CB[i].first){
        A[counter+j] = CB[i].first;
      }else isBigger = false;
    }
    counter += CB[i].second;
    if(!isBigger)break;
  }
  ll ans = 0;
  for(ll i = 0;i < N;++i)ans += A[i];

  cout<<ans;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T> 
map<T, ll> factorize(T x){//mapを返す関数
  map<T, ll> res;
  for(ll i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;//xが素数だった時用
  return res;
}


const int MAX = 1000010;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

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

  ll n,l=1;cin>>n;
  map<ll,ll> ins;

  V<ll> v(n);
  rep(i,0,n){
    cin>>v[i];
    auto u=factorize(v[i]);
    for(auto&& j:u){
      if(ins.count(j.fs))chmax(ins[j.fs],j.sc);
      else ins[j.fs]=j.sc;
    }
  }

  ll ans=0;
  for(auto&& i:ins){
    rep(j,0,i.sc){
      l*=i.fs;
      l%=mod;
    }
  }

  rep(i,0,n){
    ans+=l*inv[v[i]];
    ans%=mod;
  }
  cout<<ans<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 24448
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c,d; 
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
	n=read(),a=read(),b=read(),c=read(),d=read();
	int x=b-a;
	for(int len=0;len<n;++len){
		long long minn=1ll*(n-len-1)*c-1ll*d*len,maxn=1ll*(n-len-1)*d-1ll*c*len;
		//printf("%d %d %d\n",len,minn,maxn);
		if(minn<=x&&maxn>=x){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
}

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

const ll MX = 1e18; //10の18乗

int main(){
    ll  sum=1;
    int n;
    bool ng = false;
    cin >> n;
    
    for(int i=0;i<n;i++){
       ll  arr;
       cin >> arr;
       if(arr == 0){
           cout << 0 << endl;
           return 0;
       }
       if (ng || MX/sum < arr){
           ng = true;
       }
       
       sum = sum * arr;
    }
   
     
    // if (sum > 1000000000000000000 || sum < 0){
    //     sum = -1;
    // }
    if(ng) cout << -1 << endl;
    else cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3616
from collections import defaultdict

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            if self.same_check(x, y) != True:
                self.size[y] += self.size[x]
                self.size[x] = 0
            self.par[x] = y
        else:
            if self.same_check(x, y) != True:
               self.size[x] += self.size[y]
               self.size[y] = 0
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
               self.rank[x] += 1

    def siz(self, x):
        x = self.find(x)
        return self.size[x]

def getlist():
    return list(map(int, input().split()))

N, M = getlist()
U = UnionFind(N)
for i in range(M):
    X, Y, Z = getlist()
    U.union(X, Y)

D = defaultdict(int)


for i in range(1, N + 1):
    n = U.find(i)
    D[n] += 1

print(len(D))

Measured memory_bytes: 20992
#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;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int n_max = 504;



signed main(){
    int n,m;
    cin >> n >> m;
    int G[n_max][n_max];
    REP(i,n) REP(j,n) G[i][j] = INF;
    int dist[n_max][n_max];
    REP(i,n) REP(j,n) dist[i][j] = INF;
    REP(i,n) dist[i][i] = 0;
    REP(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a --;
        b --;
        G[a][b] = c;
        G[b][a] = c;
        dist[a][b] = c;
        dist[b][a] = c;
    }



    REP(i,n){
        REP(j,n){
            REP(k,n){
                chmin(dist[j][k],dist[j][i] + dist[i][k]);
            }
        }
    }
    int cnt = 0;
    REP(i,n){
        REP(j,n){
            if(G[i][j] == INF) continue;
            else if(dist[i][j] < G[i][j]) cnt ++ ;
        }
    }
    cout << cnt / 2 << endl;
}

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

using namespace std;

long long h, w;
long long res = 1e18;

long long max(long long a, long long b, long long c) {
    return max(a, max(b ,c));
}

long long min(long long a, long long b, long long c) {
    return min(a, min(b ,c));
}

int main() {
    cin >> h >> w;
    for (long long i = 1; i < w; ++i) {
        long long a = i * h, b, c;
        if (h % 2 == 0) b = c = (w - i) * (h / 2);
        else b = (w - i) * (h / 2), c = (w - i) * (h / 2 + 1);
        res = min(res, max(a, b, c) - min(a, b, c));
        if ((w - i) % 2 == 0) b = c = h * ((w - i) / 2);
        else b = h * ((w - i) / 2), c = h * ((w - i) / 2 + 1);
        res = min(res, max(a, b, c) - min(a, b, c));
    }
    for (long long i = 1; i < h; ++i) {
        long long a = i * w, b, c;
        if (w % 2 == 0) b = c = (h - i) * (w / 2);
        else b = (h - i) * (w / 2), c = (h - i) * (w / 2 + 1);
        res = min(res, max(a, b, c) - min(a, b, c));
        if ((h - i) % 2 == 0) b = c = w * ((h - i) / 2);
        else b = w * ((h - i) / 2), c = w * ((h - i) / 2 + 1);
        res = min(res, max(a, b, c) - min(a, b, c));
    }
    cout << res << "\n";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    int sum = 0;
    for (size_t i = 0; i < s.length(); i++)
        if (s[i] != t[i])
            sum++;
    cout << sum << endl;
    return 0;
}


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

using namespace std;



int main()
{
	priority_queue<int> q;
	char s[20];
	int  n;
	while(scanf("%s",s)!=EOF)
	{
	    if(strcmp(s,"insert")==0)
		{
			scanf("%d",&n);
			q.push(n);
		}
		else if(strcmp(s,"extract")==0)
		{
			printf("%d\n",q.top());
			q.pop();
		}
		else if(strcmp(s,"end")==0) break;
	}
	return 0;
}






Measured memory_bytes: 6896
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;

int MOD=1000000007;

int main(){
  ll N,K,ans=0;
  cin >> N >> K;
  ans=N%K;
  ans=min(ans,abs(ans-K));
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define MOD 1000000007
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;
typedef unordered_map<int, int> Hash;

// ---
int N, M, Q;
const int Qm = 50;
int a[Qm], b[Qm], c[Qm], d[Qm];
const int Nm = 10;
int A[Nm];

int Ans(int i) {
  if (i == N-1) {
    int ans = 0;
    FOR(x, A[i-1], M) {
      int newans = 0;
      A[i] = x;
      // REP(k, N) {
      //   cout << A[k] << " ";
      // }
      // cout << endl;
      REP(j, Q) {
        if (A[b[j]-1] - A[a[j]-1] == c[j]) {
          newans += d[j];
        }
      }
      ans = MAX(ans, newans);
    }
    return ans;
  }

  int ans = 0;
  FOR(x, A[i-1], M) {
    A[i] = x;
    ans = MAX(ans, Ans(i+1));
  }
  return ans;
}

signed main() {
  cin >> N >> M >> Q;
  REP(i, Q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  A[0] = 1;
  auto ans = Ans(1);

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


Measured memory_bytes: 3192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class72
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            int a = N % 2;
            Console.WriteLine(N / 2 + a);
        }
    }
}


Measured memory_bytes: 13140
n,a,b=map(int,input().split())
s = input()

cnt_s = 0
cnt_b = 0

for i in range(len(s)):
    if s[i] == 'a' and cnt_s < a+b:
        print('Yes')
        cnt_s += 1
    elif s[i] == 'a' and cnt_s > a+b:
        print('No')
    elif s[i] =='b' and cnt_s < a+b and cnt_b < b:
        print('Yes')
        cnt_b += 1
        cnt_s += 1
    else:
        print('No')
    

Measured memory_bytes: 53208
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

ll gcd(ll a, ll b) {
  if (b == 0) { return a; }
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

//a x + b y = gcd(a, b)
long long extgcd(long long a, long long b, long long &x, long long &y) {
  long long g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

long long InvMod(long long a, long long mod) {
  long long x, y;
  if (extgcd(a, mod, x, y) == 1) { return (x + mod) % mod; }
  return 0;
}

pair<ll, ll> LinearCongruence(const vector<ll> &A, const vector<ll> &B, const vector<ll> &M) {
  ll x = 0;
  ll m = 1;
  for (ll i = 0; i < (ll)A.size(); i++) {
    ll a = A[i] * m;
    ll b = B[i] - A[i] * x;
    ll d = gcd(M[i], a);
    if (b % d != 0) { return make_pair(0, -1); }
    ll t = b / d * InvMod(a / d, M[i] / d) % (M[i] / d);
    x = x + m * t;
    m *= M[i] / d;
  }
  x %= m;
  if (x < 0) { x += m; }
  return make_pair(x % m, m);
}

ll solve(ll l1, ll l2, ll r1, ll r2, ll m1, ll m2) {
  vector<ll> a, b, m;
  if (l1 == 0 && r1 != 0) { return -1; }
  if (l2 == 0 && r2 != 0) { return -1; }

  if (l1 != 0) {
    a.push_back(l1);
    b.push_back(r1);
    m.push_back(m1);
  }
  if (l2 != 0) {
    a.push_back(l2);
    b.push_back(r2);
    m.push_back(m2);
  }
  if (a.size() == 0) { return 1; }
  pair<ll, ll> nret = LinearCongruence(a, b, m);
  if (nret.second > 0) {
    if (nret.first == 0) { nret.first += nret.second; }
    return nret.first;
  }
  return -1;
}

ll n, m, a, b, c, d;
int main() {
  while (scanf("%lld %lld %lld %lld %lld %lld", &m, &n, &a, &b, &c, &d) > 0) {
    a %= m; c %= m;
    b %= n; d %= n;
    ll e = 0;
    if (a == 0 && b == 0) {
      swap(a, c);
      swap(b, d);
    }
    if (a == 0 && b == 0) {
      puts("0");
      continue;
    } else if (a == 0) {
      e = n / gcd(b, n);
    } else if (b == 0) {
      e = m / gcd(a, m);
    } else {
      e = lcm(m / gcd(a, m), n / gcd(b, n));
    }
    if (c == 0 && d == 0) {
      printf("%lld\n", e - 1);
      continue;
    }
    
    ll sqnm = sqrt(n * m) + EPS;
    ll f = 1LL << 60;
    if (e <= sqrt(n * m)) {
      REP(g, e) {
        ll v = solve(c, d, g * a % m, g * b % n, m, n);
        if (v == -1) { continue; }
        assert(v > 0);
        f = min(f, v);
      }
    } else {
      f = 1;
      FOREQ(i, 1, sqnm + 5) {
        ll v = solve(a, b, i * c % m, i * d % n, m, n);
        if (v == -1) { continue; }
        f = i;
        break;
      }
    }
    printf("%lld\n", e * f - 1);
  }
}

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


int main(void){
    // 自分の得意な言語で
    // Let's チャレンジ！！

    string str;
    int N;
    int count = 0;
    while(getline(cin, str)){
        stringstream ss;
        ss << str;
        ss >> N;
        break;


        count++;
    }





    cout << N * (N + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    ll a, b, n;
    cin >> a >> b >> n;

    ll duh = min(b-1, n);
    cout << (a*duh)/b - a*(duh/b) << "\n";
}


Measured memory_bytes: 3624