akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////
int N, M, Q;

vector<vector<int> > A;
vector<int> B;

bool next() {
	int c = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (B[i] + 1 <= M) {
			B[i]++;
			for (int j = i + 1; j < N; ++j) {
				B[j] = B[i];
			}
			return true;
		}
	}
	return false;
}
void solve() {
	
	cin >> N >> M >> Q;
	B = vector<int>(N, 1);
	A = vector<vector<int> >(Q, vector<int>(4));
	for (int i = 0; i < Q; ++i) {
		cin >> A[i][0] >> A[i][1] >> A[i][2] >> A[i][3];
		A[i][0]--;
		A[i][1]--;
	}
	
	LL ans = 0;
	do {
		LL res = 0;
		for (int i = 0; i < Q; ++i) {
			if (B[A[i][1]] - B[A[i][0]] == A[i][2]) {
				res += A[i][3];
			}
		}
		chmax(ans, res);
	} while (next());
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,K;
  cin >> N >> K;
  if(K > (N-1)*(N-2)/2){
   cout << -1 << endl; 
  }else{
    int k = (N-1)*(N-2)/2 - K;
    cout << k + N - 1 << endl;
    for(int a = 1;a < N;a++){
      cout << 1 << " " << a + 1 << endl;
      
    }
    int n = 2;
    int m = 2;
    for(int a = 0;a < k;a++){
      m++;
      if(m == n)m++;
      if(m > N){
        m = n + 2;
        n++;
      }
      cout << n << " " << m << endl;
      
    }
    
  }
}

Measured memory_bytes: 3612
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

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

    vector<int> x;
    for(int i = 0; i < m; i++){
        int tmp;
        cin >>tmp;
        x.push_back(tmp);
    }

    sort(x.begin(), x.end());

    vector<int> diff;
    for(int i = 1; i < m; i++){
        diff.push_back(abs(x[i-1] - x[i]));
    }
    sort(diff.begin(), diff.end(), greater<int>());

    int ans = 0;
    for(int i = 0; i < m-1; i++){
        if(n > 1){
            n--;
            continue;
        }
        ans += diff[i];
    }

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

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
//vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main(){
    long long int n;
    string tmp;
    long long int ac = 0;
    long long int wa = 0;
    long long int tle = 0;
    long long int re = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> tmp;
        if(tmp == "AC"){
            ac++;
        }
        if(tmp == "WA"){
            wa++;
        }
        if(tmp == "TLE"){
            tle++;
        }
        if(tmp == "RE"){
            re++;
        }

    }
    cout << "AC" << " " << "x" << " " << ac << endl;
    cout << "WA" << " " << "x" << " "<< wa << endl;
    cout << "TLE" << " " << "x" << " "<< tle <<endl;
    cout << "RE" << " " << "x" << " "<< re <<endl;
}

Measured memory_bytes: 3628
#include<stdio.h> 
int main(void) { 
  int a,b,c,count,i;
  scanf("%d %d %d",&a,&b,&c);
  count=0;
  for(i=a;i<=b;i++)
    if((c%i)==0)count++;
  printf("%d\n",count);
  return 0;
}

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

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

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
int f(int x, int y, int nx, int ny, vvi &v) {
	int ret=v[nx][ny] - v[x][ny] - v[nx][y] + v[x][y];
	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vvi b(2 * k + 1, vi(2 * k + 1, 0)), w(2 * k + 1, vi(2 * k + 1, 0));
	REP(i, n) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		x %= 2 * k;
		y %= 2 * k;
		if (c == 'B')b[y + 1][x + 1]++;
		else w[y + 1][x + 1]++;
	}
	REP(i, 2 * k) {
		REP(j, 2 * k + 1) {
			b[i + 1][j] += b[i][j];
			w[i + 1][j] += w[i][j];
		}
	}
	REP(i, 2 * k + 1) {
		REP(j, 2 * k) {
			b[i][j + 1] += b[i][j];
			w[i][j + 1] += w[i][j];
		}
	}
	int ans = 0;
	REP(i, k) {
		REP(j, k) {
			int cntb, cntw;
			cntw = f(0, 0, i, j, w) + f(i, j, i + k, j + k, w) + f(0, j + k, i, 2 * k, w) + f(i + k, 0, 2 * k, j, w) + f(i + k, j + k, 2 * k, 2 * k, w);
			cntb = f(0, j, i, j + k, b) + f(i, 0, i + k, j, b) + f(i, j + k, i + k, 2 * k, b) + f(i + k, j, 2 * k, j + k, b);
			ans = max(ans, cntb + cntw);
			cntb = f(0, 0, i, j, b) + f(i, j, i + k, j + k, b) + f(0, j + k, i, 2 * k, b) + f(i + k, 0, 2 * k, j, b) + f(i + k, j + k, 2 * k, 2 * k, b);
			cntw = f(0, j, i, j + k, w) + f(i, 0, i + k, j, w) + f(i, j + k, i + k, 2 * k, w) + f(i + k, j, 2 * k, j + k, w);
			ans = max(ans, cntb + cntw);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 31744
from itertools import combinations

N, X, Y = map(int, input().split())
count = [0] * N
for i, j in combinations(range(1, N+1), 2):
    k = min(j - i, abs(X - i) + 1 + abs(Y - j))
    count[k] += 1
print(*count[1:], sep='\n')

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

int main()
{
   int N, M, m, A, B = 0;
   vector<int> v;
   
   cin >> N >> M;
   m = M - 1;
   
   for(int i = 0;i < M;i++){
        cin >> A >> B;
        if(A >= N){
            m--;
        }else{
            v.push_back(N - A);
        }
   }
   
   sort(v.begin(), v.end());
   
   int r = 0;
   for(int i = 0;i < m;i++){
       r += v.at(i);
   }
   
   cout << r << endl;
   
   return 0;
}

Measured memory_bytes: 3144
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion


LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 



/*****************************************************************************/

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

	int n, m;
	cin >> n >> m;
	cout << pow(2,m)*(1900 * m + 100 * (n - m));
	return 0;
}

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

num = [0]*(10**5+1)

sum = sum(A)
for i in range(N):
  num[A[i]-1] += 1

for _ in range(Q):
  b,c=map(int,input().split())
  sum += (c-b)*num[b-1]
  num[c-1] += num[b-1]
  num[b-1] = 0
  
  print(sum)

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

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int main()
{
  int h, w, k;
  std::cin >> h >> w >> k;
  std::vector<int> row(h, 0);
  std::vector<int> column(w, 0);
  std::vector<std::vector<int> > matrix(h, std::vector<int>(w, 0));
  int sum = 0;
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      char c;
      std::cin >> c;
      if (c == '#')
      {
        row[i]++;
        column[j]++;
        matrix[i][j]++;
        sum++;
      }
    }
  } 
  int ans = 0;
  if (k == sum)
  {
    ans++;
  }
  for (int i = 1; i <= h; ++i)
  {
    foreach_comb(h, i, [&](int *indexes)
    {
      int rowSum = 0;
      for (int j = 0; j < i; ++j)
      {
        rowSum += row[indexes[j]];
      }
      if (rowSum + k == sum)
      {
        ans++;
      }
    });
  }
  
  for (int i = 1; i <= w; ++i)
  {
    foreach_comb(w, i, [&](int *indexes)
    {
      int columnSum = 0;
      for (int j = 0; j < i; ++j)
      {
        columnSum += column[indexes[j]];
      }
      if (columnSum + k == sum)
      {
        ans++;
      }
    });
  }

  for (int i = 1; i <= h; ++i)
  {
    foreach_comb(h, i, [&](int *indexes)
    {
      int rowSum = 0;
      for (int j = 0; j < i; ++j)
      {
        rowSum += row[indexes[j]];
      }
      
      for (int l = 1; l <= w; ++l)
      {
        foreach_comb(w, l, [&](int *indexes2)
        {
          int columnSum = 0;
          for (int j = 0; j < l; ++j)
          {
            columnSum += column[indexes2[j]];
          }
          int matrixSum = columnSum + rowSum;
          for (int rowCount = 0; rowCount < i; ++rowCount)
          {
            for (int columnCount = 0; columnCount < l; ++columnCount)
            {
              if (matrix[indexes[rowCount]][indexes2[columnCount]] > 0)
              {
                matrixSum--;
              }
            }
          }

          if (matrixSum + k == sum)
          {
            
            ans++;
          }
          matrixSum = 0;
        });
      }
    });
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<bits/locale_facets.h>
#include<algorithm>
using namespace std;
int answer[501][501];
long long input();
void output(long long value);
int main()
{
	int H=input(),W=input(),h=input(),w=input(),k,v,sum=0;
	if(!(H%h)&&!(W%w))return puts("No"),0;
	k=250000/(h*w),v=-k*(h*w-1)-1;
	for(int i=1;i<=H;i++)
	for(int j=1;j<=W;j++)
	{
		if(!(i%h)&&!(j%w))answer[i][j]=v;
		else answer[i][j]=k;
		sum+=answer[i][j];
	}
	if(sum>0)
	{
		puts("Yes");
		for(int i=1;i<=H;i++)
		{
			for(int j=1;j<W;j++)
			output(answer[i][j]),putchar(' ');
			output(answer[i][W]),putchar('\n');
		}
		return 0;
	}
	else return puts("No"),0;
}
long long input()
{
	long long value=0,positive=1;
	char digit=getchar();
	for(;!isdigit(digit);digit=getchar())
	if(digit=='-')positive=-positive;
	for(;isdigit(digit);digit=getchar())value=(value<<3)+(value<<1)+digit-'0';
	return positive*value;
}
void output(long long value)
{
	if(value<0)
	{
		putchar('-');
		value=-value;
	}
	if(value>=10)output(value/10);
	putchar(value%10+'0');
}

Measured memory_bytes: 2944
import itertools

S = input()


def calculate(s):
    arr = list(s)

    totalLength = len(s)

    spliteIndexes = [i for i in range(1,totalLength)]

    result = 0
    for i in range(1, totalLength):
        for item in itertools.combinations(spliteIndexes, i):
            ttr = [0]
            ttr.extend(list(item))
            ttr.append(totalLength)


            for i in range(len(ttr) - 1):
                result += int("".join(arr[ttr[i]:ttr[i+1]]))
    print(result + int(s))


calculate(S)




Measured memory_bytes: 9076
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class AAddtion
    {
        public static void Main(string[] args)
        {
            new AAddtion().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var list = cin.ReadIntArray(3);

            var ans = Min(list[0] * list[1],list[2]);

            WriteLine(ans);

        }
    }
}
public class ConsoleInput
{
    private readonly System.IO.TextReader _stream;
    private char _separator = ' ';
    private Queue<string> inputStream;
    public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
    {
        this._separator = separator;
        this._stream = stream;
        inputStream = new Queue<string>();
    }
    public string Read
    {
        get
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(_separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
    }
    public string ReadLine { get { return _stream.ReadLine(); } }
    public int ReadInt { get { return int.Parse(Read); } }
    public long ReadLong { get { return long.Parse(Read); } }
    public double ReadDouble { get { return double.Parse(Read); } }
    public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll dp[70][2][2][3];
ll a[400];

int main(){
	int n;cin>>n;
	ll X=0;
	rep(i,n){
		scanf("%lld",&a[i]);
		if(i>=2)X^=a[i];
	}
	ll S=a[0]+a[1];
	memset(dp,-1,sizeof(dp));
	dp[0][0][0][1]=0;
	rep(i,60)rep(j,2)rep(k,2)rep(t,3){
		ll d=dp[i][j][k][t];
		if(d==-1)continue;
		//~ cerr<<i<<' '<<j<<' '<<k<<' '<<t<<' '<<d<<endl;
		for(int l=0;l<=1;l++){
			int m=(X>>i&1)^l;
			if((l^m^j)!=(S>>i&1))continue;
			int nt=-1;
			if(t==0){
				if(l<=(a[0]>>i&1))nt=0;
				else nt=2;
			}
			else if(t==1){
				if(l<(a[0]>>i&1))nt=0;
				else if(l==(a[0]>>i&1))nt=1;
				else nt=2;
			}
			else{
				if(l<(a[0]>>i&1))nt=0;
				else nt=2;
			}
			int nj=(j+l+m>=2);
			dp[i+1][nj][k||l][nt]=max(dp[i+1][nj][k||l][nt],d+(l==1?(1LL<<i):0));
		}
	}
	ll res=max(dp[60][0][1][0],dp[60][0][1][1]);
	if(res==-1)puts("-1");
	else cout<<a[0]-res<<endl;
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
#include<iomanip>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
  int n,a,b,c,d;
  cin>>n;
  a=n/1000;b=(n/100)%10;
  c=(n%100)/10;d=n%10;
  if(a+b+c+d==7)
  cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<'='<<7<<endl;
  else if(a+b+c-d==7)
  cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<'='<<7<<endl;
  else if(a+b-c+d==7)
  cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<'='<<7<<endl;
  else if(a+b-c-d==7)
  cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<'='<<7<<endl;
  else if(a-b+c+d==7)
  cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<'='<<7<<endl;
  else if(a-b+c-d==7)
  cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<'='<<7<<endl;
  else if(a-b-c+d==7)
  cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<'='<<7<<endl;
  else if(a-b-c-d==7)
  cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<'='<<7<<endl;
}


Measured memory_bytes: 256
H, W, M = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = set()
for i in range(M):
    hh, ww = map(int, input().split())
    h[hh - 1] += 1
    w[ww - 1] += 1
    DP.add((hh - 1, ww - 1))

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0

for i in hhhh:
    for j in wwww:
        if (i, j) not in DP:
            print(hhh + www)
            exit()
print(hhh + www - 1)


Measured memory_bytes: 83380
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(void) {
	ll mod = 1000000007;
	ll N, K;
	cin >> N >> K;
	ll cnt = 0;
	for (ll k = K; k <= N + 1; k++) {
		cnt += N * k - k * k + k + 1;
		cnt = cnt % mod;
	}
	cout << cnt << endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

int main()
{   
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0, r = 0;
    ll x = 0, sum = 0;
    rep(l, n) {
        while(r < n && ((x^a[r]) == (sum+a[r]))) {
            x ^= a[r];
            sum += a[r];
            //cout << "test : "<< x << " " << sum << endl;
            r++;
        }
        //cout << l << " " << r << endl;
        ans += (r-l);
        if(l >= r) r++;
        else {
            x ^= a[l];
            sum -= a[l];
        }
    }

    cout << ans << endl;

    return 0;
}


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

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

    int n;
    long long w, w_arr[100], v_arr[100], v, final_ans; // (W+1)
    cin >> n >> w;
    v = 0;
    for (int i = 0; i < n; i++) {
        cin >> w_arr[i] >> v_arr[i];
        v += v_arr[i];
    }
    long long dp[v+1];
    dp[0] = 0;
    fill(dp+1, dp+v+1, INT_MAX);
    final_ans = 0;
    for (int i = 0; i < n; i++) {
        for (long long j = v; j >= v_arr[i]; j--) {
            dp[j] = min(dp[j], w_arr[i] + dp[j-v_arr[i]]);
            if (dp[j] <= w) {
                final_ans = max(final_ans, j);
            }
        }
    }
    cout << final_ans;

    return 0;
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

void solve(std::string s)
{
    int start, end;
    for (size_t i = 0; i < s.size(); i++)
    {
        if (s[i] == 'Z')
        {
            end = i;
        }
        if (s[s.size() - 1 - i] == 'A')
        {
            start = s.size() - 1 - i;
        }
    }

    cout << end - start + 1 << endl;
}

int main()
{
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


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

int main() {
  int n , m ;
  cin >> n >> m;
  vector<int> vec(m);
  for(int i=0;i<m;i++){
    int a;
    cin >> a;
    vec[i]=a;
  }
  int ans=0;
  int min=100;
  for(int i=0;i<102;i++){
    bool hant=1;
	for(int j=0;j<m;j++){
      if(vec[j]==i)
        hant=0;
    }
    if(hant){
      if(abs(n-i)<min){
        min=abs(n-i);
        ans=i;
      }
    }
  }
  cout << ans << endl;
}


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

class UnionFind
{
    vector<int> par, rank, sz;

public:
	UnionFind(int n){
        par.resize(n);
        rank.resize(n);
        sz.resize(n);
		for (int i = 0; i < n; i++){
			par[i] = i;
			rank[i] = 0;
			sz[i] = 1;
		}
	}

	int find(int x){
		if (x == par[x]) return x;
		else return par[x] = find(par[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}
		else{
			par[y] = x;
			sz[x] += sz[y];
			if (rank[x] == rank[y]) rank[x]++;
		}
	}

	int size(int x){
		return sz[find(x)];
	}
    
	bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind uf(m);
    bool u[100002] {0};
    int k[100002];
    for(int i = 0; i < n; i++){
        cin >> k[i];
        int l[100002];
        for(int j = 0; j < k[i]; j++){
            cin >> l[j];
            l[j]--;
            u[l[j]] = true;
            if(j > 0) uf.unite(l[j], l[j - 1]);
        }
    }
    int s = 0;
    for(int i = 0; i < m; i++) if(!u[i]) s++;
    int i = 0;
    for(; i < m; i++) if(u[i]) break;
    if(uf.size(i) == m - s) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 1920
#include<iostream>
#include<stdlib.h>

using namespace std;

int compare_int(const void *a, const void *b)
{
    return  *(int*)b - *(int*)a ;
}

int main(){
    int N;
    int A[100000];
    long long A1;
    long long A2;
    int flag = 0;
    cin >> N;

    for(int i=0;i<N;i++)
        cin >> A[i];
    
    qsort(A, N, sizeof(int), compare_int);

    for(int i=0;i<N;i++){
        if(A[i]==A[i+1] && flag==1){
            A2 = (long long)(A[i]);
            cout << A2*A1;
            return 0;
        }
        if(A[i]==A[i+1] && flag==0){
            A1 = (long long)(A[i]);
            i++;
            flag = 1;
        }
    }
    cout << '0';
    return 0;
}

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


void solve(long long N, std::vector<long long> a){
    long long alice = 0;
    long long bob = 0;
    sort(a.begin(), a.end(), greater<long long>());
    for(int i = 0; i < a.size(); ++i){
        if(i % 2 == 0) alice = alice + a[i];
        else bob = bob + a[i];
    }
    cout << alice - bob << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 1e9
#define PI (acos(-1))
#define MAX_N 2*1e5
ll n,k;
vector<ll> a,f;
bool solve(ll t){
    ll K=k;
    REP(i,n){
        if(a[i]*f[i]>t){
            K-=(a[i]-t/f[i]);
            if(K<0)return false;
        }
    }
    return true;
}
int main() {
    cin>>n>>k;
    ll x;
    REP(i,n){
        cin>>x;
        a.push_back(x);
    }
    REP(i,n){
        cin>>x;
        f.push_back(x);
    }
    sort(all(a));
    sort(all(f),greater<ll>());
    ll ng=-1,ok=1e12,mid;
    while(abs(ok-ng)>1){
        mid=(ok+ng)/2;
        if(solve(mid))ok=mid;
        else ng=mid;
    }
    cout<<ok<<endl;
    return 0;
}

Measured memory_bytes: 6384
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
c = 0
for n in range(N):
  if n == 0:
    c += min(A[0], B[0])
    temp = c
  else:
    c += min(A[n] - temp, B[n])
    temp = min(A[n] - temp, B[n])
  c += min(A[n+1], B[n] - temp)
  temp = min(A[n+1], B[n] - temp)
print(c)

Measured memory_bytes: 18476
#include <stdio.h>
#include <stdlib.h>

int main(){
    int i = 0, j = 0;
    int n;
    scanf("%d", &n);
    char *c=malloc(sizeof(char)*n+10);
    scanf("%s", c);

    int cnt = 0;
    while(i+j<n-1){
        while(c[i]=='R'){
            i++;
        }
        while(c[n-j-1]=='W'){
            j++;
        }
        c[i] = 'R';
        c[n-j-1] = 'W';
        cnt++;
    }
    printf("%d", cnt-1);
    return 0;
}

Measured memory_bytes: 1896
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
typedef long double ld;
const ld eps = 1e-8;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define stop char nyaa;cin>>nyaa;
//x,yがax+by=gcd(a,b)の解になる
ll extgcd(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}
//aのmod mでの逆元を求める
ll mod_inverse(ll a, ll m) {
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}
const int N_MAX = 1 << 18;
ll p[N_MAX];
void init() {
	p[0] = 1;
	rep1(i, N_MAX - 1) {
		p[i] = p[i - 1] * i%mod;
	}
}
//xCyを求める
ll comb(ll x, ll y, ll m) {
	if (x < y)return 0;
	ll res = p[x];
	(res *= mod_inverse(p[y], m)) %= mod;
	(res *= mod_inverse(p[x - y], m)) %= mod;
	return res;
}
int main(){
	init();
	int n; ll m; cin >> n >> m;
	if (m == 1) {
		cout << 1 << endl; return 0;
	}
	queue<int> q;
	for (ll i = 2; i < 100000; i++) {
		if (m%i == 0) {
			int cnt = 0;
			while (m%i == 0) {
				m /= i; cnt++;
			}
			q.push(cnt);
		}
	}
	if (m > 1)q.push(1);
	ll out = 1;
	while (!q.empty()) {
		ll x = q.front(); q.pop();
		(out *= comb(x + n - 1, x, mod)) %= mod;
	}
	cout << out << endl;
	return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>

using namespace::std;

int main(void){
  string input;

  cin >> input;

  bool f = true;
  if(input[0]!='A') f = false;

  int i;
  int C=0;
  int cnt=0;
  for(i=2;i<input.size()-1;i++){
    if(input[i]=='C'){
      cnt++;
      C=i;
    }
  }
  if(cnt!=1)f=false;

  for(i=1;i<input.size();i++){
    if('A'<=input[i] && input[i] <= 'Z' && i!=C) f=false;
  }

  if(f) cout << "AC" << endl;
  else cout << "WA" << endl;



  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 reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

int calc(int A,int B){
    int tmp=0;
    if((B-A)&1){
        tmp+=A-1;
        B-=tmp;
        A-=tmp;
        tmp++;
        B--;
    }
    return tmp+(B-A)/2;
}

signed main(){
    int N,A,B;
    cin>>N>>A>>B;
    

    int ans=calc(A,B);
    swap(A,B);
    A=N-A+1;
    B=N-B+1;
    chmin(ans,calc(A,B));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1, 105):
  for j in range(1, 105):
    for k in range(1, 105):
      v = i * i + j * j + k * k + i * j + j * k + k * i
      if v < 10050:
        ans[v] += 1

for i in range(n):
  print(ans[i + 1])


Measured memory_bytes: 9192
#include <iostream>

using namespace std;

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

    string s;
    cin >> s;

    int cnt = 0;
    for (int i = 0; i + 2 < n; ++i)
        cnt += (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C');

    cout << cnt;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

string s;
int K;

int mem[110][110][3];

int calc(int n,int num,int isunder){
    //cout<<n<<" "<<num<<" "<<a<<" "<<isunder<<endl;
    if(mem[n][num][isunder]!=-1)return mem[n][num][isunder];
    if(n==s.size()){
        if(isunder==0)return 0;
        else {
            if(num==K)return 1;
            else return 0;
        }
    }
    int res=0;
    if(num==K)res++;
    for(int i=0;i<=9;++i){
        if(i==0&&n==0)continue;
        else{
            int _isunder;
            if(isunder==1)_isunder=1;
            else if(isunder==2&&s[n]-'0'==i)_isunder=2;
            else if(isunder==2&&s[n]-'0'>i)_isunder=1;
            else _isunder=0;
            if(i==0)res+=calc(n+1,num,_isunder);
            else res+=calc(n+1,num+1,_isunder);
        }
    }
    return mem[n][num][isunder]=res;
}

int main(){
    for(int i=0;i<110;++i)for(int j=0;j<110;++j)for(int k=0;k<3;++k)mem[i][j][k]=-1;
    cin>>s;
    cin>>K;
    cout<<calc(0,0,2)<<endl;
}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process()throws IOException
    {
        char s[]=nln().toCharArray(),t[]=nln().toCharArray();
        int n=s.length;
        int res=0;
        for(int i=0;i<n;i++) if(s[i]!=t[i]) res++;
        pn(res);
    }
 
 
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new FastReader();
 
        long s = System.currentTimeMillis();
        int t=1;
        //t=ni();
        while(t-->0)
            process();
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }
    
    
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static int ni()throws IOException{return Integer.parseInt(sc.next());}
    static long nl()throws IOException{return Long.parseLong(sc.next());}
    static double nd()throws IOException{return Double.parseDouble(sc.next());}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    
    static long mod=(long)1e9+7l;
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

Measured memory_bytes: 40360
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    vector <int> level(8);
    level[0] = 1800;
    level[1] = 1600;
    level[2] = 1400;
    level[3] = 1200;
    level[4] = 1000;
    level[5] = 800;
    level[6] = 600;
    level[7] = 400;

    int X;
    cin >> X;
    int ans = 9;

    for (int i = 0; i < level.size(); ++i) {
        if (X >= level[i]) {
            ans = i+1;
            break;
        }
    }

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

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long

int main(void){
	ll n,k;
	vector<ll>a,b;
	cin >> n >> k;
	a.resize(n); b.resize(n);
	ll ans = 0;
	for(int i = 0; i < n; ++i){
		cin >> a[i] >> b[i];
		if((a[i]|k) <= k)
			//cout << (a[i]|k)  << endl;
			ans += b[i];
	}
	ll cnt = 0;
	ll tmp = k;
	while(true){
		if(tmp == 0) break;
		tmp /= 2;
		cnt++;
	}
	for(int i = cnt; i >= 0; --i){
		//cout << (k&(1<<i)) << endl;
		if((k & (1<<i))){
			//cout << i << endl;
			ll bit = (1<<i) - 1;
			bit = (bit|k) - (1<<i);
			//cout << bit << endl;
			ll tmp = 0;
			for(int j = 0; j < n; ++j){
				if((bit|a[j]) <= bit){
					tmp += b[j];
				}
			}
			if(ans < tmp){
				ans = tmp;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[110];
    for(int i=0; i < n; i++) cin >> a[i];
    sort(a, a + n, greater<int>());
    int alice = 0;
    int bob = 0;
    for(int i=0; i< n; ++i) {
        if(i % 2 == 0){
            alice += a[i];
        }
        else {
            bob += a[i];
        }
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define fi(s) freopen(s,"r",stdin);
#define fo(s) freopen(s,"w",stdout);
using namespace std;
typedef long long ll;
const int N = 1000000 + 5;
ll read() {
	ll x = 0,f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}
int a[N];
int Min,Max,Minjs,Maxjs;
int main() {
	int n = read();
	Min = N; Max = -1;
	Minjs = Maxjs = 0;
	for(int i = 1;i <= n;++i) {
		a[i] = read();
		Min = min(Min,a[i]); Max = max(Max,a[i]);
	}
	if(Max - Min > 1) {
		puts("No");//continue; ret
		return 0;
	}
	if(Min == Max) {
		if(Min + 1 == n || Min <= (n>>1)) puts("Yes");
		else puts("No");
		return 0;
	}
	for(int i = 1;i <= n;++i) {
		if(a[i] == Min) Minjs++;
		if(a[i] == Max) Maxjs++;
	}
	if(Max <= Minjs) {
		puts("No");
		return 0;
	}
	Max -= Minjs;
	if(Max > (Maxjs >> 1) ) {
		puts("No"); 
		return 0;
	}
	puts("Yes");
	return 0;
}
 
 

Measured memory_bytes: 640
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

string to_string(string s){
  return '"' + s + '"';
}
string to_string(const char *s){
  return to_string((string)s);
}
string to_string(bool b){
  return (b ? "true" : "false");
}
template<class A, class B>
string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template<class A, class B, class C>
string to_string(tuple<A, B, C> p){
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template<class A, class B, class C, class D>
string to_string(tuple<A, B, C, D> p){
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
template<class A>
string to_string(A v){
  bool first = true;
  string res = "{";
  for(const auto &x : v){
    if(!first){
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out(){cerr << endl;}
template<class Head, class... Tail>
void debug_out(Head H, Tail... T){
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL//compile with -DLOCAL
#define debug(...) cerr << "LINE" << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(0)
#endif

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

vector<ll> dist;
vector<bool> visited;
bool dfs(vector<vector<pair<int,ll>>> &graph, int v){
  if(visited.at(v)) return true;
  visited.at(v) = true;
  if(dist.at(v) == -1e18) dist.at(v) = 0;

  rep(i,sz(graph.at(v))){
    int nv = graph.at(v).at(i).fi;
    int c = graph.at(v).at(i).se;
    if(dist.at(nv) == -1e18){
      dist.at(nv) = dist.at(v) + c;
      if(!dfs(graph, nv)) return false;
    }
    else{
      if(dist.at(nv) != dist.at(v) + c) return false;
    }
  }
  return true;
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,M;
  cin >> N >> M;
  vector<vector<pair<int,ll>>> graph(N);
  rep(i,M){
    int l,r,d;
    cin >> l >> r >> d;
    l--;
    r--;
    graph.at(l).p_b(m_p(r, d));
    graph.at(r).p_b(m_p(l, -d));
  }

  dist.resize(N);
  visited.resize(N);
  rep(i,N){
    dist.at(i) = -1e18;
    visited.at(i) = false;
  }
  rep(i,N){
    if(!dfs(graph,i)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 20368
def ten_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

def main():
    N, K = [int(_) for _ in input().split()]
    ans = ten_to_n(N, K)
    print(len(ans))
main()


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

#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)

#define INF LONG_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  int f=0;
  string s;
  cin>>s;
  rep(i,s.length()){
    if(s[i]=='C'){
      f=1;
    }
    if(s[i]=='F' and f==1){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

  cout<<"No"<<endl;
  
  return 0;
}

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

using namespace std;

int n, k, a[200005], b[200005];

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 0 ; i <= k; i++)
        b[i] = 0;
    for (int i = 0; i <= k; i++){
        for (int j = 1; j <= n; j++)
            b[i + a[j]] = max(b[i + a[j]], 1 - b[i]);
    }
    if (b[k] == 1){
        cout << "First";
    } else
        cout << "Second";
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n, d, x;
	cin >> n >> d >> x;
	int ans = n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		ans += (d - 1) / a;
	}
	cout << ans + x << endl;
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T &a){int t = 0;for(auto itr :a){if(t++)cout << " "; cout << itr;} cout <<endl; }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    //    std::ios_base::sync_with_stdio(false);
    //    cin.tie(NULL);
    int a,b,c; cin >> a >> b >> c;
    cout << min(c,b/a) << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char str[101][101];
  int h, w;

  scanf("%d%d", &h, &w);

  for(int i = 0; i < h; i++) scanf(" %s", &str[i]);

  for(int i = 0; i < h+2; i++){
    if(i == 0 || i == h+1 ) for(int j = 0; j < w+1; j++) printf("%s", "#");
    else printf("#%s", str[i-1]);
    printf("%s", "#\n");
  }
}

Measured memory_bytes: 256
///*Bismillahir Rahmanir Rahim***///
/***Stay_Home_Stay_Safe***/
///**Author Thasin Sheikh**///
#include<bits/stdc++.h>
using namespace std;
#define MAX 1e6+10
#define MOD 1000000007
#define PI 3.14159265359
#define makefast__  ios_base::sync_with_stdio(false);
using ll=long long int  ;
using dl =double;
const int N = 2e5 + 10;
ll aarray[200000+10];
ll magic[101][101];
vector<ll>v;
bool prime[1000001];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    makefast__
    string str;
    ll i,j,n,m,k,t;
    cin>>n;
    k=0;
    i=1;
    while(i<=1e7)
    {
        k=((10*k)+7)%n;
        if(k==0)
        {
            cout<<i<<endl;
            return 0;
        }
        i++;
    }
    cout<<-1<<endl;
    return 0;
}




Measured memory_bytes: 3520
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n);
    REP(i,n) a[i] = in();
    REP(t,k){
        VI b(n);
        REP(i,n){
            int l = i - a[i], r = i + a[i] + 1;
            if (l >= 0) b[l]++;
            else b[0]++;
            if (r < n) b[r]--;
        }
        REP(i,n-1) b[i + 1] += b[i];
        bool end = true;
        REP(i,n) if (b[i] < n) end = false;
        a = b;
        if (end) {
            break;
        }
    }
    REP(i,n) printf("%d ", a[i]);
    cout << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        char a;
        cin >> a;
        if (islower(a)) {
                cout << "a" << endl;
        } else {
                cout << "A" << endl;
        }
}

Measured memory_bytes: 3632
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    s,t = map(lambda x:int(x)-1, input().split())
    edges[s].append(t)
    edges[t].append(s)

from collections import deque
def bfs(edges, s)->list:
    V = len(edges)
    dist = [float('inf')]*V
    visited = [False]*V
    dist[s] = 0
    visited[s] = True
    q = deque([s])
    while q:
        cur = q.popleft()
        for nex in edges[cur]:
            if visited[nex]:
                continue
            q.append(nex)
            visited[nex] = True
            dist[nex] = dist[cur] + 1
    return dist

dist1 = bfs(edges, 0)
dist2 = bfs(edges, N-1)
score1 = 0
for d1,d2 in zip(dist1, dist2):
    if d1 <= d2:
        score1 += 1
# print(score1)
print("Fennec" if score1 > N/2 else "Snuke")


Measured memory_bytes: 30112