akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStore.Entry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.NoSuchElementException;

public class Main {

	void run() {
		Scanner sc = new Scanner();
		int n = (int) sc.nextLong();
		char[][] map = new char[n][n];
		for (int i = 0; i < n; ++i) {
			map[i] = sc.next().toCharArray();
		}

		// s(i,j)←map((i+a)%n,(j+b)%n)
		// s(i,j)=s(j,i)を満たすようにしたい
		// s(i,j)=s(j,i)⇔map((i+a)%n,(j+b)%n)==map((j+a)%n,(i+b)%n))
		// 0<=a,b<n
		// for all i,j map((i,j)==map((j+(a-b))%n,(i+(b-a))%n)
		// これより
		// map(a,b)=map(a+k,b-k)
		// map(i,j)=map(j+c,i-c)なるcを数えて、c
		// c=-(n-1),...,n-1
		// c=n-1=a-bの時 1
		// c=n-2=a-bの時2
		// c=n-3=a-bのとき3
		// c=1のとき
		// c=0のとき n
		int ans = 0;
		block: for (int c = -(n - 1); c <= n - 1; ++c) {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < n; ++j) {
					if (map[i][j] != map[(j + c + n) % n][(i - c + n) % n])
						continue block;
				}
			}
			ans += n - Math.abs(c);
		}
		System.out.println(ans);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 24532
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int a[10000];
int main()
{
	int i,j,k,n,m,x,y;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%d",&x);
		for(j=0;j<x;j++)
		{
			scanf("%d",&y);
			a[y]++;
		}
	}
	int ans=0;
	for(i=1;i<=m;i++)
	{
		if(a[i]==n)
		{
			ans++;
		}
	}
	printf("%d",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N,M;
vector<vector<int>>G;
bool flag=true;
int co[100005];
int wh,bl;
void dfs(int x){
    if(co[x]==1)wh++;
    else bl++;
    for(int i:G[x]){
        if(co[i]&&co[i]==co[x]){
            flag=false;return;
        }
        if(co[i])continue;
        co[i]=co[x]*-1;
        dfs(i);
    }
}
signed main(){
    cin>>N>>M;G.resize(N);
    rep(i,M){
        int a,b;cin>>a>>b;a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    co[0]=1;
    dfs(0);
    if(flag){
        cout<<wh*bl-M<<endl;
    }else {
        cout<<N*(N-1)/2-M<<endl;
    }
}


Measured memory_bytes: 7296
{-# LANGUAGE MultiWayIf #-}

import Data.List
import Data.Ord
import Data.Function
import Control.Arrow


main = do
  n <- readLn :: IO Int
  vs <- map read . words <$> getLine :: IO [Int]

  let
    f = map (length . head &&& map head) . groupBy ((==) `on` length) . reverse . sortBy (comparing length) . group . sort 
    xs = f $ [v | (i,v) <- zip [0..] vs, even i]
    ys = f $ [v | (i,v) <- zip [0..] vs, odd i]

    ((lx,xx):xs') = xs
    ((ly,yy):ys') = ys

  print $
    if
      | length xx == 1 && length yy == 1 ->
          if
            | head xx == head yy ->
              if
                | xs' == [] && ys' == [] -> min lx ly
                | xs' == [] && ys' /= [] -> n - (fst . head $ ys')
                | xs' /= [] && ys' == [] -> n - (fst . head $ xs')
                | otherwise -> n - max (lx + (fst . head $ ys')) (ly + (fst . head $ xs'))

            | otherwise -> n - lx - ly
      | otherwise -> n - lx - ly


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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int main()
{
    int X, A;
    cin >> X >> A;
    
    if (X < A) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}

Measured memory_bytes: 764
//
// Created by Wangzhe on 2019/10/19.
//

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll maxn = 2e5 + 10, INF = 0x3f3f3f3f;

const ll INFF = 1e12;

int a[maxn];


int main() {
    int a, b; cin >> a >> b;
    if (a > 9 || b > 9) puts("-1");
    else cout << a * b <<endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const long long md=1e9+7;
const int maxn=4010;
long long dp[2010][2010];
long long dq[2010][2010];
long long C[maxn][maxn];
long long pw2[maxn];
int main(){
//	freopen("E.in","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	C[0][0]=C[1][0]=C[1][1]=1;
	for(int i=1;i<maxn;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%md;
	}
	pw2[0]=1;
	for(int i=1;i<maxn;i++)
		pw2[i]=pw2[i-1]*2%md;
	for(int i=0;i<=n;i++)
		dq[i][0]=1;
	for(int j=1;j<=m;j++)
	{
		dp[0][j]=1;
		dq[0][j]=1;
		for(int i=1;i<=n;i++)
		{
			dp[i][j]=(dp[i-1][j]+C[j-1][i])%md;
			dq[i][j]=(dq[i-1][j]+dp[i][j])%md;
		}
	}
	if(n==1){
		printf("%d\n",m+1);
		return 0;
	}
	if(m==1){
		printf("%d\n",n+1);
		return 0;
	}
	long long ans=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n-i;j++)
		{
			if(j==0)
				ans=(ans+C[m-1][j])%md;
			else
				ans=(ans+C[m-1][j]*dq[n-i-j][j])%md;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

#define ll long long
#define ld double
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sc(a) scanf("%lld",&a);
#define sd(a) scanf("%lf",&a);
#define test() ll tt;cin>>tt;for(ll testcase=1;testcase<=tt;testcase++)
#define all(v) v.begin(),v.end()
#define vivek_ghosh ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000055
#define mod 1000000007
#define ff first
#define ss second
const int INF=0x3f3f3f3f;

ll power(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

ll modinv(ll a,ll m)
{
    ll g =__gcd(a, m);
    ll res=power(a, m-2, m);
    return res;
}

vb prime(MAX,true);
vl prm;
void sieve()
{
	prime[0] = prime[1] = false;
	for(ll p=2;p*p<MAX;p++)
	{
		if(prime[p])
		{
			for(ll i=p*p;i<MAX;i+=p)
				prime[i] = false;
		}
	}
	for(ll p=2;p<MAX;p++)
	{
		if(prime[p])
			prm.pb(p);
	}
}

ll n,m,t,i,j,k,q,x,y,ans=0,cnt=0,sum=0,mx=-1,mn=INT_MAX;
string s;


int main()
{
	vivek_ghosh;
	
	cin>>n>>k;
	
	ll a[n];
	for(i=0;i<n;i++)
	{
		a[i] = k+i;
		sum+=a[i];
	}
	ll ans = 0;
	ll temp = 0;
	cnt = INT_MAX;
	for(i=0;i<n;i++)
	{
		temp = 0;
		for(j=0;j<n;j++)
		{
			if(i!=j)
			{
				temp+=a[j];	
			}
		}
		if(abs(sum-temp)<cnt)
		{
			ans = temp;
			cnt = abs(sum-temp);
		}
	}
	
	cout<<ans<<endl;
	
	
	
	
	
	
	
	
	
	
	return 0;
}




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

namespace Atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var s = int.Parse(input);
            var hash = new HashSet<string>();
            foreach(var i in Enumerable.Range(0, s)) {hash.Add(Console.ReadLine()); }

            Console.WriteLine(hash.Count().ToString());
        }
    }
}


Measured memory_bytes: 47860
#include<stdio.h>
#include<math.h>
int a[1010];

int main(){
	int n;
	while(scanf("%d",&n),n){
		double s=0;
		for(int i=0;i<n;i++){
			scanf("%d",a+i);
			s+=a[i];
		}
		s/=n;
		double ans=0;
		for(int i=0;i<n;i++)ans+=(a[i]-s)*(a[i]-s);
		printf("%f\n",sqrt(ans/n));
	}
}


Measured memory_bytes: 2052
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int m1 = vs[0];
			int d1 = vs[1];
			vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int m2 = vs[0];
			int d2 = vs[1];
			int ans = 0;
			if (m1 != m2) {
				ans = 1;
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}


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

#define rep(i, u) for (int i = 0; i < u; i++)

using ll = long long;
using ull = unsigned long long;

int gcd(int x, int y) {
  while (y != 0) {
    int a = x % y;
    x = y;
    y = a;
  }
  return x;
}

int main() {
  int x, y;
  int ans;
  cin >> x >> y;
  if (x >= y) ans = gcd(x, y);
  else ans = gcd(y, x);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0);
  	ios::sync_with_stdio(false);
  	string s;
  	cin >> s;
  	map<char, int> cnt;
  	string ans = "yes";
  	for (int i = 0; i < s.length(); i++) {
      	if (cnt[s[i]] == 0)
          	cnt[s[i]]++;
      	else {
          	ans = "no";
          	break;
        }
    }
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <memory>
#include<time.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

typedef vector<double> vd;
typedef vector<vd> vvd;

int n;
double dfs(int mask,int pos,int last, vvd &dp,vi &r){
	if(pos==n){
		return r[last];
	}
	if(dp[mask][last]){
		return dp[mask][last];
	}
	double ret=INT_MAX;
	REP(i,n){
		if(!((1<<i)&mask)){
			ret=min(ret,dfs(mask|(1<<i),pos+1,i,dp,r)+sqrt(r[last]*r[i])*2);
		}
	}
	return dp[mask][last]=ret;
}

int main(){
	string line;
	while(getline(cin,line)){
		istringstream iss(line);
		int l;
		iss>>l;
		vi r;
		int rr;
		while(iss>>rr){
			r.push_back(rr);
		}
		n=r.size();

		double ans=INT_MAX;
		REP(i,n){
			vvd dp(1<<n,vd(n));
			ans=min(ans,dfs(1<<i,1,i,dp,r)+r[i]);
		}
		cout<<(ans<l+EPS?"OK":"NA")<<endl;
	}
}

Measured memory_bytes: 1620
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = string_to_int(inputs[0])
    count = 0
    for i in range(0, len(nums)-2):
        if nums[i+1] >= nums[i] and nums[i+1] <= nums[i+2]:
            count += 1
        elif nums[i+1] <= nums[i] and nums[i+1] >= nums[i+2]:
            count += 1
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll n;
ll a[100010];

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

  rep( i, n )
    std::cin >> a[i];

  std::sort( a, a+n );

  repi( i, n-1, n )
  {
    ll idx = std::lower_bound( a, a+i, (a[i]+1)/2 )-a;

    if( idx-1 >= 0 )
    {
      if( llabs(2*a[idx-1]-a[i]) > llabs(2*a[idx]-a[i]) )
        std::cout << a[n-1] << ' ' << a[idx] << std::endl;
      else
        std::cout << a[n-1] << ' ' << a[idx-1] << std::endl;
    }
    else
    {
      std::cout << a[n-1] << ' ' << a[idx] << std::endl;
    }
  }

  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	string s, t;
	cin >> s >> t;
	cout << t << s;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n= sc.nextInt();
        int[] l = new int[n];
        String ans = "No";
        
        for(int i=0; i<n; i++){
            l[i] = sc.nextInt();
        }
        
        Arrays.sort(l);
        int sum=0;
        
        for(int i=0; i<n-1; i++){
            sum+=l[i];
        }
        
        if(sum>l[n-1]){
            ans="Yes";
        }
        
        System.out.println(ans);
        
	}
}

Measured memory_bytes: 35760
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    ll res=min(a,min(b,min(c,min(d,e))));
    ll time=5+((n-1)/res);
    cout << time << "\n";
    return 0;
}   

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

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

    string S;
    cin >> S;

    int counter = 0;
    for(int i = 0; i < 3; ++i){
        if(S[i] == 'o'){
            counter += 100;
        }
    }

    cout << 700 + counter << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int a=0;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='C')a=1;
		else if(s[i]=='F'&&a==1)a=2;
	}
	if(a==2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

using ld = long double;
const ld eps = 1e-8, pi = acos(-1.0);

bool eq(ld a, ld b) {
	return abs(a - b) < eps;
}

using Point = complex<ld>;
class Line {
public:
	Point a, b;
};
class Circle {
public:
	Point p;
	ld r;
};

ld dot(Point a, Point b) {
	return real(conj(a) * b);
}

ld cross(Point a, Point b) {
	return imag(conj(a) * b);
}

int ccw(Point a, Point b, Point c) {
	b -= a, c -= a;
	if (cross(b, c) > eps) return 1;
	if (cross(b, c) < -eps) return -1;
	if (dot(b, c) < 0) return 2;
	if (norm(b) < norm(c)) return -2;
	return 0;
}

bool isis_ll(Line l, Line m) {
	return abs(cross(l.b - l.a, m.b - m.a)) > eps;
}

bool isis_ls(Line l, Line s) {
	return (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps);
}

bool isis_lp(Line l, Point p) {
	return abs(cross(l.b - p, l.a - p)) < eps;
}

bool isis_sp(Line s, Point p) {
	return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps;
}

Point proj(Line l, Point p) {
	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
	return l.a + t * (l.a - l.b);
}

Point is_ll(Line s, Line t) {
	Point sv = s.b - s.a, tv = t.b - t.a;
	assert(cross(sv, tv) != 0);
	return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

bool isis_ss(Line s, Line t) {
	if (isis_ll(s, t)) return isis_ls(s, t) && isis_ls(t, s);
	return isis_sp(s, t.a) || isis_sp(s, t.b) || isis_sp(t, s.a);
}

int main()
{
	int q;
	ld x1, x2, x3, x4, y1, y2, y3, y4;
	cin >> q;
	while (q--) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		Line l1 = { (Point) { x1, y1 }, (Point) { x2, y2 } };
		Line l2 = { (Point) { x3, y3 }, (Point) { x4, y4 } };
		cout << isis_ss(l1, l2) << endl;
	}
	return 0;
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define f(i,a,b) for(int i=(a); i<=(b);++i)
int main()
{
    double x;
    cin>>x;
    double r=2*x*acos(-1);
    cout<<r<<endl;
        return 0;
    }


Measured memory_bytes: 3740
while(True):
    cards=list(input())
    if(cards[0]=="-"):
        break
    else:
        m=int(input())
        for i in range(m):
            h=int(input())
            withdraw=cards[:h]
            rest=cards[h:]
            cards=rest+withdraw
#            print(cards)
        print(''.join(cards))



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

using ll = long long;

const int MAX_N = 1e5+10;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int N, a[MAX_N];
ll dp[MAX_N][2];

void solve()
{
	dp[0][0]=0, dp[0][1]=-INF;
	for(int i=0;i<N;++i){
		dp[i+1][0] = max(dp[i][0]+a[i], dp[i][1]-a[i]);
		dp[i+1][1] = max(dp[i][0]-a[i], dp[i][1]+a[i]);
	}
	cout << dp[N][0] << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N;++i)cin>>a[i];
	solve();
	return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define minit(a, b) memset(a, b, sizeof(a))

typedef pair< int, int > pii;

int n, deg[888], p[888], d[888];
vector< vector< pii > > edges;

pii rec(int v, int prev, int dst) {
	pii res(dst, v);
	
	int edge_num = (int)edges[v].size();
	
	for_(i,0,edge_num) {
		pii e = edges[v][i];
		int u = e.first, du = e.second;
		if (u == prev) continue;
		pii pi = rec(u, v, dst + du);
		res = max(res, pi);
	}
	
	return res;
}

int diam() {
	for_(v,0,n) if (deg[v] > 1) {
		pii st = rec(v, -1, 0);
		pii ret = rec(st.second, -1, 0);
		return ret.first;
	}
	return -1;
}

int main() {
	while (cin >> n, n) {
		minit(deg, 0);
		
		for_(i,1,n) {
			cin >> p[i];
			--p[i];
			
			++deg[i];
			++deg[p[i]];
		}
		
		for_(i,1,n) cin >> d[i];
		
		edges.assign(n, vector< pii >());
		
		int sum_of_leaf = 0, sum_of_noleaf = 0;
		
		for_(i,1,n) {
			int u = i, v = p[i];
			
			if (deg[u] == 1 || deg[v] == 1) {
				sum_of_leaf += d[i];
			} else {
				edges[u].push_back(pii(v, d[i]));
				edges[v].push_back(pii(u, d[i]));
				sum_of_noleaf += 3 * d[i];
			}
		}
		
		int diameter = diam();
		cout << sum_of_leaf + (sum_of_noleaf - diameter) << endl;
	}
}

Measured memory_bytes: 1364
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  map<string,ll> S;
  for(ll i=0;i<N;i++) {
string s;
    cin>>s;
    S[s]++;
  }
  vector<pair<string,ll>> vec(0);
  ll count=0;
  for(auto x:S) {
    vec.push_back(x);
    count=max(count,x.second);
  }
  
  sort(all(vec));
  for(ll i=0;i<vec.size();i++) {
if(vec[i].second==count) {
cout<<vec[i].first<<endl;
}
  }
  
}


Measured memory_bytes: 29212
fun main(arr: Array<String>) {
    println(if(solve(readLine()!!)) "YES" else "NO")
}

fun solve(s:String):Boolean {
    val target = "AKIHABARA".toList()
    val tmp = mutableListOf<Char>()
    tmp.addAll(s.toList())
    for(i in target.indices) {
        if(i > tmp.lastIndex || target[i] != tmp[i]) {
            if(target[i] == 'A') {
                tmp.add(i, 'A')
            } else {
                return false
            }
        }
    }
    return target.joinToString("") == tmp.joinToString("")
}

Measured memory_bytes: 36528
N, K = map(int, input().split())
arr = list(map(int, input().split()))
check = [0]*N
index = 0
cnt = 0
while True:
    if cnt == K:
        print(index+1)
        exit()
    if check[index] == 1:
        break
    check[index] = 1
    index = arr[index]-1
    cnt += 1

index2 = 0
first_cnt = 0
while True:
    if index2 == index:
        break
    index2 = arr[index2]-1
    first_cnt += 1

ans_cnt = ((K-first_cnt) % (cnt-first_cnt))+first_cnt
index = 0
cnt = 0
while True:
    if cnt == ans_cnt:
        break
    index = arr[index]-1
    cnt += 1
print(index+1)


Measured memory_bytes: 92404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define pb push_back
vector<ll> enum_div(ll d){
    vector<ll>res;
    for(ll i=1;i*i<=d;++i){
        if(d%i==0){
            res.pb(i);
            if(i*i!=d)res.pb(d/i);
        }
    }
    return res;
}
int main(void){
    // Your code here!
    ll n;
    cin>>n;
    vector<ll>a(n);
    rep(0,i,n){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    vector<ll>pa;
    ll ans=0;
    rep(0,i,n){
        vector<ll>d=enum_div(a[i]);
        bool t=true;
        rep(0,j,(ll)d.size()){
            if(binary_search(pa.begin(),pa.end(),d[j]))t=false;
        }
        pa.pb(a[i]);
        if(i>0)if(a[i]==a[i-1])continue;
        if(i<n-1)if(a[i+1]==a[i])continue;
        if(t)++ans;
    }
    cout<<ans;
}

Measured memory_bytes: 6932
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

pair<ll, ll> dfs(vv<int>& tree, int v, int p) {
    ll w = 1, b = 1;
    for (int u : tree[v]) {
        if (u != p) {
            auto r = dfs(tree, u, v);
            w = w * (r.first + r.second) % MOD;
            b = b * r.first % MOD;
        }
    }
    return { w, b };
}

int main() {
    int N;
    cin >> N;
    vv<int> tree(N);
    rep(i, N - 1) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }

    auto r = dfs(tree, 0, -1);
    write((r.first + r.second) % MOD);
}

Measured memory_bytes: 12672
n, m = map(int,input().split())
lst = [-1 for i in range(n + 1)]
for i in range(m):
    x = int(input())
    lst[x] = 0

lst[0] = 1
for i in range(1, n + 1):
    if (i == 1):
        if(lst[1] == -1):
            lst[1] = 1
    elif (lst[i] == 0):
        pass
    else:
        lst[i] = (lst[i - 1] + lst[i - 2])%(1000000007)

print(lst[n])


Measured memory_bytes: 12904
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

    public static void main(String[] args) throws IOException
    {
        BufferedReader bReader =
                       new BufferedReader(new InputStreamReader(System.in));
        int datanum;


        //datanumに代入し、datanum != 0が真か偽か判定
        while ( (datanum = Integer.parseInt(bReader.readLine())) != 0 )
        {
            //----------datanumが0でない時の処理-----------

            String[][] dataSet = new String[datanum][datanum];
            String inputStr;

            for ( int x = 0; x < datanum; x++ )
            {
                //データセットのi行目を入力
                inputStr = bReader.readLine();
                dataSet[x] = inputStr.split(" ");
            }

            //表示部
            for ( int x = 0; x < datanum; x++ )
            {
                int rmul = 0;
                for ( int y = 0; y < datanum; y++ )
                {
                    int output = Integer.parseInt(dataSet[x][y]);
                    rmul += output;
                    System.out.printf("%5d", output);
                }

                System.out.printf("%5d", rmul);
                if ( x == datanum - 1 )
                {
                    int cmulsum = 0;
                    System.out.println();
                    for ( int i = 0; i < datanum; i++ )
                    {
                        int cmul = 0;
                        for ( int j = 0; j < datanum; j++ )
                        {
                            cmul += Integer.parseInt(dataSet[j][i]);
                        }
                        System.out.printf("%5d", cmul);
                        cmulsum += cmul;
                        cmul = 0;
                    }
                    System.out.printf("%5d", cmulsum);
                }

                System.out.println();
            }
        }
    }
}

Measured memory_bytes: 12000
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let s: i32 = sc.read();
    let w: i32 = sc.read();
    let ans = if w >= s { "unsafe" } else { "safe" };
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 2160
#include <bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;

const int N = 1e4 + 5, M = 105, mod = 1e9 + 7, inf = 1e18;

string A, B;
int n, d, dp[N][2][2][M];

int go(int pos, bool bigA, bool smallB, int rem){
    if(pos >= n)
        return rem % d == 0;

    int &ans = dp[pos][bigA][smallB][rem];
    if(~ans)
        return ans;
    ans = 0;
    for(int i = 0; i < 10; i++){
        if(!bigA && i < A[pos] - '0')   continue;
        if(!smallB && i > B[pos] - '0') continue;

        ans = (ans + go(pos + 1, bigA || (i > A[pos] - '0'), smallB || (i < B[pos] - '0'), (rem + i)%d)) % mod;
    }
    return ans;
}

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

    memset(dp, -1, sizeof(dp));
    cin >> B >> d;
    A = "1";
    reverse(A.begin(), A.end());
    while(sz(A) < sz(B))
        A.push_back('0');
    reverse(A.begin(), A.end());
    n = sz(B);
    int ans = 0;

    for(int i = 0; i < 10; i++){
        if(i < A[0] - '0')  continue;
        if(i > B[0] - '0')  continue;

        ans += go(1, i > A[0] - '0', i < B[0] - '0', i % d);
        ans %= mod;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 34176
#include<stdio.h>
#include<string.h>
int main(){
	char a[10];
	while(scanf("%s",a)!=EOF){
		a[0]=a[0]-'0';a[1]=a[1]-'0';a[2]=a[2]-'0';a[3]=a[3]-'0';
		if	   (a[0]+a[1]+a[2]+a[3]==7)printf("%d+%d+%d+%d=7\n",a[0],a[1],a[2],a[3]);
		else if(a[0]+a[1]+a[2]-a[3]==7)printf("%d+%d+%d-%d=7\n",a[0],a[1],a[2],a[3]);
		else if(a[0]+a[1]-a[2]+a[3]==7)printf("%d+%d-%d+%d=7\n",a[0],a[1],a[2],a[3]);
		else if(a[0]+a[1]-a[2]-a[3]==7)printf("%d+%d-%d-%d=7\n",a[0],a[1],a[2],a[3]);
		else if(a[0]-a[1]+a[2]+a[3]==7)printf("%d-%d+%d+%d=7\n",a[0],a[1],a[2],a[3]);
		else if(a[0]-a[1]+a[2]-a[3]==7)printf("%d-%d+%d-%d=7\n",a[0],a[1],a[2],a[3]);
		else if(a[0]-a[1]-a[2]+a[3]==7)printf("%d-%d-%d+%d=7\n",a[0],a[1],a[2],a[3]);
		else if(a[0]-a[1]-a[2]-a[3]==7)printf("%d-%d-%d-%d=7\n",a[0],a[1],a[2],a[3]);
	}
	return 0;
}

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

int main(){
    string a,b;
    cin >> a >> b;
    int c = stoi(a+b);
    for(int i = 0; i < 400; i++) {
        if(c == i*i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;

vec q(300001,0);
int main() 
{

 fast();
  

  ll a,b;
  cin>>a>>b;
  if(b==1)
  {
    cout<<0;
    return 0;
  }
  a--;
  ll s=1;
  f(i,1,1000)
  {
      s+=a;
   
      if(s>=b)
      {
        cout<<i<<edl;
        return 0;
      }
  }
  

 
  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 


Measured memory_bytes: 2560
import math
a,b,c= map(float,input().split())
def triangle(A,B,C):
    S = math.sin(math.radians(C))*A*B/2
    L = A+B+math.sqrt(A**2+b**2-2*A*B*math.cos(math.radians(C)))
    H=2*S/A
    print(S)
    print(L)
    print(H)

triangle(a,b,c)



Measured memory_bytes: 5700
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

const int MAX = 55;
int n;
int dp[MAX];

int solve(int n) {
    if (dp[n] != -1) return dp[n];
    return dp[n] = (solve(n-1) + solve(n-2));
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    memset(dp, -1, sizeof(dp));
    dp[0] = 1;
    dp[1] = 1;
    scanf("%d", &n);
    printf("%d\n", solve(n));
    return 0;
}

Measured memory_bytes: 3208
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define f first
#define s second
#define y1 yasfasf
#define kz ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILE "substring"

#define fr freopen(FILE".in", "r", stdin); freopen(FILE".out", "w", stdout);
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef struct node* treap;

const int N = 111, inf = 1e9;
const ll linf = 1e18, mod = 1e9 + 7;

int n, m, c[N];
vector <int> v;
multiset <int> s;

int main(){
	cin >> n >> m;
	for(int i = 1; i <= n; ++i)
	for(int j = 1; j <= m; ++j){
		char ch;
		cin >> ch;
		c[ch - 'a']++;
	}
	for(int i = 0; i < 26; ++i)
		s.insert(c[i]);
	for(int i = 1; i <= (n + 1) / 2; ++i)
	for(int j = 1; j <= (m + 1) / 2; ++j){
		int r = 2;
		if(n % 2 == 1 && n / 2 + 1 == i)
			r = 1;
		int c = 2;
		if(m % 2 == 1 && m / 2 + 1 == j)
			c = 1;
		v.pb(r * c);
	}
	sort(v.rbegin(), v.rend());
	for(auto j : v){
		int u = *s.rbegin();
		s.erase(s.find(u));
		if(u < j){
			cout << "No";
			return 0;
		}
		u -= j;
		if(u)
			s.insert(u);
	}
	cout << "Yes";
	return 0;
}           

Measured memory_bytes: 256
package main

import (
	"io"
	"os"

	"fmt"

	"sort"
)

func Solve(in io.Reader, out io.Writer) {
	a := make([]int, 3)
	var k int
	fmt.Fscan(in, &a[0], &a[1], &a[2])
	fmt.Fscan(in, &k)

	sort.Ints(a)

	fmt.Fprintln(out, a[0]+a[1]+pow(a[2], k))
}

func pow(a, b int) int {
	if b <= 0 {
		return a
	}
	return pow(a*2, b-1)
}

func main() {
	Solve(os.Stdin, os.Stdout)
}


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

#define INF 1000000007
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl << "\n" ;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		int k,n;
		cin >> k >> n;
		vi A(n);
		for(auto &it : A) cin >> it;
		int mx=0;
		for(int i=0;i<n;i++) mx = max(mx,A[i+1]-A[i]);
		mx = max(mx,A[0] + k-A[n-1]);
		cout << k - mx endl
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll h, w, s, t;
int main(){
    cin>>h>>w>>s>>t;

    if(h%2!=0 && w%2!=0 && ((s%2==0 && t%2!=0) || (s%2!=0 && t%2==0))) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3108
N = int(input())
AList = list(map(int, input().split()))
BList = list(map(int, input().split()))
BList.append(0)
CList = [0] #前の勇者の余力
Answer = 0
for i in range(0,N+1):
    if BList[i]+CList[i] > AList[i]:
        CList.append(min(BList[i]+CList[i]-AList[i],BList[i]))
        Answer += AList[i]
    else:
        CList.append(0)
        Answer += BList[i]+CList[i]
print(Answer)

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

int main() {

   int a,b,c;
  
  cin >> a >> b;
  
  if(a==1&&b==2){
  c=3;
  }
  if(a==2&&b==1){
  c=3;
  } 
  if(a==2&&b==3){
  c=1;
  }
    if(a==3&&b==2){
  c=1;
  }
    if(a==1&&b==3){
  c=2;
  }
    if(a==3&&b==1){
  c=2;
  }
  
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;

long long power(long long a, long long b) {
    //a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
    }
  ll int binomial(ll int n, ll int k) 
{ 
    ll int C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll int i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (int j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 
  vector<int> pr;
void Sieve(ll int n) 
{ 
    bool prime[10000000];
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            pr.push_back(p);
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}
 




//It reurns Fn,Fn+1
pair<int, int> fib (int n) {
    if (n == 0)
        return {0, 1};

    auto p = fib(n >> 1);
    int c = p.first * (2 * p.second - p.first);
    int d = p.first * p.first + p.second * p.second;
    if (n & 1)
        return {d, c + d};
    else
        return {c, d};
}


  
int main() {
     int n;
     cin>>n;
     int k;
     cin>>k;
     int a[n];
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
     }
     sort(a,a+n);
     int s=0;
     for(int i=0;i<k;i++)
     {
         s+=a[i];
     }
     cout<<s<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  vi a(3);
  rep(i,3){
    cin >> a[i];
  }
  sort(all(a));
  print(a[0]+ a[1]);
}

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

def topological_sort(graph: list, n_v: int) -> list:
    # graph[node] = [(cost, to)]
    indegree = [0] * n_v # 各頂点の入次数
    for i in range(n_v):
        for c, v in graph[i]:
            indegree[v] += 1

    cand = deque([i for i in range(n_v) if indegree[i] == 0])
    res = []
    while cand:
        v1 = cand.popleft()
        res.append(v1)
        for c, v2 in graph[v1]:
            indegree[v2] -= 1
            if indegree[v2] == 0:
                cand.append(v2)

    return res


n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    edges[l].append((d, r))

ts = topological_sort(edges, n)

if len(ts) != n:
    # Not DAG
    ans = "No"
else:
    # DAG
    dist = [-1] * n
    ans = "Yes"
    for v in ts:
        if dist[v] == -1:
            dist[v] = 0

        for c, u in edges[v]:
            if dist[u] == -1:
                dist[u] = dist[v] + c
            elif dist[u] != dist[v] + c:
                ans = "No"
                break

print(ans)


Measured memory_bytes: 41716
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    s = S()
    c = ''
    cnt = 0
    for i in range(N):
        if c != s[i]:
            cnt += 1
        c = s[i]
    print(cnt)

main()



Measured memory_bytes: 5716
#include <iostream>
  
using namespace std;  
  
// ??\???  
int a, b;  
  
void solve()  
{  
    int res = 0;  
  
    a += b;  
  
    for (; a; a /= 10)  
        res++;  
  
    cout << res << endl;  
}  
  
int main()  
{  
    while (cin >> a >> b)  
        solve();  
  
    return 0;  
} 

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

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

#define     _test int _TC; cin >> _TC; while(_TC--)
#define     CS(x) cout << "Case " << x << ": ";
#define     precision(n) cout << fixed << setprecision(n);
#define     Clear(a, b) memset(a, b, sizeof(a))
#define     sq(x) ((x) * 1LL * (x))
#define     eb emplace_back
#define     all(_n) _n.begin(), _n.end()
#define     rall(_n) _n.rbegin(), _n.rend()
#define     endl "\n"
#define     show(x) cout << x << endl
#define     nl cout << endl
#define     sz(x) int(x.size())
#define     gcd(a, b) __gcd(a, b)
#define     lcm(a, b) (abs((a) * (b)) / gcd(a, b))
#define     parity(a, b) ((a&1) ^ (b&1))
#define     make_unique(x) sort(all((x))); (x).erase(unique(all((x))), (x).end())
#define     IN(a) for(auto &it : a) cin >> it

template <typename T> void print (T t){ for(const auto &it : t) cout << it << ' '; nl; }
template <typename T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key find_by_order

const    double Pi = acos(-1.0);
const    int Mod = 1e9 + 7;
const    int Inf = 1 << 30; // INT_MAX = (1LL << 31) -1 // Inf -> 1e9
const    int Maxx = 1e6 + 10;

/************************************[Code Starts Here]************************************/


void _case()
{
	int n; cin >> n;
	precision(2)
	show(2*Pi*n);
}

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    _case();
    return 0;
}




Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	ll m=0,a=0,r=0,c=0,h=0;
	rep(i,n){
		string s;cin>>s;
		if(s[0]=='M') m++;
		else if(s[0]=='A') a++;
		else if(s[0]=='R') r++;
		else if(s[0]=='C') c++;
		else if(s[0]=='H') h++;
	}
	ll ans=m*a*r+(c+h)*(m*a+a*r+r*m)+(m+a+r)*c*h;

	cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,d;
    cin >> a>>b;
    c=b-a;
    d=0;
    for(int i=1;i<c;i++){
        d+=i;
    }
    cout << d-a<<endl;
    return 0;
}


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

#define rep(i, N) for (int i = 0; i < (N); i++)

using ll = long long;

const int X = 5000;
const int MOD = 998244353;

ll C[X + 1][X + 1];

ll H(int N, int K) {
	if (K == 0) {
		return N == 0;
	}
	return C[N + K - 1][K - 1];
}

ll f(int s, int t, int N) {
	ll ans = 0, coef = 1;
	for (int r = 0; r <= s; r++) {
		ll x = C[s][r];
		if (N - r >= 0) {
			x = x * H(N - r, r + t) % MOD;
			x = x * coef % MOD;
			ans = (ans + x) % MOD;
		}
		coef = coef * 2 % MOD;
	}
	return ans;
}

int main() {
	rep(x, X + 1) {
		C[x][0] = 1;
		for (int y = 1; y <= x; y++) {
			C[x][y] = (C[x - 1][y - 1] + C[x - 1][y]) % MOD;
		}
	}
	int K, N; cin >> K >> N;
	for (int i = 2; i <= K * 2; i++) {
		int s = 0, t = K;
		bool z = false;
		for (int k = 1; k <= K; k++) {
			int _k = i - k;
			if (!(1 <= _k && _k <= K)) {
				continue;
			}
			if (k < _k) {
				s++;
				t -= 2;
			}
			if (k == _k) {
				z = true;
				t--;
			}
		}
		t = max(0, t);
		// cerr << s << ' ' << t << ' ' << z << endl;
		ll ans = f(s, t, N);
		if (z) {
			ans = (ans + f(s, t, N - 1)) % MOD;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 193792
N, M = gets.split.map{|i|i.to_i}
n1 = 0
n2 = N - 1
M.times{|m|
    puts "%d %d" % [n1 + 1, n2 + 1]
    #warn "diff:%d %d" % [(n2 - n1) % N, (n1 - n2) % N]
    n1 += 1
    n2 -= 1
    if N.even? && n1 == N / 4
        n2 -= 1
    end
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    deque<int> q;
    rep(i,n){
        int m; cin >> m;
        int index = lower_bound(all(q),m)-q.begin(); //m以上のインデックスを探す
        if(index == 0)q.push_front(m);
        else q[index - 1] = m;
    }
    cout << q.size() << endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>
#include <set>

using namespace std;


int main() {


    string s;
    cin >> s;

    for (int i = 0; i < 3; i++) {

        if (s[i] == '1') {
            s[i] = '9';
        } else {
            s[i] = '1';
        }

    }

    cout << s << "\n";

    return 0;
}

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

using namespace std;
using ll=long long int;
ll dp[401][401];
ll sum[401];
int a[401];

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i]; sum[i]=a[i]+sum[i-1];
    }
    for(int len=2;len<=n;len++) {
        for(int i=1;i<=n-len+1;i++) {
            int j=i+len-1;
            for(int k=i;k<j;k++) {
                if(!dp[i][j]) dp[i][j]=dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1];
                else dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]);
            }
        }
    }
    cout<<dp[1][n]<<endl;
}


Measured memory_bytes: 1536