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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18	9223372036854775807LL
//	O(1e7) O(1e8)

void Main()
{
	ll K;
	cin>>K;

	ll ans=0;
	ll N=0;
	for(ll i= 0; i<=1e8;i++){
		N=(N*10+7)%K;
		//dout<<i<<':'<<N<<_n;
		if(N%K==0){cout<<i+1;return;}
	}
	cout<<-1<<_n;
}


void Test();
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3656
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, A, B = MAP()

MIN = A*(N-1)+B
MAX = B*(N-1)+A

if MAX < MIN:
	print(0)
	exit()

print(MAX - MIN + 1)

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

A, B, C, D, E, F = [int(x) for x in input().split()]

ans = [0, 0, -1]

for x in range((30 // A) + 1):
    for y in range((30 // B) + 1):
        if 100 * (A * x + B * y) > F or x + y == 0:
            continue
        a = 100 * (A * x + B * y)
        for z in range(1 + ((a // 100) * E) // C):
            b = C * z + D * (((a // 100) * E - C * z) // D)
            b_2 = C * z + D * ((F - (a + C * z)) // D)
            if b + a > F or b > (a // 100) * E:
                b = 0
            if b_2 + a > F or b_2 > (a // 100) * E:
                b_2 = 0
            b = max(b, b_2)
            if b / (a + b) > ans[-1]:
                ans = [a + b, b, b / (a + b)]

print(ans[0], ans[1])



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

int main() {
	long double a, b, c;
	cin >> a >> b >> c;
	long double ab = sqrt(a * b);
	if (ab < (c - a - b) / 2.0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

const ll MOD = 1e9+7;

void solve()
{
    ll N;
    cin>>N;

    

    //total number of sequences = 10^N
    //total number of sequences without 0 = 9^N;
    //total number of sequences without 9 = 9^N;
    //total number of sequences without 0 & 9 = 8^N;

    //final ans = 10^N - 2*(9^N) + 8^N -> inclusion and exclusion

    ll m1 = 1,m2 = 1,m3 = 1;

    for(ll i = 0; i < N; i++)
    {
        m1 = (m1*10) % MOD;
        m2 = (m2*9) % MOD;
        m3 = (m3*8) % MOD;
    }

    ll ans = (m1 + MOD - (2*m2) % MOD + m3) % MOD;
    
    cout<<ans<<endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	vector<ll> a(n,0),b(n,0),c(n-1,0);
	for(ll i=0;i<n;i++) cin>>a[i];
	for(ll i=0;i<n;i++) cin>>b[i];
	for(ll i=0;i<n-1;i++) cin>>c[i];
	
	ll ans=0;
	for(ll i=0;i<n;i++) ans+=b[i];
	
	for(ll i=0;i<n-1;i++){
		if(a[i]+1==a[i+1]){
			ans+=c[a[i]-1];
		}
	}
	
	cout<<ans<<endl;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    ll n,w;
    cin >> n >> w;
    vector<vector<ll>> dp(n+1,vector<ll>(w+1,0));
    for (int i = 0;i < n;++i) {
        int u,v;
        cin >> u >> v;
        dp[i+1] = dp[i];
        for (int j = 0;j <= w-u;++j) dp[i+1][j+u] = max(dp[i+1][j+u],dp[i][j]+v);
    }
    cout << dp[n][w] << endl;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define help freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);

vector<int> vec[200009];
bool flag[200009];

int dfs(int x)
{
    flag[x] = true;
    int cnt = 0;
    for (int i = 0; i < vec[x].size(); i++)
    {
        if (!flag[vec[x][i]])
            cnt += 1 + dfs(vec[x][i]);
    }
    return cnt;
}

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        vec[x].push_back(y);
        vec[y].push_back(x);
    }
    int ans = -1;
    for (int i = 1; i <= n; i++)
    {
        if (!flag[i])
        {
            int x = dfs(i)+1;
            //cout << i << " " << x << endl;
            ans = max(ans, x);
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
    long int N,B=0;
    cin >>N;
    for(int i=0;i<N;i++){
        if(((i+1)%3!=0)&&((i+1)%5!=0)){
            B=B+i+1;
        }
    }
    cout << B <<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


// 1白
// 2黒

int main(){
	int n;
	cin >> n;
	int co[100002]={};
	vector<P> tree[n];
	FOR(i,0,n-1){
		int a,b,w;
		cin >> a >> b >> w;
		a--;b--;
		tree[a].push_back({b,w});
		tree[b].push_back({a,w});
	}
	queue<int> q;
	q.push(0);
	co[0] = 1;
	while(!q.empty()){
		int now = q.front();
		q.pop();
		for(auto to:tree[now]){
			if(co[to.first]==0){
				if(to.second%2){
					co[to.first] = 3 - co[now];
				}else{
					co[to.first] = co[now];
				}
				q.push(to.first);
			}
		}
	}
	FOR(i,0,n){
		cout << co[i]-1 << endl;
	}
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    char A;
  	cin>>A;
  	char B=A+1;
  	cout<<(char)B<<endl;
}

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

int main(){
  
  string S; cin >> S;
  
  int cnt = 0;
  
  if(S[0] == S[1]) cnt++;
  if(S[0] == S[2]) cnt++;
  if(S[0] == S[3]) cnt++;
  if(S[1] == S[2]) cnt++;
  if(S[1] == S[3]) cnt++;
  if(S[2] == S[3]) cnt++;
  
  if(cnt == 2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int v[1100000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a+b){
		for(int i=0;i<b;i++)v[i]=-1;
		v[a]=0;
		int now=1;
		int at=a*10%b;
		while(1){
			if(at==0){
				printf("%d %d\n",now,0);break;
			}
			if(~v[at]){
				printf("%d %d\n",v[at],now-v[at]);break;
			}
			v[at]=now;
			now++;
			at=at*10%b;
		}
	}
}

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

using namespace std;

set<long long> divisors(long long n) {
    set<long long> ans;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ans.insert(i);
            ans.insert(n / i);
        }
    }
    return ans;
}

bool check(long long a, long long n) {
    if (a == 1) return false;
    while (n % a == 0) {
        n = n / a;
    }
    return (n % a) == 1;
}

int main() {
    long long n;
    cin >> n;
    set<long long> candidates, divs1, divs;
    divs1 = divisors(n - 1);
    divs = divisors(n);
    candidates.insert(divs1.begin(), divs1.end());
    candidates.insert(divs.begin(), divs.end());
    int ans = 0;
    for (auto a: candidates) {
        if(check(a, n))ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)] 
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main(){
	 ios::sync_with_stdio(false);
	 cin.tie(nullptr);
	 cout.tie(nullptr);
	 int T = 1;
	 for(int t = 1; t <= T; t++){
		 int64_t a,b,k;
		 cin >> a >> b >> k;
		 if(a <= k){
			 k -= a;
			 a = 0;
		 }else{
			 a -= k;
			 k = 0;
		 }
		 if(b <= k){
			 k -= b;
			 b = 0;
		 }else{
			 b -= k;
			 k = 0;
		 }
		 cout << a << " " << b << "\n";
	 }
}



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

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

template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
struct Unionfind {
    vector<int> par;

    Unionfind(int n) : par(n) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] =ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    ll n;
    cin >> n;

    vector<pair<int, int>> table;

    for(ll i = 2; i * i <= n; ++i) {
        int cnt = 0;
        while(n % i == 0) {
            n /= i;
            ++cnt;
        }
        table.emplace_back(i, cnt);
    }
    //素数の要素があるならば
    if(n != 1) table.emplace_back(n, 1);

    int ans = 0;
    rep(i, table.size()) {
        int c = 1;
        int a = table[i].second;
        while(c <= a) {
            a -= c;
            ++c;
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11616
using System;

class B
{
	static void Main()
	{
		var s = Console.ReadLine().Replace("BC", "X");

		var r = 0L;
		for (int t = -1, i = 0; i < s.Length; i++)
		{
			if (s[i] == 'X') { if (t != -1) r += i - t++; }
			else if (s[i] == 'A') { if (t == -1) t = i; }
			else t = -1;
		}
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 13664
w,h,n = gets.chomp.split(" ").map(&:to_i)
whiteStartW = 0
whiteEndW = w
whiteStartH = 0
whiteEndH = h
n.times do
  x,y,a = gets.chomp.split(" ").map(&:to_i)
  case a
    when 1
    	whiteStartW = x if(x > whiteStartW)
    when 2
    	whiteEndW = x if(x < whiteEndW)
    when 3
    	whiteStartH = y if(y > whiteStartH)
    when 4
        whiteEndH = y if(y < whiteEndH)
  end
end
whiteH = (whiteEndH - whiteStartH)
whiteH = 0 if whiteH < 0
whiteW = (whiteEndW - whiteStartW)
whiteW = 0 if whiteW < 0
puts whiteH * whiteW



Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	string S;
	cin >> S;
	cout << ((S[2] == S[3] && S[4] == S[5])? "Yes": "No") << endl;

	return 0;
}


Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[]str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int K = int.Parse(str[2]);
		int[]A = new int[N];
		int[]B = new int[M];
		string[]str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str2[i]);
		}
		string[]str3 = Console.ReadLine().Split();
		for(var i=0;i<M;i++){
			B[i] = int.Parse(str3[i]);
		}
		int ans = 0;
		long sum = 0;
		int a = 0;
		int b = 0;
		for(var i=0;i<N;i++){
			if(sum+A[i]<=K){
				sum += A[i];
				a++;
			} else {
				break;
			}
		}
		for(var i=0;i<M;i++){
			if(sum+B[i]<=K){
				sum += B[i];
				b++;
			} else {
				break;
			}
		}
		ans = a+b;
		for(var i=a-1;i>=0;i--){
			sum -= A[i];
			while(b<M){
				if(sum+B[b]<=K){
					sum += B[b];
					b++;
				} else {
					break;
				}
			}
			ans = Math.Max(ans,i+b);
		}
		Console.WriteLine(ans);
	}
}

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

using namespace std;

const int max_n = 100011, mod = 1000000007;
const int m = 13;

int n, dp[max_n][m];
char s[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%s", s);
    n = strlen(s);
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int x = 0; x < m; ++x) {
            for (char c = '0'; c <= '9'; ++c) {
                if (s[i] == '?' || c == s[i]) {
                    dp[i + 1][(x * 10 + c - '0') % m] += dp[i][x];
                    dp[i + 1][(x * 10 + c - '0') % m] %= mod;
                }
            }
        }
    }
    printf("%d\n", dp[n][5]);
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


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

  int a, b, c;

  vector<int> dp(pow(2, N)+1, INF);
  dp[0] = 0;
  REP(i, M){
    cin >> a >> b;
    int hoge = 0;
    REP(j, b){
      cin >> c;
      c--;
      hoge |= (1<<c);
    }

    REP(j, pow(2, N)){
      int cur = j|hoge;
      dp[cur] = min(dp[cur], dp[j]+a);
    }
  }

  if(dp[pow(2, N)-1] == INF) cout << -1 << endl;
  else cout << dp[pow(2, N)-1] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll divi[129];
ll vis[129];
map<long double,ll>mp1;
map<ll,ll>mp2;
vector<int>stp[29];
string str1;
string str2;
ll arra[100007];
deque<ll>save;
ll ans1[100005];
ll ans2[100005];
ll inp1[200009];
ll inp2[200009];
pair<ll,ll>sol;
//map<pair<ll, ll>, ll> mp3;
map<char,ll>mp3;
map<ll,ll>L;
map<ll,ll>R;
vector<ll>c_pg[1009];
ll x_p[1009];
ll y_p[1009];
ll x_last[1009];
ll y_last[1009];
ll p_m[200009];
int main()
{
  ll i,j,k,l,p=2,q=0,r=0,s=0,t,m,n,check=1,x=0,y=1,z=0,a=1,b=1,c=0,zero=0;
  cin>>n;
  while(1)
  {
     n=n/2;
     if(n>0)
     {
        a=a*p;
        b=b+a;	
     }
     else
       break;	
  }
  cout<<b;
  
 
     
  
   
  
    	
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>

int dp[1001][100001];
int main()
{
	int h, n;
	scanf("%d%d", &h, &n);
	int a[1000], b[1000];
	for (int i = 0; i < n; ++i)
	{
		scanf("%d%d", a + i, b + i);
	}
	for (int i = 0; i <= n; ++i)
	{
		std::fill(dp[i], dp[i] + h, (int)1e9);
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = h; j >= 0; --j)
		{
			dp[i + 1][j] = std::min(dp[i][j], dp[i + 1][j]);
			if (j - a[i] <= 0)
			{
				dp[i + 1][0] = std::min(std::min(dp[i + 1][0], dp[i + 1][j] + b[i]), dp[i][0]);
			}
			else
			{
				dp[i + 1][j - a[i]] = std::min(std::min(dp[i + 1][j - a[i]], dp[i + 1][j] + b[i]), dp[i][j - a[i]]);
			}
		}
	}
	printf("%d\n", dp[n][0]);
	return 0;
}


Measured memory_bytes: 387712
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int q[1000000],C[100010];
int ta[100010],nt[200010],to[200010],co[200010];
int f[100010],g;
/*int dfs(int v,int e,int s){
  int i,max=C[s];
  for(i=ta[s];i+1;i=nt[i]){
    if(f[to[i]])continue;
    f[to[i]]=1;
    C[to[i]]=C[s]+co[i];
    max=MAX(max,dfs(v,e,to[i]));
  }
  return max;
}//*/
int bfs(int v,int e,int s){
  int t,r,i,max=0;
  for(i=0;i<v;i++)C[i]=1000000000;
  C[q[0]=s]=t=0;//printf("a\n");
  for(r=1;r-t;t++){
    for(i=ta[q[t]];i+1;i=nt[i]){//printf("%d %d %d\n",q[t],to[i],co[i]);
      if(C[to[i]]>C[q[t]]+co[i])C[q[r++]=to[i]]=C[q[t]]+co[i];
      if(max<C[to[i]])max=C[g=to[i]];//printf("m%d\n",max);
    }
  }
  return max;
}//*/
int tyokkei(int v,int e,int *a,int *b){
  int i,max=0,j;
  /*for(i=0;i<v;i++){
    ta[i]=-1;
    C[i]=1000000000;
    f[i]=0;
  }
  C[0]=0;
  f[0]=1;*/
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i]=ta[a[i]];
    ta[a[i]]=i;
    nt[i+e]=ta[to[i]];
    to[i+e]=a[i];
    co[i+e]=co[i];
    ta[to[i]]=i+e;    
  }
  /*for(i=0;i<v;i++){printf("%d:",i);
    for(j=ta[i];j+1;j=nt[j])printf("%d ",to[j]);printf("\n");
    }*/
  max=bfs(v,e*2,0);
  /*for(i=0;i<v;i++){
    if(max==C[i])g=i;
    C[i]=1000000000;
    f[i]=0;
  }
  C[g]=0;
  f[g]=1;//printf("g%d m%d\n",g,max);//*/
  return bfs(v,e*2,g);
}
int main(){
  int n,a[100010],b[100010],i;
  scanf("%d",&n);
  for(i=0;i<n-1;i++)scanf("%d %d %d",&a[i],&to[i],&co[i]);
  printf("%d\n",tyokkei(n,n-1,a,b));
  return 0;
}

Measured memory_bytes: 5480
sx, sy, tx, ty = map(int, input().split())

def forward(x, y, tx, ty):
   while y < ty:
      print('U', end='')
      y += 1
   while x < tx:
      print('R', end='')
      x += 1
   return()

def backward(x, y, sx, sy):
   while y > sy:
      print('D', end='')
      y -= 1
   while x > sx:
      print('L', end='')
      x -= 1
   return()

forward(sx, sy, tx, ty)
backward(tx, ty, sx, sy)

print('L', end='')
forward(sx-1, sy, tx, ty+1)
print('DR', end='')
backward(tx+1, ty, sx, sy-1)
print('U')


Measured memory_bytes: 4468
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
using namespace std;

#define lint long long int
#define N_MAX 100000



int main()
{
    int n, m;
    cin >> n >> m;
    
    lint h[N_MAX+1];
    for (int i = 1; i <= n; i++) cin >> h[i];
    
    bool is_good[N_MAX+1];
    for (int i = 1; i <= n; i++) is_good[i] = true;
    
    
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        
        if (h[a] <= h[b]) is_good[a] = false;
        if (h[b] <= h[a]) is_good[b] = false;
    }
    
    
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (is_good[i]) ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 4552
#define _GLIBCXX_DEBUG
#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++)

#include <bits/stdc++.h>
using namespace std;



int main() {
    long long N, K;
    cin >> N >> K;
    long ans = N % K;
    long ans1 = (-1*N) % K + K;
    cout << min(ans,ans1) << endl;
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#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 pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
int N, a[200010], M;
V c;

void solve()
{
    bool ans = true;
    for (int i = N; i > 1; i--) {
        if (a[i]) {
            for (int n = 1; n * n <= i; n++) {
                if ((i % n) == 0) {
                    a[n] = !a[n];
                    if (n * n != i && n != 1) {
                        a[i / n] = !a[i / n];
                    }
                }
            }
        }
    }
    FORR(i, 1, N)
    {
        if (a[i])
            c.pb(i);
    }
    M = (int)c.size();
    if (ans) {
        cout << M << endl;
        FOR(i, 0, M)
        cout << c[i] << " ";
        cout << endl;
    } else {
        cout << "-1" << endl;
    }
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FORR(i, 1, N)
    cin >> a[i];
    solve();
    return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define _ ios::sync_with_stdio(false);cin.tie(0);
#define __ cout<<fixed;cout<<setprecision(10);
#define int long long

int32_t main() {
	_ __

#ifdef LOCAL_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int d[n][2];
	for (int i = 0; i < n; i++) {
		cin >> d[i][0] >> d[i][1];
	}
	for (int i = 0; i < n - 2; i++) {
		if (d[i][0] == d[i][1] && d[i + 1][0] == d[i + 1][1] && d[i + 2][0] == d[i + 2][1]) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";


#ifdef LOCAL_JUDGE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif

	return 0;
}

Measured memory_bytes: 3604
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,M = mint()
print((1900*M+100*(N-M))*(2**M))

Measured memory_bytes: 68764
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;

import java.util.Scanner;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        Queue<Pair<String, Integer>> queue = new Queue<>();
        
        int n = sc.nextInt();
        int q = sc.nextInt();
        
        for (int i = 0; i < n; i++) {
            queue.enqueue(new Pair<String, Integer>(sc.next(), sc.nextInt()));
        }
        
        long pass = 0;
        
        while (!queue.isEmpty()) {
            Pair<String, Integer> p = queue.dequeue();
            int i = p.getValue() - q;
            if (i <= 0) {
                pass += (q + i);
                System.out.println(p.getKey() + " " + pass);
            } else {
                pass += q;
                p.setValue(i);
                queue.enqueue(p);
            }
        }
    }
}

class Stack<T> {
    private List<T> list;
    
    public Stack() {
        list = new ArrayList<>();
    }
    
    public void push(T t) {
        list.add(t);
    }
    
    public T pop() {
        T t = list.get(list.size()-1);
        list.remove(list.size()-1);
        return t;
    }
    
    public boolean isEmpty() {
        return list.isEmpty();
    }
}

class Queue<T> {
    Node<T> head;
    Node<T> tail;
    
    public void enqueue(T t) {
        Node<T> n = new Node<>(t);
        if (head == null) head = n;
        if (tail != null) {
            tail.next = n;
            n.prev = tail;
        }
        tail = n;
    }
    
    public T dequeue() {
        T t = head.elem;
        head = head.next;
        if (head != null) {
            head.prev = null;
        } else {
            tail = null;
        }
        return t;
    }
    
    public boolean isEmpty() {
        return head == null && tail == null;
    }
}

class Node<T> {
    T elem;
    Node<T> prev;
    Node<T> next;
    public Node(T t) { elem = t; }
}

class Pair<K, V> {
    K k;
    V v;
    public K getKey() { return k; }
    public void setKey(K k) { this.k = k; }
    public V getValue() { return v; }
    public void setValue(V v) { this.v = v; }
    public Pair(K k, V v) {
        this.k = k;
        this.v = v;
    }
}

Measured memory_bytes: 74040
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		char n = N.charAt(N.length() - 1);
		String ans = " ";
		if(n == '2' || n == '4' || n == '5' || n == '7' || n == '9'){
			ans = "hon";
		}else if(n == '3'){
			ans = "bon";
		}else{
			ans = "pon";
		}
		System.out.println(ans);
	}
}

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

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

#define MOD 1000000007

template<int64_t mod> struct Combination{
    vector<int64_t> f, rf;
 
    Combination(int max_n): f(max_n+1), rf(max_n+1){
        f[0] = 1;
        for(int i = 1;i <= max_n;i++) f[i] = f[i-1] * i % mod;
		int64_t a = f[max_n], inv = 1;
		for(int64_t b = mod-2;b > 0;b>>=1){
			if(b & 1) inv = inv*a % mod;
			a = a * a % mod;
		}
		for(int i = max_n;i >= 0;i--) inv = (rf[i] = inv) * i % MOD;
    }
 
    int64_t operator()(int n, int r){
        return (r < 0 || n < r) ? 0 : f[n] * rf[r] % mod * rf[n-r] % mod;
    }
	
	int kai(int n) { return f[n]; };
};

int pow_mod(int n, int m){
	int ans = 1;
	while(m > 0){
		if(m & 1) ans = (ans * n) % MOD;
		n = (n * n) % MOD;
		m >>= 1;
	}
	return ans;
}


signed main(){
	int b, w;
	cin >> b >> w;
	Combination<MOD> ncr(b+w);

	int two, nibe;
	two = nibe = pow_mod(2, MOD-2) % MOD;

	int n = b + w;
	cout << nibe << endl;

	int none = 0;

	int all[200010] = {};
	int ma[200010] = {};
	int sa[200010] = {};

	all[0] = ma[0] = 1;
	sa[0] = 0;

	for(int i = 1;i <= w-1;i++){
		all[i] = all[i-1] * 2 % MOD;
		ma[i] = ncr(i, i);
		sa[i] = (MOD + all[i] - ma[i]) % MOD;
	}

	for(int i = w;i <= w+b;i++){
		all[i] = sa[i-1]*2 % MOD + ma[i-1]% MOD;
		ma[i] = ncr(i, w-1);
		sa[i] = (MOD + all[i]-ma[i]) % MOD;
	}

	int nall[200010] = {};

	nall[b] = ncr(b, 0);

	for(int i = b+1;i < b+w;i++){
		nall[i] = nall[i-1]*2 % MOD;
		nall[i] = (nall[i] + ncr(i-1, i-b)) % MOD;
	}

	for(int i = 0;i < n;i++){
		all[i] = (MOD + all[i]-nall[i]) % MOD;
	}
	all[n] = 0;

	int ww = 0;
	for(int i = 2;i <= n;i++){
		nibe = (nibe * two) % MOD;
		int al = nibe * all[i-1] % MOD;

		if(i-1 >= w){
			ww += ncr(i-2, w-1) * nibe % MOD *2 % MOD;
			ww %= MOD;
		}

		int ans = (al + ww) % MOD;

		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 11520
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define int long long
#define For(i,x,y) for(int i = x; i <= y; ++i)
#define FOR For
#define rev_For(i,x,y) for(int i = x; i >= y; --i)
#define REV_FOR rev_For
#define ll long long
#define Size(v) ((int)v.size())
#define _section "\n--------------------\n"
#define fi first
#define se second
#define pb push_back
using namespace std;
// using namespace __gnu_pbds;


int n, k;
const int INF = 1e18 + 3;

void input() {
	cin >> n >> k;
}

void solve() {
	if (n < k) {
		cout << min(n, k - n);
		return;
	}
	else {
		int rem = (n - k) / k;
		int ret = INF;
		ret = min(ret, abs(n - (k * (rem - 1))));
		ret = min(ret, abs(n - (k * rem)));

		int now = abs(n - (k * (rem + 1)));

		ret = min(ret, now);
		ret = min(ret, k - now);

		cout << ret;
	}
}

signed main() {
#ifdef _DEBUG
	// freopen("INPUT.inp", "r", stdin);
	//freopen("OUTPUT.out", "w", stdout);
	clock_t start, end;
	start = clock();
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//------------------------------------------------------------------------------------
//----------------------------------MAIN PROGRAM--------------------------------------
	int t = 1;
	while (t--) {
		input();
		solve();
	}
//--------------------------------------END-------------------------------------------
//------------------------------------------------------------------------------------
#ifdef _DEBUG
	end = clock();
	cerr << "\n----------\nTime Elapsed: " << fixed << double(end - start) / double(CLOCKS_PER_SEC) << setprecision(6) << '\n';
#endif
	return 0;
}

Measured memory_bytes: 3660
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()

typedef unsigned long long ll;

int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

int main(){ 
int N; cin >> N;
vector<string> s(N);
rep(i,N) cin >> s[i];
map<string,ll> mp;
string x;
rep(i,N){
	sort(s[i].begin(),s[i].end());
	x = s[i];
	if(! mp.count(x)){
		mp[x] = 0;
	}
	else{
		mp[x] = mp[x] + 1;
	}
}
	ll cnt = 0;
	for(auto p : mp){
		
		cnt += (p.second + 1) * p.second / 2;

	}
	cout << cnt << endl;
}


Measured memory_bytes: 18176
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int []x = new int [n+1];
		int []y = new int [n+1];
		int []t = new int [n+1];
		
		x[0] = 0; y[0] = 0; t[0] = 0;
		int exist = 0;
		
		for (int i = 1; i <= n; i++) {
			t[i] =sc.nextInt();
			x[i] =sc.nextInt();
			y[i] =sc.nextInt();
			
			int X = Math.abs(x[i] - x[i - 1]);
			int Y = Math.abs(y[i] - y[i - 1]);
			int T = t[i] - t[i -1];
			
			if(T < X + Y || (X + Y)%2 != T%2) 
				 break;
			exist += 1;
		}
		if(exist == n)
			System.out.print("Yes");
		else
			System.out.println("No");
	    }
	}




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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
int main(int argc, char const *argv[])
{
	int x;
	int a[] = {400,600,800,1000,1200,1400,1600,1800};
	scanf("%d",&x);
	int pos = 0;
	while(a[pos] < x)
		pos++;
	if(a[pos] > x)
		pos--;
	printf("%d\n",8-pos);
	return 0;
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i <= (b); ++i)
#define fd(i, a, b) for (int i = (a); i >= (b); --i)
#define edge(i, u) for (int i = head[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define N 200005
#define ls(u) t[u].s[0]
#define rs(u) t[u].s[1]
#define lowbit(x) x & -x
#define ll long long
#define pb push
int n, m, ans, a[N];
struct node{
    int p, v;
    node (int p, int v) : p(p), v(v) {}
};
std::stack<node> q;
inline bool check (int x)
{
    while (!q.empty()) q.pop();
    q.pb(node(0, x));
    q.pb(node(a[1], 1));
    fo (i, 2, n)
    {
        if (a[i] > a[i - 1])
        {
            q.pb(node(a[i], 1));
        }
        else
        {
            while (1)
            {
                node now = q.top(); q.pop(); 
                node last = q.top();
                if (last.p < a[i] && now.v < x)
                {
                    if (now.p >= a[i])
                    {
                        if (last.p + 1 == a[i])
                        {
                            q.push(node(a[i], now.v + 1));
                        }
                        else
                        {
                            q.push(node(a[i] - 1, now.v));
                            q.push(node(a[i], now.v + 1));
                        }
                        break;
                    }
                    else
                    {
                        if (now.p == last.p + 1)
                        {
                            q.push(node(now.p, now.v + 1));
                        }
                        else
                        {
                            q.push(node(now.p - 1, now.v));
                            q.push(node(now.p, now.v + 1));
                        }
                        q.push(node(a[i], 1));
                        break;
                    }
                }
                if (last.p == 0) return 0;
            }
        }
    }
    return 1;
}
int main ()
{
    scanf("%d", &n);
    fo (i, 1, n) {scanf("%d", &a[i]);}
    int l = 1, r = n;
    while (l < r)
    {
        int mid = l + r>> 1;
        if (check(mid))
            r = mid;
        else
            l = mid + 1;
    }
    printf("%d\n", r);
    return 0;
}

Measured memory_bytes: 2720
#include <stdio.h>
long xxx[10][1001][101];
long pattern(int n,int s,int from){
    if(n>1){
        long i,x=0;
		if(xxx[n][s][from]>=0)x=xxx[n][s][from];
        else{
		for(i=s-100*(n-1)>from?s-100*(n-1):from; i<100 && i<=s ;i++){x+=pattern(n-1,s-i,i+1);}
		xxx[n][s][from]=x;
		}
        return x;
    }
    else{if(from<=s && s<=100)return 1; else return 0;}
}
 
int main(void){
    int n,s,i,j,k;
	for(i=0;i<10;i++){for(j=0;j<1001;j++){for(k=0;k<101;k++){xxx[i][j][k]=-1;}}}
    while(scanf("%d %d",&n,&s)*(n+s)){printf("%ld\n",pattern(n,s,0));}
    return 0;
}

Measured memory_bytes: 8496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  ll n, ans = LLONG_MAX;
  cin >> n;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) ans = min(ans, i + n / i - 2);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main() {
int N;
string str;
cin >> N >> str;
bool nxor[N];
for (int i = 0; i < N; i++) {
nxor[i] = (str[i] == 'o');
}
int line[N];
line[0] = 0;
line[1] = 0;
for (int i = 2; i < N; i++) {
if (line[i-1] == 0) {
line[i] = (nxor[i-1] ? line[i-2] : ~line[i-2]);
}
else {
line[i] = (nxor[i-1] ? ~line[i-2] : line[i-2]);
}
}
bool c = true;
if (nxor[0] && line[N-1] != line[1]) {
c = false;
}
if (!nxor[0] && line[N-1] == line[1]) {
c = false;
}
if (!line[N-1] && nxor[N-1] && line[N-2] != line[0]) {
c = false;
}
if (!line[N-1] && !nxor[N-1] && line[N-2] == line[0]) {
c = false;
}
if (line[N-1] && nxor[N-1] && line[N-2] == line[0]) {
c = false;
}
if (line[N-1] && !nxor[N-1] && line[N-2] != line[0]) {
c = false;
}
 
if (c) {
for(int i = 0; i < N; i++) {
cout << (!line[i] ? 'S' : 'W');
}
cout << endl;
return 0;
}
c = true;
 
line[0] = 0;
line[1] = -1;
for (int i = 2; i < N; i++) {
if (line[i-1] == 0) {
line[i] = (nxor[i-1] ? line[i-2] : ~line[i-2]);
}
else {
line[i] = (nxor[i-1] ? ~line[i-2] : line[i-2]);
}
}
if (nxor[0] && line[N-1] != line[1]) {
c = false;
}
if (!nxor[0] && line[N-1] == line[1]) {
c = false;
}
if (!line[N-1] && nxor[N-1] && line[N-2] != line[0]) {
c = false;
}
if (!line[N-1] && !nxor[N-1] && line[N-2] == line[0]) {
c = false;
}
if (line[N-1] && nxor[N-1] && line[N-2] == line[0]) {
c = false;
}
if (line[N-1] && !nxor[N-1] && line[N-2] != line[0]) {
c = false;
}
 
if (c) {
for(int i = 0; i < N; i++) {
cout << (!line[i] ? 'S' : 'W');
}
cout << endl;
return 0;
}
c = true;
 
line[0] = -1;
line[1] = 0;
for (int i = 2; i < N; i++) {
if (line[i-1] == 0) {
line[i] = (nxor[i-1] ? line[i-2] : ~line[i-2]);
}
else {
line[i] = (nxor[i-1] ? ~line[i-2] : line[i-2]);
}
}
 
if (nxor[0] && line[N-1] == line[1]) {
c = false;
}
if (!nxor[0] && line[N-1] != line[1]) {
c = false;
}
if (!line[N-1] && nxor[N-1] && line[N-2] != line[0]) {
c = false;
}
if (!line[N-1] && !nxor[N-1] && line[N-2] == line[0]) {
c = false;
}
if (line[N-1] && nxor[N-1] && line[N-2] == line[0]) {
c = false;
}
if (line[N-1] && !nxor[N-1] && line[N-2] != line[0]) {
c = false;
}
 
if (c) {
for(int i = 0; i < N; i++) {
cout << (!line[i] ? 'S' : 'W');
}
cout << endl;
return 0;
}
c = true;
 
line[0] = -1;
line[1] = -1;
for (int i = 2; i < N; i++) {
if (line[i-1] == 0) {
line[i] = (nxor[i-1] ? line[i-2] : ~line[i-2]);
}
else {
line[i] = (nxor[i-1] ? ~line[i-2] : line[i-2]);
}
}
 
if (nxor[0] && line[N-1] == line[1]) {
c = false;
}
if (!nxor[0] && line[N-1] != line[1]) {
c = false;
}
if (!line[N-1] && nxor[N-1] && line[N-2] != line[0]) {
c = false;
}
if (!line[N-1] && !nxor[N-1] && line[N-2] == line[0]) {
c = false;
}
if (line[N-1] && nxor[N-1] && line[N-2] == line[0]) {
c = false;
}
if (line[N-1] && !nxor[N-1] && line[N-2] != line[0]) {
c = false;
}
 
if (c) {
for(int i = 0; i < N; i++) {
cout << (!line[i] ? 'S' : 'W');
}
cout << endl;
return 0;
}
c = true;
 
cout << -1 << endl;
return 0;
 
}

Measured memory_bytes: 1024
/*
  Contest 074
  A - Bichrome Cells
  Rakesh Kumar --> 11/09/2020
 */

#include <bits/stdc++.h>

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

    int n = 0, a = 0;
    std::cin >> n >> a;
    std::cout << (n * n) - a << std::endl;


    return 0;
}


Measured memory_bytes: 3652
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())


h,w,k = MI()
C = LS(h)

# pprint(C)

def mycalc(c):
    count = 0
    for i in range(h):
        for j in range(w):
            if c[i][j] == '#':
                count += 1
    return count

n = h+w
ans = 0
for i in range(2**n):
    c = deepcopy(C)
    for j in range(n):
        if i & (2**j):
            if j>=0 and j<h:
                c[j] = ['.']*w
            else:
                col = j - h
                for r in range(h):
                    c[r][col] = '.'
    # pprint(c)
    count = mycalc(c)
    if count == k:
        ans += 1
print(ans)

Measured memory_bytes: 82972
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), i = 1, no = N, t = 1, j = 1;
		boolean ok = false;
		int[] a = new int[N+1];
		while (N-->0) a[i++] = sc.nextInt();
		while (no-->0) {
			if (a[j]==2) { ok = true; break; }
			j = a[j]; t++;
		}
		System.out.println(ok ? t : -1);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 59684
///https://atcoder.jp/contests/abc153/tasks/abc153_c
#include<bits/stdc++.h>
using namespace std;
int h[200001];
long long sum=0;

int main()
{

    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++) scanf("%d",h+i);
    sort(h,h+n);
    for(int i=0; i<n-k; i++) sum+= h[i];
    printf("%lld\n",sum);

    return 0;
}



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

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

    int a[n];
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }

    int sum_2 = sum;

    sum_2 /= n;
    int ans = 0;
    if(sum % n == 0){
        for(int i = 0; i < n; i++){
            ans += (sum_2 - a[i]) * (sum_2 - a[i]);
        }
    }else{
        int ans_2 = 0;
        for(int i = 0; i < n; i++){
            ans += (sum_2 - a[i]) * (sum_2 - a[i]);
        }
        sum_2++;
        for(int i = 0; i < n; i++){
            ans_2 += (sum_2 - a[i]) * (sum_2 - a[i]);
        }

        if(ans_2 <= ans){
            ans = ans_2;
        }
    }

    cout << ans << endl;
}

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

int main() {
    int a, b, c; cin >> a >> b >> c;
    if(a == b && b != c  || b == c && a != c || a == c && b != c){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;


int n;
int a[MAXN],b[MAXN];




void run() {
	scanf("%d",&n); REP(i,n) scanf("%d%d",&a[i],&b[i]);

	map<ll,int> L,R; ll dl=a[0],dr=a[0]; L[0]=+1; R[0]=+1; ll ret=0;
	FOR(i,1,n) {
		dl-=b[i]-a[i]; dr+=b[i-1]-a[i-1];
		ll lmx; { map<ll,int>::iterator it=L.end(); assert(it!=L.begin()); --it; lmx=dl+it->first; }
		ll rmn; { map<ll,int>::iterator it=R.begin(); assert(it!=R.end()); rmn=dr+it->first; }
		if(a[i]<lmx) {
			ret+=lmx-a[i];
			L[a[i]-dl]+=2;
			map<ll,int>::iterator it=L.end(); assert(it!=L.begin()); --it; assert(lmx==dl+it->first);
			--it->second; if(it->second==0) L.erase(it);
			R[lmx-dr]++;
		} else if(a[i]>rmn) {
			ret+=a[i]-rmn;
			R[a[i]-dr]+=2;
			map<ll,int>::iterator it=R.begin(); assert(it!=R.end()); rmn=dr+it->first; assert(rmn==dr+it->first);
			--it->second; if(it->second==0) R.erase(it);
			L[rmn-dl]++;
		} else {
			L[a[i]-dl]++;
			R[a[i]-dr]++;
		}
		//printf("ret=%lld\n",ret);
		//printf("L:"); for(map<ll,int>::iterator it=L.begin();it!=L.end();++it) printf(" %lld:%d",dl+it->first,it->second); puts("");
		//printf("R:"); for(map<ll,int>::iterator it=R.begin();it!=R.end();++it) printf(" %lld:%d",dr+it->first,it->second); puts("");
	}
	printf("%lld\n",ret);
}

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


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define ppll pair<pll,ll>
#define vi vector <ll>
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define f(i,x,n) for(ll i=x;i<n;i++)
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;} 
const ll N = 1e6 + 5, M = 1e18 + 7; 

int main(){
    FAST;
    ll n, k, t, m = 0, x = 0, i, ans = 0, j, y = 0, z = 4, c = 0;
    cin >> n;
    f(i, 1, n + 1){
        f(j, 1, n + 1){
            f(k, 1, n + 1){
                ans += __gcd(__gcd(i, j), k);
            }
        }
    }
    cout << ans;
}   

Measured memory_bytes: 3616