akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;
ll a[200010], b[200010];
ll tmp[200010];
int n;
inline ll chk(ll k)
{
	register int l = 1, r = n + 1;
	while (l < r)
	{
		register int mid = (l + r) >> 1;
		if (tmp[mid] >= k)r = mid; else l = mid + 1;
	}
	return l;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n; 
	for (register int i = 1; i <= n; i++) cin >> a[i];
	for (register int i = 1; i <= n; i++) cin >> b[i];
	register ll ans = 0;
	for (register int k = 1; k <= 29; k++)
	{
		register ll base = (1 << k) - 1;
		for (register int i = 1; i <= n; i++)tmp[i] = b[i] & base;
		sort(tmp + 1, tmp + n + 1);
		register ll cnt = 0;
		for (register int i = 1; i <= n; i++)
			cnt += n - chk((1 << (k - 1)) - (a[i] & base)) + 1;
		for (register int i = 1; i <= n; i++)
			cnt -= chk((1 << k) + (1 << (k - 1)) - (a[i] & base)) - chk((1 << k) - (a[i] & base));
		if (cnt & 1) ans += (1 << (k - 1));
	}
	cout << ans << endl; return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int m;
vector<int> G;
int insertionSort(int A[], int n, int g){
    int cnt = 0;
    for(int i=g; i<n; ++i){
        int v = A[i];
        int j = i - g;
        while(j>=0 && A[j]>v){
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
    return cnt;
}
int shellSort(int A[], int N){
    int cnt = 0;
    int x=3;
    int y=1;
    while(y <= N){
        G.push_back(y);
        x *= 3;
        y = (x-1)/2;
    }
    reverse(G.begin(), G.end());
    m = G.size();
    for(int i=0; i<m; ++i){
        cnt += insertionSort(A, N, G[i]);
    }
    return cnt;
}
int main(){
    int N; cin >> N;
    int A[1145149];
    for(int i=0; i<N; ++i) cin >> A[i];
    int res = shellSort(A, N);
    cout << m << endl;
    for(int i=0; i<m; ++i){
        if(i) cout << " ";
        cout << G[i];
        if(i == m-1) cout << endl;
    } 
    cout << res << endl;
    for(int i=0; i<N; ++i){
        cout << A[i] << endl;
    } 
    return 0;
}


Measured memory_bytes: 6928
integer N,K
character(10**5) S
integer a(0:10**5),b(0:10**5)
integer asoeji,bsoeji
integer ans
read*,N,K
read*,S
a=0
b=0
if(S(1:1)=="1")then
  asoeji=1
  a(asoeji)=1
  bsoeji=0
else
  asoeji=1
  a(asoeji)=0
  bsoeji=1
  b(bsoeji)=1
endif
do i=2,N
  if(S(i:i)==S(i-1:i-1))then
    if(S(i:i)=="1")a(asoeji)=a(asoeji)+1
    if(S(i:i)=="0")b(bsoeji)=b(asoeji)+1
  else
    if(S(i:i)=="1")then
      asoeji=asoeji+1
      a(asoeji)=1
    else
      bsoeji=bsoeji+1
      b(bsoeji)=1
    endif
  endif
end do
ans=0
do i=1,bsoeji+1
  ans=max(ans,sum(a(i:i+k))+sum(b(i:i+k-1)) )
end do
print"(I0)",ans
end

Measured memory_bytes: 1316
n = int(input())
alphabet = ["","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"]
ans = ""
for i in reversed(range(12)):
    b=0
    if n//26**i>0:
        for j in range(i):
            b+=26**j
    a = (n-b)//26**i
    ans += alphabet[a]
    n = n-a*(26**i)
print(ans)

Measured memory_bytes: 9192
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o B.exe B.cpp 
Execute: ./B
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 	
	string s, t; 
	int result = 0; 
	
	cin >> s >> t; 
	
	for(int i = 0; i < s.size(); i++) {
		if(s[i] != t[i]) {
			result++; 
		}
	}
	
	cout << result << endl; 
	
	return 0; 
} 


Measured memory_bytes: 3852
#include<stdio.h>
#include<string.h>
int main(void)
{
    char s[100],sc[100],p[100];
    int sl,pl,f=0;
    scanf("%s",s);
    scanf("%s",p);
    strcpy(sc,s);
    sl=strlen(s);
    pl=strlen(p);
    for(int j=0;j<sl;j++){
        sc[0]=s[sl-1];
        for(int i=0;i<(sl-1);i++){
            sc[i+1]=s[i];
        }
        if(strncmp(sc,p,pl)==0){
            f=1;
            break;
        }
        strcpy(s,sc);
    }
    if(f==1){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 2736
#include <iostream>
#include <string>
#define REP(i, n) for(int i = 0; i < (n); i++)

using namespace std;

int main()
{
  string s;
  cin >> s;
  REP(i, s.size() - 2) {
    if (s[i] == s[i + 1] || s[i + 1] == s[i + 2] || s[i + 2] == s[i]) {
      cout << (i + 1) << ' ' << (i + 3) << endl;
      return 0;
    }
  }
  if (s.size() == 2 && s[0] == s[1]) cout << "1 2" << endl;
  else cout << "-1 -1" << endl;
  return 0;
}

Measured memory_bytes: 512
nondividers :: Integer -> Integer -> Integer -> Integer
nondividers 0 n m = 0
nondividers k n m = k - div k n - div k m + div k (lcm n m)

count :: Integer -> Integer -> Integer -> Integer -> Integer
count a b c d = nondividers b c d - nondividers (a - 1) c d

main = do
  a:b:c:d:_ <- map (read :: String -> Integer) . words <$> getLine
  putStrLn . show $ count a b c d


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

int main(void){
	int n, m, l, a[101][101], b[101][101];
	long int ans[101][101]={0};
	cin >>n >>m >>l;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cin >>a[i][j];
		}
	}
	for(int i=0; i<m; i++){
		for(int j=0; j<l; j++){
			cin >>b[i][j];
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			for(int k=0; k<l; k++){
				ans[i][k]+=a[i][j]*b[j][k];
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<l-1; j++){
			cout <<ans[i][j] <<" ";
		}
		cout <<ans[i][l-1] <<endl;
	}
    return 0;
}

Measured memory_bytes: 1324
N=int(input())
if N==3:
    print(2,3,25)
elif N==4:
    print(2,3,25,30)
elif N==5:
    print(2,3,25,30,60)
else:
    ans=[]
    base=1
    while len(ans)+6<=N:
        for i in range(base,base+12):
            if (i%2==0)^(i%3==0):
                ans.append(i)
        base+=12
        if base>=30000:
            break
    base=6
    while len(ans)<N:
        ans.append(base)
        base+=6
    print(*ans)

Measured memory_bytes: 4580
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<valarray>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iostream>
#include<iomanip>
using namespace std;
   
   
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define DREP(i,n) for(int i=n;i>0;i--)
#define Rep(i,m,n) for(int i=m;i<n;i++)
#define ReP(i,m,n) for(int i=m;i<=n;i++)
#define scani(a) scanf("%d",&a)
#define scand(a) scanf("%lf",&a)
#define scans(s) scanf("%s",s)
#define readi(a) int a;scanf("%d",&a)
#define printi(a) printf("%d",a)
#define prints(s) printf("%s",s)
#define even(n) (((n)+1)%2)
#define odd(n) ((n)%2)
#define sg(x) ((x)?1:0)
#define LF printf("\n")
#define SPACE printf(" ")
#define pb push_back
#define mp make_pair
#define bs binary_search
#define all(a) (a).begin(),(a).end()
#define forall(itr,a) for(auto itr=(a).begin();itr!=(a).end();++itr)
   
typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<double,double> pdd;
typedef pair<int,int> pii;

const double pi = acos(-1.0);
double rad(double t){return t*pi/180.0;}
double deg(double d){return d*180.0/pi;}
template<typename T>T GCD(T x,T y){return y?GCD(y,x%y):x;}
template<typename T>T LCM(T x,T y){return x/GCD(x,y)*y;}
template<class T>ostream& operator<<(ostream& os,const set<T>& s){os<<"{";for(auto itr=s.begin();s.end() != itr;++itr){if(itr!=s.begin())os<<',';os<<*itr;}os<<"}";return os;}
template<class S,class T>ostream& operator<<(ostream& os,const pair<S,T>& p){os<<'('<<p.first<<','<<p.second<<')';return os;}
const int MOD = (int)pow(10,9) +7;
 
 
//begin global variable
//


//
//end   global variable

int main(){
  ios::sync_with_stdio(false);
  //begin main()
  //

  int n,a,b,acount=0,bcount=0;
  string s ;
  cin >> n >> a >> b;
  cin >> s;
  rep(i,n){
    if(s[i] == 'a'){
      if( acount + bcount < a+b ){//tsuuka
        acount ++;
        cout << "Yes" << endl;
      }else cout << "No" << endl;
    }else if(s[i] == 'b'){
      if( acount + bcount < a+b && bcount < b){
        bcount ++ ;
        cout << "Yes" << endl;
      }else cout << "No" << endl;
    }else{
      cout << "No" << endl;
    }
  }

  //
  //end   main()
  return 0;
}


Measured memory_bytes: 848
r,c = [int(i) for i in input().split()]
mat = []
for i in range(r):
  arr = input()
  tmp = []
  for j in range(c):
    if arr[j] == '.':
      tmp.append(-1)
    else:
      tmp.append(-2)
  mat.append(tmp)

# assigning bottom row to 1 if val == -1 else 0
mat[r-1][c-1] = 1
for i in range(c-2, -1, -1):
  if mat[r-1][i] == -1:
    mat[r-1][i] = mat[r-1][i+1]
  elif mat[r-1][i] == -2:
    mat[r-1][i] = 0

#assiginign to rightmost complex
for j in range(r-2, -1, -1):
  if mat[j][c-1] == -1:
    mat[j][c-1] = mat[j+1][c-1]
  elif mat[j][c-1] == -2:
    mat[j][c-1] = 0

# compute for represent
for i in range(r-2, -1, -1):
  for j in range(c-2, -1, -1):
    if mat[i][j] == -2:
      mat[i][j] = 0
    else:
      mat[i][j] = (mat[i+1][j] + mat[i][j+1])%1000000007
print("%s" % mat[0][0])

Measured memory_bytes: 52188
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    bool ans = false;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(i * j == N){
                ans = true;
            }
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		long ans=0;
		for(long i=2; i*i<=n; i++){
			int count=0;
			while(n%i==0){
				count++;
				n/=i;
			}
			for(int j=1; count-j>=0; j++){
				ans++;
				count-=j;
			}
		}
		if(n>1){
			ans++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35776
#include <bits/stdc++.h>
using namespace std;
void main_sub(void);
int main(int argc, char* argv[]) {
    main_sub();
    return 0;
}
// int を int64_t にする
// g++ に -DUSE_STRICT_INT をつけるか、
// 下のコメントアウトを外すと無効化
// #define USE_STRICT_INT
using i64 = int64_t;
#ifndef USE_STRICT_INT
#define int i64
#endif
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = (1 << 30);
constexpr i64 INFL = (1LL << 62);
constexpr i64 MOD = 1000000007;
void print(const std::vector<int>& v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
void main_sub(void) {
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> x(n);
    vector<int> y(n);

    rep(i, n) {
        int xi, yi;
        cin >> xi >> yi;
        x[i] = xi;
        y[i] = yi;
        v[i] = i;
    }
    long double ans = 0;
    int cnt = 0;
    do {
        long double d = 0;
        rep(i, n - 1) {
            d += pow(pow(x[v[i]] - x[v[i + 1]], 2.0) +
                         pow(y[v[i]] - y[v[i + 1]], 2.0),
                     0.50);
        }
        ans += d;
        ++cnt;
    } while (next_permutation(all(v)));
    cout << fixed << setprecision(12);
    cout << ans / cnt << endl;
    return;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
par = [-1 for _ in range(n)]


def root(x):
    if par[x] < 0:
        return x
    par[x] = root(par[x])
    return par[x]


def union(x, y):
    rx, ry = root(x), root(y)
    if rx == ry:
        pass
    else:
        if par[rx] > par[ry]:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx


def size(x):
    return -par[root(x)]


for _ in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    union(a, b)
    
ans = 0
for i in range(n):
    ans = max(ans, size(i))
print(ans)


Measured memory_bytes: 14688
#include<iostream>

using namespace std;

main(){
  string a,b;
  cin>>a>>b;
  
  if (a=="H"){
    if (b=="H") cout<<"H"<<endl;
    else cout<<"D"<<endl;
  }
  else{
  if (b=="H") cout<<"D"<<endl;
    else cout<<"H"<<endl;
  }
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  unordered_set<int> hashSet;
  int N;
  cin >> N;
  int x;
  for (int i = 0; i < N; ++i) {
    cin >> x;
    if (hashSet.count(x)) {
      cout << "NO" << endl;
      return 0;
    }
    hashSet.insert(x);
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 8520
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	scan.useDelimiter("/|¥n");
    	int a = scan.nextInt();
      	int b = scan.nextInt();
      	String c = scan.next();
      	System.out.print("2018/01/" + c);
      
    }
}

Measured memory_bytes: 23124
<?php

fscanf(STDIN, "%d", $n);
$stdin = trim(fgets(STDIN));

$as = explode(" ", $stdin);

$subtotal = [];
for ($k = 0; $k < $n; $k++) {
	if ($k == 0) {
		$subtotal[$k] = $as[$k];
	} else {
		$subtotal[$k] = $subtotal[$k - 1] + $as[$k];
	}
}

$absxsuby = [];
for ($k = 0; $k < $n - 1; $k++) {
	$absxsuby[$k] = abs($subtotal[$k] * 2 - $subtotal[$n - 1]);
}

echo min($absxsuby) . "\n";

?>

Measured memory_bytes: 39396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll N, K;


double f( int i ){
	if ( i*2 >= K )
		return 0.5;
	else
		return f(i*2)*0.5;
}

int main(){
	cin >> N >> K;
	
	double ne = 0.0; // N × 期待値E
	for ( int i = 1; i <= N; i++ ){
		if ( i >= K )
			ne += 1.0;
		else
			ne += f(i);
	}
	
	
	cout << setprecision(14) << ne/N << endl;
	
	return 0;
}



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

int main()
{
  int a,b,c;
  cin >>a;
  cout << 3 * a * a << endl;
  return 0;
}


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

int main()
{
  string s1, s2;
  cin >> s1 >> s2;
  sort(s1.begin(), s1.end());
  sort(s2.begin(), s2.end(), greater<char>{});
  if (s1 < s2) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

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



int main() {
   string s;
   cin>>s;
   
      if(s=="Sunny") 
      cout<<"Cloudy";
      
      else if (s=="Cloudy")
      cout<<"Rainy";
      else
      cout<<"Sunny";
   
   cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c.at(i);
    }
    sort(c.begin(), c.end());
    vector<pair<ll, ll>> d(m);
    for (int i = 0; i < m; i++) {
        cin >> d.at(i).second >> d.at(i).first;
    }
    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());
    int f = 0;
    for (int i = 0; i < m; i++) {
        for (ll j = 0; j < d.at(i).second; j++) {
            ll t = d.at(i).first;
            c.at(f) = max(t,c.at(f));
            f++;
                if (f == n)break;
        }
        if (f == n)break;
    }
    ll ans=0;
    for (int i = 0; i < n; i++) {
        ans += c.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
import sys
input = sys.stdin.readline

N = int(input())
H = list(map(int, input().split()))
M = H[0]
ans = 1
for i in range(1, N):
    if H[i] >= M:
        ans += 1
    if H[i] > M:
        M = H[i]
print(ans)

Measured memory_bytes: 38384
K, N = map(int, input().split())
A = [int(x) for x in input().split()]
S = A[0]
A.insert(0,0)

def chmax(a,b):
    if a < b:
        return b,True
    else:
        return a,False

m = 0
r = 0
for i in range(1,N+1):
    # print("----")
    # print(i,"/",A[i-1],A[i])
    if i==N:
        # print("@", A[i-1], (K+S)-A[i])
        # print("¥", (K+S)-A[i])
        r = r+(K+S)-A[i]
        A[i],j = chmax(A[i-1], (K+S)-A[i])
        m = i if j else m
    else:
        # print(A[i-1], A[i+1]-A[i])
        r = A[i+1]-A[i]+r
        A[i],j = chmax(A[i-1], A[i+1]-A[i])
        m = i if j else m
    # print(A[i])


# print(m)
print(r-A[m])

Measured memory_bytes: 26444
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


n = int(input())
edges = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

seen = [-1] * n


def dfs(node, prev):
    if seen[node] != -1:
        return
    seen[node] = prev

    for to in edges[node]:
        dfs(to, node)


dfs(0, 0)

colors = [0] * n

node = n-1
goal_to_start = [n-1]
while node:
    node = seen[node]
    goal_to_start.append(node)

length = len(goal_to_start)
limit = (length) // 2

colors = [0] * n
for node in goal_to_start[:limit]:
    colors[node] = 2

for node in goal_to_start[limit:]:
    colors[node] = 1

fennec_todo = [node for node in range(n) if colors[node] == 1]
snuke_todo = [node for node in range(n) if colors[node] == 2]


def paint(todo, my_color):
    while todo:
        node = todo.pop()
        for to in edges[node]:
            if colors[to]:
                continue

            colors[to] = my_color
            todo.append(to)


paint(fennec_todo, 1)
paint(snuke_todo, 2)

feccec_count = len([color for color in colors if color == 1])
snuke_count = len([color for color in colors if color == 2])

if feccec_count > snuke_count:
    print('Fennec ')

else:
    print('Snuke ')


Measured memory_bytes: 110276
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef pair<int, int> pi;
typedef vector<pair<int,int> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N],ARR[N]  ;
bool visited[N]={};
int cnt[N]={};
bool f;
int main()
{
    int n;
    cin>>n;
    unordered_map<string, long long> uom;
    string s;
    rep(i,n)
    {
        cin>>s;
        sort(all(s));
        uom[s]++;
    }
    auto ans=0L;
    for(auto &x:uom )
    {
        if(x.S>1)
        {
            ans+=x.S*(x.S -1 )/2;
        }
    }
    cout<<ans;

go;
}


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

"""
愚直にやると、Kを2～Nの範囲で全部調べて数え上げる。N <= 10**12 なので間に合わない。


たとえば N=100だと、
[2, 3, 4, 9, 10, 11, 33, 99, 100]
が条件を満たす数字になる。

割り算を行わないとき、明らかに N % K = 1 になる
これは、「NをKで割ったら、１あまる」であるから、「N-1をKでわったら割り切れる」ともいえる。
なので、割り算が起こらないものは、N-1の約数。

割り算が起こるやつは、割れるだけ割った後、余りを調べればよい。
"""



def solve(n):
    i = 1
    ret = set()
    while i * i <= n:
        if n % i == 0:
            ret.add(i)
            ret.add(n // i)
        i += 1

    return ret


div_N_sub_1 = solve(N-1)
div_N = solve(N)

ans = len(div_N_sub_1) - 1

for i in div_N:
    if i == 1:
        continue
    tmp = N
    while tmp % i == 0:
        tmp //= i
    if tmp % i == 1:
        ans += 1


print(ans)

Measured memory_bytes: 14196
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef complex<double> point;

const ll N = 105;
const ll INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-7;
const double PI = acos(-1.0);

ll dp[100005];
ll n, m, w[N], v[N], ans;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> w[i] >> v[i];

    for(int i = 1; i < 100005; i++)
        dp[i] = -1;

    for(int i = 0; i < n; i++)
        for(int j = 100000; j >= 0; j--)
            if(w[i] <= j && dp[j - w[i]] != -1)
                dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
    
    for(int i = 0; i <= m; i++)
        ans = max(dp[i], ans);
    
    cout << ans << endl;
}


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

using namespace std;
int main(void) {
  string s;
  cin >> s;

  long long sum = 0;
  long long num_of_pattern = 1 << (s.size() - 1);

  for(long long ptn = 0; ptn < num_of_pattern; ptn++) {
    long long ptn_sum = 0;
    int cur = 0;
    for(int len = 1; cur + len < s.size(); len++) {
      if(ptn & ((long long)1 << (cur + len - 1))) {
        ptn_sum += stoll(s.substr(cur, len));
        cur += len;
        len = 0;
      }
    }
    ptn_sum += stoll(s.substr(cur));
    sum += ptn_sum;
  }
  cout << sum << endl;
  return 0;
}


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

int main() {
    
    int a,b,t ;
    cin>>a>>b>>t ;
    
    int j=1 , i=a*j  , count =0 ;
    
    while(i<=t){
        count+=b ;
        j++ ;
        i = a*j ;
    }
    
    cout<<count<<"\n" ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int (i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int (i) = (int)(initial); (i) < (int)(n); ++(i))
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int (i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int (i) = (int)(initial); (i) > (int)(n); (i)--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
	vector< pair<ll, ll> > p;
	for(ll i = 2; i*i <= n; i++) {
		if ((n % i) != 0) continue;
		p.push_back(make_pair(i, 0));
		while((n % i) == 0) {
			n /= i;
			p[i].second += 1;
		}
		p.push_back(make_pair(n, 0));
	}

	if (n != 1) p.push_back(make_pair(n, 1));
	return p;
}
string alphabet() { return "abcdefghijklmnopqrstuvwxyz"; }

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

	repeat(i, N.length()) {
		string n = N.substr(i, 1);

		if (n == "7") {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 200010
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-9
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, m, k, t, cnt, ans;
ll a[SIZE], pre[SIZE] = { 1,1 }, sum[SIZE];
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll mod) { //快速幂 a ^ b % mod
	ll ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ans;
}

int main() {
	io(); cin >> n;
	rep(i, 1, n) pre[i] = pre[i - 1] * i % mod;
	rep(i, 1, n) sum[i] = (sum[i - 1] + pre[n - 1] * qpow(i * (i + 1ll) % mod, mod - 2ll, mod) % mod + mod) % mod;
	rep(i, 1, n) cin >> a[i];
	rep(i, 2, (n - 1))
		ans = (ans + a[i] * sum[i - 1] % mod + mod) % mod;
	rep(i, 1, (n - 1))
		ans = (ans - a[i] * sum[n - 1 - i] % mod + mod) % mod;
	rep(i, 1, (n - 1))
		ans = (ans - a[i] * pre[n - 1] % mod * qpow(n - i, mod - 2ll, mod) % mod + mod) % mod;
	rep(i, 1, (n - 1))
		ans = (ans + a[n] * pre[n - 1] % mod * qpow(n - i, mod - 2ll, mod) % mod + mod) % mod;
	cout << ans;
}
//3 1 2 3

Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  char a[n + 1][n + 1], b[m * 1][m + 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> b[i][j];
    }
  }

  bool exist = false;
  for (int i = 0; i <= n - m; i++) {
    for (int j = 0; j <= n - m; j++) {
      bool match = true;
      for (int k = 1; k <= m; k++) {
        for (int l = 1; l <= m; l++) {
          if (a[k + i][l + j] != b[k][l]) {
            match = false;
          }
        }
      }
      if (match) {
        exist = true;
      }
    }
  }
  if (exist) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	ll x;
	cin>>x;
	ll ans=0;
	ll van=x/500;
	x-=van*500;
	ans+=van*1000;
	van=x/5;
	x-=van*5;
	ans+=van*5;
	cout<<ans<<"\n";
	
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB = sorted(AB, key=lambda a: a[0])
total = 0
total_count = 0
for i in range(N):
    if total_count + AB[i][1] >= M:
        total += (AB[i][0] * (M - total_count))
        break
    else:
        total_count += AB[i][1]
        total += (AB[i][0] * AB[i][1])
print(total)


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  bool flag = false;
  if(A != B && B == C) flag = true;
  if(B != C && C == A) flag = true;
  if(C != A && A == B) flag = true;
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#c
h,w,k = map(int,input().split())
c = [None]*h
for i in range(h):
    c[i] = list(input())

import copy
ans =[0]*(h*w+1)
for i in range(2**h):
    for j in range(2**w):
        
        cc = copy.deepcopy(c)
        bi = bin(i)[2:].zfill(h)
        bj = bin(j)[2:].zfill(w)
        for ii in range(h):
            for jj in range(w):
                if bi[ii]=="1":
                    cc[ii]=[2]*w
                if bj[jj]=="1":
                    for kk in range(h):
                        cc[kk][jj]=2
                    
        n_black = sum(ccc.count("#") for ccc in cc )
        
#        print(i,bi,j,bj,n_black,cc)
        ans[n_black]+=1
print(ans[k])

Measured memory_bytes: 77444
import scala.math._

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"

  val input: Array[Array[Int]] = Array.ofDim(6, 6000000)
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
  val s = sc.next
//  val b = sc.nextInt
//  val a = List.fill(n)(sc.nextInt)
//  val b = List.fill(n)(sc.nextInt)
//  val c = List.fill(n - 1)(sc.nextInt)

  val ans = s.foldLeft((0, 0)){ case ((acc, workingSize), in) =>
    val isPartition = Seq('A', 'C', 'G', 'T').contains(in)
    if (!isPartition) if (acc < workingSize) (workingSize, 0) else (acc, 0)
    else {
      if(acc < workingSize + 1) (workingSize + 1, workingSize + 1)
      else (acc, workingSize + 1)
    }
  }._1

  println(ans)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 167364
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int inf = 1<<30;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

int main () {
  int N; cin >> N;
  vi H(N); rep(i,N) cin >> H.at(i);
 
  int next = inf;
  for (int i = N-1; i >= 0; i--) {
    if (H[i] <= next) {
      next = H[i];
    }
    else if (H[i]-1 <= next) {
      next = H[i]-1;
    }
    else {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 640
n = int(input())
za = list(map(int,input().split()))
za_max = max(za)
za_min = min(za)
kouho = 0
kouho_sum = 0
ans = 9999999999999999999999999999999999999999999999999999999999999999999999999999
for zahyou in range(za_min,za_max+1):
    for i in za:
        kouho = (i - zahyou)*(i - zahyou)
        kouho_sum = kouho_sum + kouho
    if(ans > kouho_sum):
        ans = kouho_sum
        kouho_sum = 0
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
const int INF = (1 << 30);

//毎回変える場所
#define N_MAX 200
int N, M;

int main() {
	cin >> N >> M;
	LL time = 0;
	time += M * 1900 + (N - M) * 100;
	REP(i, M)time *= 2;
	cout << time << endl;
	cin >> N;
	return 0;
}

Measured memory_bytes: 256
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int LMAX=1e3+1,MOD=1e9+7;
int h,w,dp[LMAX][LMAX];
char laby[LMAX][LMAX];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> h >> w;
	
	for(int l=1;l<=h;l++){
		for(int c=1;c<=w;c++){
			cin >> laby[l][c];
		}
	}
	
	dp[1][1]=1;
	
	for(int l=1;l<=h;l++){
		for(int c=1;c<=w;c++){
			if((l>1 || c>1) && laby[l][c]=='.'){
				dp[l][c]=(dp[l-1][c]+dp[l][c-1])%MOD;
			}
		}
	}
	
	cout << dp[h][w] << '\n';
		
	
}


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

int main(){
  int a,b;
  b=0;
  cin>>a;
  int x[5]={3,5,7,11,13};
  for(int i=0;i<5-2;i++){
	for(int j=i+1;j<5-1;j++){
      for(int k=j+1;k<5;k++){
        if(x[i]*x[j]*x[k]<=a) b++;
      }
    }
  }
  if(27*5<=a)b++;
  if(27*7<=a)b++;
  
  cout<<b<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x, y, z, n;

int main()
{
    cin >> x;
    int mx = -1;

    int xx = 1;
    while(true){
        int tmp = xx * 2;
        if(tmp > x){
            cout << xx << endl;
            return 0;
        }
        xx = tmp;
    }


    return 0;
}


Measured memory_bytes: 256
while True:
    N = int(input())
    if N == 0:
        break

    abc = []
    cities = [False] * 10
    for i in range(N):
        a, b, c = list(map(int, input().split()))
        cities[a] = True
        cities[b] = True
        abc.append([a, b, c])

    cnum = cities.count(True)

    # G[i][j]: iとjの最短経路
    G = []
    for i in range(cnum):
        a = [float('inf')] * cnum
        G.append(a)

    for i in range(cnum):
        G[i][i] = 0

    for a, b, c in abc:
        G[a][b] = min(G[a][b], c)
        G[b][a] = min(G[b][a], c)


    for k in range(cnum):
        for i in range(cnum):
            for j in range(cnum):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

    # for i in range(cnum):
    #     print(G[i])
    min_city = None
    min_cost = float('INF')
    for i in range(cnum):
        c = sum(G[i])
        if c < min_cost:
            min_cost = c
            min_city = i

    print(min_city, min_cost)



Measured memory_bytes: 5616
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;


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

	string s;
	cin >> s;

	for(int i = 0; i < sz(s); i++){
		if(s[i] == '?') s[i] = 'D';
	}

	cout << s;
}

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

int d[10][10];

int main() {

    int H, W;
    cin >> H >> W;
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            cin >> d[i][j];
        }
    }

    for(int k = 0; k < 10; k++) {
        for(int i = 0; i < 10; i++) {
            for(int j = 0; j < 10; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            int a;
            cin >> a;
            if(a == -1) continue;
            ans += d[a][1];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    string s = "";
    int K;
    cin >> K;
    REP(_, 0, K)
    {
        s += "ACL";
    }
    cout << s << endl;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>

#define MAX 999999999999999999

using namespace std;

vector<int> graph[2501];
vector<pair<pair<int, int>, long long>> arr;
long long adj[2501][2501];
int parent[2501];
bool reachable[2501] = { 0, };
bool inf[2501] = { false, };

void dfs(int cur)
{
	int i;
	int next;

	for (i = 0; i < graph[cur].size(); i++)
	{
		next = graph[cur][i];

		if (!inf[next])
		{
			inf[next] = true;

			dfs(next);
		}
	}
}

void dfs2(int cur)
{
	int i;
	int next;

	for (i = 0; i < graph[cur].size(); i++)
	{
		next = graph[cur][i];

		if (!reachable[next])
		{
			reachable[next] = true;

			dfs2(next);
		}
	}
}

int main()
{
	int n, m;
	int u, v;
	long long d, p;
	int i, j;
	long long dist[2501];
	bool changed;

	//freopen("input.txt", "r", stdin);

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

	for (i = 2; i <= n; i++)
	{
		dist[i] = MAX;
	}

	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			adj[i][j] = MAX;
		}

		adj[i][i] = 0;
	}

	dist[1] = 0;
	reachable[1] = true;

	for (i = 0; i < m; i++)
	{
		scanf("%d %d %lld", &u, &v, &d);
		
		if (u == v)
		{
			if (p - d < 0)
			{
				adj[u][v] = p - d;

				inf[u] = true;
			}
		}

		else
		{
			adj[u][v] = p - d;

			arr.push_back(make_pair(make_pair(u, v), p - d));

			graph[u].push_back(v);
		}
	}

	dfs2(1);

	for (i = 0; i < n -	1; i++)
	{
		for (j = 0; j < arr.size(); j++)
		{
			if (dist[arr[j].first.first] + arr[j].second < dist[arr[j].first.second])
			{
				dist[arr[j].first.second] = dist[arr[j].first.first] + arr[j].second;
			}
		}
	}

	for (i = 0; i < arr.size(); i++)
	{
		if (dist[arr[i].first.first] != MAX&&dist[arr[i].first.first] + arr[i].second < dist[arr[i].first.second])
		{
			inf[arr[i].first.first] = true;
		}
	}

	for (i = 1; i <= n; i++)
	{
		if (inf[i] && reachable[i])
		{
			dfs(i);
		}
	}

	if (inf[n])
	{
		printf("-1\n");
	}

	else
	{
		printf("%lld\n", -dist[n] > 0 ? -dist[n] : 0);
	}

	/*
	changed = true;
	while (changed)
	{
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				if (dist[j] > dist[i] + adj[i][j])
				{
					dist[j] = dist[i] + adj[i][j];

					changed = true;
				}
			}
		}
	}
	*/

	return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code

int main(int argc, char const* argv[])
{
	LL l,r;
	cin >>l>>r;
	LL m = 2019;
	for (LL i = l; i <= r; i++) {
		if (i % m == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	LL ans = 2019;
	for (LL i = l; i <= r; i++) {
		for (int j = i+1; j <= r; j++) {
			ans = min(ans,((i%m) * ((j)%m))%m);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define N_ 201000
using namespace std;
int n, V, w[N_], m;
int C[20][N_], L[20], PP[30];
int BE[20][N_], ED[20][N_];
int D1[1048576], D2[1048576];
int main(){
    int i, j;
    scanf("%d%d",&n,&V);
    for(i=1;i<=n;i++)scanf("%d",&w[i]);
    L[0] = V;
    for(i=1;;i++){
        L[i]=L[i-1]/2;
        if(!L[i])break;
    }
    m = i+1;
    for(i=0;i<m;i++){
        int c = 0;
        for(j=1;j<=n;j++){
            if(j==1 || w[j]-w[j-1] > L[i])c++;
            C[i][j] = c;
        }
        for(j=1;j<=c;j++)BE[i][j]=1e9,ED[i][j]=0;
        for(j=1;j<=n;j++){
            BE[i][C[i][j]] = min(BE[i][C[i][j]],j);
            ED[i][C[i][j]] = max(ED[i][C[i][j]],j);
        }
    }
    if(C[0][n] > m){
        for(i=1;i<=n;i++)puts("Impossible");
        return 0;
    }
    for(i=0;i<(1<<m);i++)D2[i] = n+1;
    for(i=0;i<(1<<m);i++){
        for(j=0;j<m;j++){
            if(i&(1<<j))continue;
            if(D1[i]!=n)D1[i|(1<<j)] = max(D1[i|(1<<j)], ED[j][C[j][D1[i]+1]]);
            else D1[i|(1<<j)] = n;
            if(D2[i]!=1)D2[i|(1<<j)] = min(D2[i|(1<<j)], BE[j][C[j][D2[i]-1]]);
            else D2[i] = 1;
        }
    }
    for(i=1;i<=C[0][n];i++){
        int b = BE[0][i], e = ED[0][i];
        for(j=0;j<(1<<m);j++){
            if(j&1)continue;
            int t = (1<<m) - 2 - j;
            if(D1[j] + 1 >= b && D2[t] - 1 <= e)PP[i] = 1;
        }
    }
    for(i=1;i<=n;i++){
        if(PP[C[0][i]])puts("Possible");
        else puts("Impossible");
    }
}

Measured memory_bytes: 58368
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}


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

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

 
  int ans=inf;

  int res=0,sum=0;
  rep(i,n){
    sum+=a[i];
    if(i%2&&sum<=0){
      res+=1-sum;
      sum=1;
    }if(i%2==0&&sum>=0){
      res+=1+sum;
      sum=-1;
    }
  }

  ans=res;
  res=0;
  sum=0;

  rep(i,n){
    sum+=a[i];
    if(i%2==0&&sum<=0){
      res+=1-sum;
      sum=1;
    }if(i%2&&sum>=0){
      res+=1+sum;
      sum=-1;
    }
  }

  cout<<min(ans,res)<<endl;

}



Measured memory_bytes: 1024
// C - HonestOrUnkind2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int N, A[15], X[15][15], Y[15][15];

int isbit(int x, int i){ return x>>i&1; }

int check(int bits){
	rp(i, 0, N)
		if(isbit(bits, i))
			rp(j, 0, A[i]) if(isbit(bits, X[i][j]) != Y[i][j]) return 0;
	return bitset<15>(bits).count();
}

int main(){
	scanf("%d",&N);
	rp(i, 0, N){ scanf("%d",A+i); rp(j, 0, A[i]){ scanf("%d%d",X[i]+j,Y[i]+j); X[i][j]--; } }
	int ans = 0;
	rp(bits, 1, 1<<N) ans = max(ans, check(bits));
	printf("%d\n", ans);
}

Measured memory_bytes: 256
Sa = input()
Sb = input()
Sc = input()

x = 'a'

while True:
    if x == 'a':
        if len(Sa) == 0:
            print('A')
            break
        x = Sa[0]
        Sa = Sa[1:len(Sa)]
    elif x == 'b':
        if len(Sb) == 0:
            print('B')
            break
        x = Sb[0]
        Sb = Sb[1:len(Sb)]
    elif x == 'c':
        if len(Sc) == 0:
            print('C')
            break
        x = Sc[0]
        Sc = Sc[1:len(Sc)]

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

int main(){
  int n,tmp;
  cin >> n;
  vector<pair<int, int>> a(n+1);
  for (int i = 1; i <= n; i++) {
    cin >> tmp;
    a[i] = make_pair(tmp, i);
  }
  sort(a.begin(), a.end());
  for(int i=1;i<=n;i++){
    if(i == a[n].second){
      cout << a[n-1].first << endl;
    }
    else{
      cout << a[n].first << endl;
    }
  }
}

Measured memory_bytes: 3200
#include<stdio.h>

int main(void) {
  char N[5];
  scanf("%s",&N);
  
  if(N[0]==N[1] && N[1]==N[2]) {
    printf("Yes\n");
  }
  else if(N[1]==N[2] && N[2]==N[3]) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 128