akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
from queue import Queue
# 12:55~
sys.setrecursionlimit(10**9)

N,M = map(int,input().split())
uv = [list(map(int,input().split())) for _ in range(M)]
S,T = map(int,input().split())

S -= 1
T -= 1
#%%
adj_list = [[[] for _ in range(3)] for _ in range(N)]
for u,v in uv:
    for i in range(3):
        adj_list[u-1][i].append([v-1,(i+1)%3])


INF = 10**9+7
dist = [[INF]*3 for _ in range(N)]
dist[S][0] = 0

stack = Queue()
stack.put([S,0])
while not stack.empty():
    v,c = stack.get()
    nxt_v = adj_list[v][c]
    for nv,nc in nxt_v:
        if dist[nv][nc]==INF:
            dist[nv][nc] = dist[v][c] + 1
            stack.put([nv,nc])
            
            
if dist[T][0]==INF:
    ans = -1
else:
    ans = dist[T][0]//3
print(ans)
            
        
        
        
    





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

	public static void main(String[] args) {
	   Scanner sc = new Scanner(System.in);
	   
	   char []s = sc.next().toCharArray();
	   int temp = -1;
	   	   
	   for(int i = 0; i < s.length; i++) {
		 if(i % 2 == 0) {
			 if(s[i] !='R'&&s[i] !='U'&&s[i] !='D'){
				temp = 0;	 
				 break;
		 }
		}
		 if(i % 2 == 1) {
			 if(s[i] !='L'&&s[i] !='U'&&s[i] !='D'){
				 temp = 0;
					 break;
		 }
			 
	   }
		 }
	   if(temp == -1) {
		   System.out.println("Yes");
	   }
	   else {
		   System.out.println("No");
	   }
	   
	}
	}


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

int dp[100001];
vector <int> v;
int n,t;
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	fill(dp,dp+100001,1e9);
	dp[0] = 0;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		v.push_back(t);
	}

	for(int i=1;i<n;i++)
	{
		if(i-1>=0)
		{
			dp[i] = min(dp[i],dp[i-1] + abs(v[i] - v[i-1]));
		}
		if(i-2>=0)
		{
			dp[i] = min(dp[i],dp[i-2] + abs(v[i] - v[i-2]));
		}
	}

	cout << dp[n-1] << '\n';
	
	return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int gcd(int a,int b) {
    if(a < b) swap(a,b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,X;
    cin >> n >> X;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = abs(x[0]-X);
    rep2(i,1,n) ans = gcd(ans,abs(x[i]-X));
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

int main(void)
{
    char str[201], stra[201], strb[201];
    int m, i, j, h, lstr, k = 0;
    
    while(1){
        scanf("%s", str);
        lstr = strlen(str);
        if(strcmp(str, "-") == 0 && lstr == 1){
            break;
        }
        scanf("%d", &m);
        for(i = 0; i < m; i++){
            scanf("%d", &h);
            strcpy(stra, str);
            for(j = 0; j < h; j++){
                str[lstr - h + j] = stra[j];
            }
            for(j = 0; j < lstr - h; j++){
                str[j] = stra[j + h];
            }
        }
        for(j = 0; j < lstr; j++){
            strb[k++] = str[j];
        }
        strb[k++] = '\n';
    }
    strb[k] = '\0';
    printf("%s", strb);

    return 0;
}


Measured memory_bytes: 2056
public class Main {


  private static void solve() {
    long a = ni();
    long b = ni();
    long k = ni();
    for (long i = Math.min(a, b); i >= 1 ; i --) {
      if (a % i == 0 && b % i == 0) {
        k --;
        if (k == 0) {
          System.out.println(i);
        }
      }
    }
  }
  
  public static long gcd(long a, long b) {
    while (b > 0){
        long c = a;
        a = b;
        b = c % b;
    }
    return a;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	ll n; cin>>n;
	if(n==2){ cout<<1; return 0; }
	ll ans = 1;
	for(ll i=2;i<=sqrt(n-1);i++)
	{
	    if((n-1)%i==0)
	    {
	        ans++;
	        if((n-1)/i != i) ans++;
	    }
	}
	for(ll i=2;i<=sqrt(n);i++)
	{
	    if(n%i==0)
	    {
	        ll j=n;
	        while(j%i==0) j/=i;
	        if(j%i==1) ans++;
	        if(n/i!=i)
	        {
	            ll k=n; ll p=n/i;
	            while(k%p==0) k/=p;
	            if(k%p==1) ans++;
	            
	        }
	    }
	}
	cout<<ans+1;
	
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int t = scan.nextInt();
	int y = scan.nextInt();
	int m = t*y;
	int n = 2*t + 2*y;

	System.out.println(m + " " + n);
	}
}

Measured memory_bytes: 17156
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;} 
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
    int n,ans = 0;
    cin >> n;
    while(n){
        ans += n%10;
        n /= 10; 
    }   
    if(ans == 1) cout << 10 << '\n';
    else cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e17;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b;
    cin >> a >> b;
    cout << max(a * b, max(a - b, a + b)) << ENDL;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    ll n;
    cin >> n;
    ll arr[n];
    ll sum = 0;
    forn(i, n) cin >> arr[i], sum += arr[i];
    ll mn = 1e18;
    for (int y = -100; y <= 100; y++) {
        ll cost = 0;
        forn(i, n) cost += (arr[i] - y) * (arr[i] - y);
        mn = min(mn, cost);
    }
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define pii pair <int,int>
#define vpii vector< pair<int,int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int MAX = 1e5 + 5;
const int inf = 1e9 + 5;
vi adj[MAX];
void dfs(int x, int p, vi &d)
{
	for(auto v : adj[x]){
		if(v != p){
			d[v] = d[x] + 1;
			dfs(v, x, d);
		}
	}
}
int main()
{
	boost;
	int n, a, b, u, v, i;
	cin >> n >> u >> v;
	fo(i, 0, n - 1){
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	vi d1(MAX, 0), d2(MAX, 0);
	dfs(u, -1, d1);
	dfs(v, -1, d2);
	int ans = 0;
	foe(i, 1, n){
		if(d1[i] < d2[i])
		ans = max(ans, d2[i] - 1);
	}
	cout << ans;
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (ll i = (ll)(start); i < (ll)(n); ++i)
ll N, M, K;
void func()
{
    cin >> N >> M >> K;
    ll ans = 0, tmp;
    ll a[N + 1] = {}, b[M + 1] = {};
    rep(i, 1, N + 1)
    {
        cin >> tmp;
        a[i] = a[i - 1] + tmp;
    }
    rep(i, 1, M + 1)
    {
        cin >> tmp;
        b[i] = b[i - 1] + tmp;
    }
    ll j = M;
    rep(i, 0, N + 1)
    {
        if (a[i] > K)
            break;
        while (j)
        {
            if (b[j] <= K - a[i])
                break;
            --j;
        }
        ans = max(ans, i + j);
    }
    cout << ans << endl;
}
int main()
{
    func();
}

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

const int maxn = (int) 2e5 + 20;

#define LL long long

LL n, x;
LL B[maxn], L[maxn], R[maxn];
LL sum[maxn];
LL tsum[maxn];
int rk[maxn];


bool vis[maxn];


int gao(LL score)
{
    LL tot = 0;
    LL les = score % x;
    for(int i = 0; i < n; i++)
    {
        rk[i] = i;
        vis[i] = 0;
        tot -= B[i] * L[i];

        sum[i] = (x - B[i]) * R[i] + B[i] * L[i];

        if(les >= B[i]) tsum[i] = (les - B[i]) * R[i] + B[i] * L[i];
        else tsum[i] = les * L[i];
    }

    sort(rk, rk + n, [](int x, int y){
         if(sum[x] == sum[y]) return tsum[x] < tsum[y];
         return sum[x] > sum[y];
         });

    int k = score / x;
    LL pre = 0;
    for(int i = 0; i < k; i++) pre += sum[rk[i]];

    if(k == n) return tot + pre >= 0;

    LL k1 = sum[rk[k]];

    LL mx = 0;
    for(int i = 0; i < n; i++)
    {
        if(i < k) mx = max(mx, pre - sum[rk[i]] + k1 + tsum[rk[i]]);
        else mx = max(mx, pre + tsum[rk[i]]);
    }

    return tot + mx >= 0;
}

void work()
{
    cin >>n >>x;

    for(int i = 0; i < n; i++)
        cin >>B[i] >>L[i] >>R[i];


    LL l = 0, r = n * x, mid, ans = -1;

    while(l <= r)
    {
        mid = (l + r) / 2;

        if(gao(mid))
        {
            r = mid - 1;
            ans = mid;
        }
        else
        {
            l = mid + 1;
        }
    }

    cout <<ans <<endl;

}

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 7680
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 16
using namespace std;
long long ans;
int n;
char s[MAXN];
long long cont(int l,int r)
{
	long long re=0;
	for(int i=l;i<=r;i++)
		re=re*10+s[i]-'0';
	return re;
}
int main()
{
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<n;i++)
	{
		for(int j=i;j<n;j++)
		{
			long long a=cont(i,j);
			ans+=a*(1<<(max(0,i-1)+max(0,n-j-2)));
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fr(i, p, n) for(int i = (int )p; i < (int )n; i++)
#define frn(i, p, n) for(int i = (int )p; i <= (int )n; i++)
#define rev(i, n, p) for(int i = (int )n; i >= (int )p; i--)

typedef long long int LL;
typedef pair< int, int> ii;
const int mod = 1e9 + 7;
const int mx = 1e6;
const int i27 = 1 << 27;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	string s;
	cin >> s;
	stack< char> st;
	for(char c: s) {
	    if(c == ')') {
	        if(!st.empty() && st.top() == '(') st.pop();
	        else st.push(c);
	    }
	    else st.push(c);
	}
	if(st.empty()) {
	    cout << s; return 0;
	}
	int l = 0, r = 0;
    while(!st.empty()) {
        if(st.top() == '(') r++;
        else l++;
        st.pop();
    }
    string x = "";
    while(l-- > 0)
        x += '(';
    s = x + s;
    while(r-- > 0)
        s += ')';
    cout << s;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int n;
char S[10];
int Pr(int x){
	printf("%d\n",x);
	fflush(stdout);
	scanf("%s",S);
	if(*S=='V') return 0;
	if(*S=='M') return 1;
	if(*S=='F') return 2;
}
int main(){
	scanf("%d",&n);
	int d1=Pr(0);
	if(!d1) return 0;
	int d2=Pr(n-1);
	if(!d2) return 0;
	int l=1, r=n-2, mid;
	while(l<=r){
		mid=l+r>>1;
		int d=Pr(mid);
		if(!d) return 0;
		if((mid&1)^(d!=d1)) r=mid-1;
		else l=mid+1;
	}
	return 0;
}

Measured memory_bytes: 760
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18


int main(){
    int N;cin >> N;
    vector<vector<int>> a(N,vector<int>(3)),dp(N+10,vector<int>(3));
    rep(i,N){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    rep(i,N){
        rep(j,3){
            rep(k,3){
                if(j == k) continue;
                dp[i+1][k] = max(dp[i+1][k],dp[i][j] + a[i][k]);
            }
        }
    }
    int ans = 0;
    rep(i,3){
        ans = max(ans,dp[N][i]);
    }
    cout << ans << endl;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  double sum = 0;
  for (int i = 0; i < n; ++i) {
    double x;
    cin >> x;
    string s;
    cin >> s;
    if (s == "JPY") {
      sum += x;
    } else {
      sum += 380000.0 * x;
    }
  }

  cout << fixed << setprecision(9) << sum << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <string>
#include <numeric>
#include <functional>
using namespace std;

int main()
{
	int A,B;
	int res = 0;
	cin >> A >> B;
	if (B%A == 0) {
		res = A + B;
	}
	else {
		res = B - A;
	}
	cout << res << endl;
}

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

int n,z[25],h[25],wa,f;

int main(){
	while(1){
		wa=0;
		f=0;
		cin>>n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>z[i]>>h[i];
		}
		for(int i=0;i<n-1;i++){
			for(int j=0;j<n-1;j++){
				if(h[j]>h[j+1]){
					swap(z[j],z[j+1]);
					swap(h[j],h[j+1]);
				}
			}
		}
		for(int i=0;i<n;i++){
			wa+=z[i];
			if(wa>h[i]){
				cout<<"No"<<endl;
				f=1;
				break;
			}
		}
		if(f!=1) cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define F first
#define S second
#define ld long double
int const M=2e5+10,inf=1e9+10,mod=1e9+7;
char a[400][400],b[400][400];
int cnt=0,col[M],ro[400+10][400+10],n;
map<string,int>id;
int check(int ind)
{
	for(int j=1;j<=n;j++)
	{
		string now="";
		for(int i=1;i<=n;i++)
		{
			now+=b[i][j];
		}
		if(!id[now])id[now]=++cnt;
		col[j]=id[now];
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{	
		bool flag=1;
		for(int j=1;j<=n;j++)
		{
			int o=j-ind;
			if(o<=0)o+=n;
			int indd=j-i;
			if(indd<=0)indd+=n;
			if(ro[o][i]!=col[indd])flag=0;
		}
	//	cout<<ind<<" "<<i<<endl;
		ans+=flag;
	}
	return ans;
}
int32_t main()
{
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)cin>>a[i][j];
	}	
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<n;j++)
		{
			string now="";
			for(int k=1;k<=n;k++)
			{
				int ind=k-j;
				if(ind<=0)ind+=n;
				now+=a[i][ind];
			}
			//cout<<i<<" "<<j<<" "<<now<<endl;
			if(!id[now])id[now]=++cnt;
			ro[i][j]=id[now];
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				int ind=j-i;
				if(ind<=0)ind+=n;
				b[j][k]=a[ind][k];
			}
		}
		ans+=check(i);
	}
	cout<<ans;
}

Measured memory_bytes: 102272
N = int(input())
lst = list(map(int, input().split()))

dic1, dic2 = dict(), dict()
#dic1[0] = 0
#dic2[0] = 0
for i, x in enumerate(lst):
    dic = dic1 if  i%2 == 0 else dic2
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1
#print (type(dic1))
dic1 =sorted(dic1.items(), key = lambda x:x[1])[::-1]
dic2 =sorted(dic2.items(), key = lambda x:x[1])[::-1]

#print (type(dic2))
#print (dic1)
#print (dic2)

if dic1[0][0] != dic2[0][0]:
    print (N-dic1[0][1]-dic2[0][1])
elif len(dic1) == 1 and len(dic2) == 1:
    print (N//2)
elif len(dic1) == 1:
    print (N-dic1[0][1]-dic2[1][1])
elif len(dic2) == 1:
    print (N-dic1[1][1]-dic2[0][1])
else:
    print (min(N-dic1[0][1]-dic2[1][1], N-dic1[1][1]-dic2[0][1]))


Measured memory_bytes: 19292
/*
 © 2020-08-15 21:07:12 Franco1010 All Rights Reserved
*/

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;

int main(){ _
  string s; cin >> s;
  lli res = 0, cur = 0;
  fore(i, 0, sz(s)){
    if(s[i] == 'S'){
      res = max(res, cur);
      cur = 0;
    }else cur++;
  }
  cout << max(res, cur) << ENDL;
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int odd_flag = (a % 2) * (b % 2);
    if (odd_flag) {
        cout << "Odd" << endl;
    }
    else {
        cout << "Even" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n,q = map(int,input().split())
graph = [[] for _ in range(n)]
point = [0]*n

for i in range(n-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
    
for _ in range(q):
    a,b = map(int,input().split())
    a = a -1
    point[a]+=b
stack = []
stack.append(0)
visited = [False]*n
while stack:
    x = stack.pop()
    visited[x] = True
    for y in graph[x]:
        if visited[y] == False:
            point[y] += point[x]
            stack.append(y)
print(*point)


Measured memory_bytes: 55728
#include <bits/stdc++.h>
using namespace std;
int n, m, j, i, k, s, c[1003][1003], a[1005], f[1005];
int main(){
	scanf("%d%d", &n, &m);
	for(i=1; i<=m; i++){
		scanf("%d", &a[i]);
		for(j=1; j<=a[i]; j++){
			scanf("%d", &c[i][j]);
		}
	}
	for(i=1; i<=n; i++){
		f[i]=i;
	}
	for(i=1; i<=m; i++){
		for(j=1; j<=a[i]; j++){
			for(s=1; s<=n; s++){
				if(f[s]==c[i][j]){
					f[s]=0;
				}
			}
		}
	}
	for(i=1; i<=n; i++){
		if(f[i]!=0){
			k++;
		}
	}
	printf("%d", k);
	return 0;
}


Measured memory_bytes: 4116
#include<iostream>

using namespace std;

int main()
{
	int n,m,g1,g2;
	cin >> n;
	if (n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n == 12)
	{
		g1 = 1;
	}
	else if (n == 4 || n == 6 || n == 9 || n == 11)
	{
		g1 = 2;
	}
	else
	{
		g1 == 3;
	}
	cin >> n;
	if (n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n == 12)
	{
		g2 = 1;
	}
	else if (n == 4 || n == 6 || n == 9 || n == 11)
	{
		g2 = 2;
	}
	else
	{
		g2 == 3;
	}
	if (g1 == g2)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
    return 0;
}



Measured memory_bytes: 256
L = input()
n = len(L)
mod = 1000000007
dp = [[0,0] for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    dp[i+1][1] += 3*dp[i][1]%mod
    dp[i+1][1] %= mod
    if L[i] == "1":
        dp[i+1][0] += 2*dp[i][0]
        dp[i+1][0] %= mod
        dp[i+1][1] += dp[i][0]
        dp[i+1][1] %= mod
    else:
        dp[i+1][0] += dp[i][0]
        dp[i+1][0] %= mod
ans = (dp[n][0]+dp[n][1])%mod
# for i in range(n+1): print(dp[i])
print(ans)

Measured memory_bytes: 19684
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int,input().split()))
an.reverse()
b = [0] * n
for i,v in enumerate(an):
    if i%2==0:
        b[i//2]=v
    else:
        b[n-i//2-1]=v
print(" ".join(map(str,b)))


Measured memory_bytes: 29764
#include<cstdio>
#include<algorithm>
#include<iostream>

using namespace std;

main(){
  int p=2001,j=2001,temp;
  for(int i=0;i<3;i++){
    scanf("%d",&temp);
    p=min(p,temp);
  }
  
  for(int i=0;i<2;i++){
    scanf("%d",&temp);
    j=min(j,temp);
  }

  printf("%d\n",p+j-50);

}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=55;
int a[N],b[N],c[N],d[N],deg[N],nei[N],mark[N];
ll preT[N],preE[N];
vi t[N],e[N];
int n,ans,cnt;

void T(int u,int fa,ll s){
	preT[u]=s,s|=1ll<<u;
	for(auto v:t[u])
		if(v!=fa)T(v,u,s);
}

void E(int u,int fa,ll s){
	preE[u]=s,s|=1ll<<u;
	for(auto v:e[u])
		if(v!=fa)E(v,u,s);
}

void dfs(int u,int fa){
	cnt++;
	sort(t[u].begin(),t[u].end());
	sort(e[u].begin(),e[u].end());
	for(int i=0,j=0;i<t[u].size()||j<e[u].size();i++,j++){
		int a=(i<t[u].size()?t[u][i]:n+1);
		int b=(j<e[u].size()?e[u][j]:n+1);
		if(a==fa&&b==fa)continue;
		if(a==b)dfs(a,u);
		else if(a<b)T(a,u,0),j--;
		else E(b,u,0),i--;
	}
}

void doit(int x,int y){		// first step: x -> y
	rep(i,1,n){
		t[i].clear(),e[i].clear();
		mark[i]=preT[i]=preE[i]=0;
	}
	t[x].pb(y),t[y].pb(x);
	rep(i,1,n-1){
		if(a[i]!=x&&b[i]!=x)
			t[a[i]].pb(b[i]),t[b[i]].pb(a[i]);
		e[c[i]].pb(d[i]),e[d[i]].pb(c[i]);
	}
	cnt=-1,dfs(x,0);
	rep(i,1,n)rep(j,1,n)
		if(preT[i]>>j&1)preE[j]|=1ll<<i;
	rep(i,1,n)rep(j,1,n)
		if(preE[j]>>i&1)preE[j]|=preE[i];
	rep(i,1,n)if(preE[i]>>i&1)return;
	ans=min(ans,n-cnt);
}

void rmain(){
	map<pii,int> owo; int same=1;
	read(n),fill(deg+1,deg+n+1,0),ans=n+1;
	rep(i,1,n-1){
		read(a[i]),read(b[i]);
		if(a[i]>b[i])swap(a[i],b[i]);
		owo[mp(a[i],b[i])]=1;
		deg[a[i]]++,deg[b[i]]++;
		nei[a[i]]=b[i],nei[b[i]]=a[i];
	}
	rep(i,1,n-1){
		read(c[i]),read(d[i]);
		if(c[i]>d[i])swap(c[i],d[i]);
		if(!owo[mp(c[i],d[i])])same=0;
	}
	if(same){puts("0");return;}
	rep(i,1,n)if(deg[i]==1)
		rep(j,1,n)if(i!=j&&i!=nei[i])
			doit(i,j);
	printf("%d\n",ans<=n?ans:-1);
}

int main(){
	int T; read(T);
	while(T--) rmain();	
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
	int A, B;
	cin >> A >> B;

	int answer = 0;
	for (int i = A; i <= B; i++) {
		std::string cur_s(std::to_string(i));
		std::string reverse_s;
		for (int j = cur_s.size() - 1; j >= 0; j--) {
			reverse_s += cur_s[j];
		}
		if (cur_s == reverse_s) {
			answer++;
		}
	}

	cout << answer << endl;
	return 0;
}


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

using namespace std;

long long x;

int main(void)
{
	scanf("%lld", &x);
	
	for(long long i = 0 ; i <= 4500 ; i++)
	{
		for(long long j = 0 ; j <= 4500 ; j++)
		{
			if(i * i * i * i * i - j * j * j * j * j == x)
			{
				printf("%lld %lld", i, j);
				return 0;
			}
			
			if(i * i * i * i * i + j * j * j * j * j == x)
			{
				printf("%lld %lld", i, -j);
				return 0;
			}
			
			if(-i * i * i * i * i + j * j * j * j * j == x)
			{
				printf("%lld %lld", -i, -j);
				return 0;
			}
			
			if(-i * i * i * i * i - j * j * j * j * j == x)
			{
				printf("%lld %lld", -i, j);
				return 0;
			}
		}
	}
	
	return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[2005];

int main() {
    ll N, X, Y;
    cin >> N >> X >> Y;
    REP(i, N) {
        cin >> A[i];
    }
    if (N == 1)
        cout << abs(A[0] - Y) << endl;
    else
        cout << std::max(abs(A[N - 1] - A[N - 2]),
                         abs(A[N - 1] - Y)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int n, i;
	cin >> n;
	int arr[n];
	fo(i, 0, n)
	cin >> arr[i];
	int pref[n], suf[n];
	pref[0] = arr[0];
	fo(i, 1, n){
		pref[i] = max(pref[i - 1], arr[i]);
	}
	suf[n - 1] = arr[n - 1];
	for(i = n - 2; i >= 0; i--){
		suf[i] = max(suf[i + 1], arr[i]);
	}
	int ans[n];
	fo(i, 0, n){
		ans[i] = max((i > 0 ? pref[i - 1] : 0), (i < n - 1 ? suf[i + 1] : 0));
	}
	for(auto x : ans)
	cout << x << ' ';
}

Measured memory_bytes: 4864
N=int(input())
W=list(map(int,input().split()))
min=-1
for T in range(N):
	S1=0
	for i in range(T):
		S1=S1+W[i]
	S2=sum(W)-S1
	temp=abs(S2-S1)
	if(min==-1):
		min=temp
	elif(temp<min):
		min=temp
print(min)


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

int main(){
  int d;
  cin >> d;
  
  if (d == 25)
    cout << "Christmas" << endl;
  else if (d == 24)
    cout << "Christmas Eve" << endl;
  else if (d == 23)
    cout << "Christmas Eve Eve" << endl;
  else
    cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 3532
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

int main(){    
  long long N,K,sum=0;
  cin >> N >> K;
  long long H[N];
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  sort(H,H+N);

  for(int i=0;i<N-K;i++){
    sum += H[i];
  }
  
  cout << sum << endl;
  
}


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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mxn = 55;
int n, lim, d;
ll sm[mxn]; int sz[mxn];
vector <int> g[mxn];

void dfs(int u) {
	sz[u] = 1;
	rep(i, g[u].size()) {
		int v = g[u][i];
		dfs(v);
		sm[u] += sm[v];
		sz[u] += sz[v];
	}
}

int id[mxn];

bool comp(int a, int b) {
	return sz[a] * sm[b] == sz[b] * sm[a] ? a < b : sz[a] * sm[b] > sz[b] * sm[a];
}

int x[mxn];

int solve() {
	int ans = 0;
	rep(i, n) id[i] = i;
	sort(id, id + n, comp);
	rep(i, n) {
		int u = id[i];
		int nw = lim / sm[u];
		if (u != 0) nw = min(nw, d);
		lim -= nw * sm[u];
		ans += nw * sz[u];
		x[u] = nw;
	}
	return ans;
}

ll dp[mxn][2 * mxn * mxn * mxn];

int main() {
//	freopen("c.in", "r", stdin);
//	freopen("c.out", "w", stdout);
	scanf("%d %d %d", &n, &lim, &d);
	rep(i, n) {
		scanf("%lld", &sm[i]);
		if (i) {
			int fa; scanf("%d", &fa); -- fa;
			g[fa].pb(i);
		}
	}
	dfs(0);
	int ans = solve();
	memset(dp, 0x3f, sizeof(dp));
	dp[0][mxn * mxn * mxn] = 0;
	rep(i, n) {
		int u = id[n - 1 - i];
		rep(r, 2 * mxn * mxn * mxn) {
			for (int dlt = -min(x[u], mxn); dlt <= (u ? min(d - x[u], mxn) : mxn); ++ dlt) {
				if (r + dlt * sz[u] >= 0 && r + dlt * sz[u] < 2 * mxn * mxn * mxn) {
					dp[i + 1][r + dlt * sz[u]] = min(1LL * dp[i + 1][r + dlt * sz[u]], dp[i][r] + dlt * sm[u]);
				}
			}
		}
	}
	int Ans = ans;
	rep(r, mxn * mxn * mxn) if (dp[n][mxn * mxn * mxn + r] <= lim) Ans = ans + r;
	printf("%d\n", Ans);
	return 0;
}


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

int main()
{
    string S;
    bool t=false;
    cin >> S;
    REP(i,2) {
        if(!(S[i]==S[i+1])) {
            t=true;
            break;
        }
    } 
    if(t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
c = 0
lste = []
lsto = []

for i in range(len(s)):
  if i%2 == 0:
    lsto.append(s[i])
  if i%2 != 0:
    lste.append(s[i])
      
if "L" not in lsto and "R" not in lste:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;

void merge(vector<pair<string, int>> &a, int left, int mid, int right)
{
	int n0 = mid - left;
	int n1 = right - mid;

	vector<pair<string, int>> l(n0 + 1);
	vector<pair<string, int>> r(n1 + 1);

	for (int i = 0; i < l.size() - 1; i++)
	{
		l.at(i) = a.at(left + i);
	}

	for (int i = 0; i < r.size() - 1; i++)
	{
		r.at(i) = a.at(mid + i);
	}

	l.at(n0).second = INF;
	r.at(n1).second = INF;

	int x = 0;
	int y = 0;

	for (int i = left; i < right; i++)
	{
		if (l.at(x).second <= r.at(y).second)
		{
			a.at(i) = l.at(x);
			x++;
		}
		else
		{
			a.at(i) = r.at(y);
			y++;
		}
	}
}

void merge_sort(vector<pair<string, int>> &a, int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		merge_sort(a, left, mid);
		merge_sort(a, mid, right);
		merge(a, left, mid, right);
	}
}

int partition(vector<pair<string, int>> &a, int p, int r)
{
	pair<string, int> x = a.at(r);
	int id = p - 1;

	for (int i = p; i < r; i++)
	{
		if (a.at(i).second <= x.second)
		{
			id++;
			swap(a.at(i), a.at(id));
		}
	}
	swap(a.at(id + 1), a.at(r));

	return id + 1;
}

void quick_sort(vector<pair<string, int>> &a, int p, int r)
{
	if (p < r)
	{
		int q = partition(a, p, r);
		quick_sort(a, p, q - 1);
		quick_sort(a, q + 1, r);
	}
}

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

	vector<pair<string, int>> p(n);

	for (int i = 0; i < n; i++)
	{
		string s;
		int id;
		cin >> s >> id;

		p.at(i) = (make_pair(s, id));
	}

	vector<pair<string, int>> a = p;
	vector<pair<string, int>> b = p;

	quick_sort(a, 0, n - 1);
	merge_sort(b, 0, n);

	bool stable = true;
	for (int i = 0; i < n; i++)
	{
		if (a.at(i) != b.at(i))
		{
			stable = false;
			break;
		}
	}

	cout << (stable ? "Stable" : "Not stable") << endl;

	for (int i = 0; i < n; i++)
	{
		cout << a.at(i).first << " " << a.at(i).second << endl;
	}
}


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

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  priority_queue<int> q;
  rep(i, n){
    cin >> v[i];
    q.push(v[i]);
  }
  rep(i, m){
    int tmp = q.top();
    q.pop();
    tmp /= 2;
    q.push(tmp);
  }
  ll sum = 0;
  while(!q.empty()){
    sum += q.top();
    q.pop();
  }
  cout << sum << endl;
}


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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	char ch;
	cin >> ch;
	if(ch>='A' && ch<='Z')
		cout << 'A' << "\n";
	else
		cout << 'a' << "\n";
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  int n, m; cin >> n >> m;
  vector<int> vec(n);

  rep(i, m) {
    int l, r; cin >> l >> r;
    l--, r--;
    vec[l] += 1, vec[r+1] -= 1;
  }
  vector<int> cumul(n);
  cumul[0] = vec[0];
  rep(i, n-1) {
    cumul[i+1] = cumul[i] + vec[i+1];
  }

  int ans = 0;
  rep(i, n) {
    if(cumul[i] == m) ans++;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <utility>
#include <stack>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int,int> pii;
vector<ll>a[3];
vector<ll>sum[3];
int main(){
    int n;
    ll W;
    cin >> n >> W;
    vector<int>w(n);
    vector<ll>v(n);
    rep(i,n){
        cin >> w[i] >> v[i];
        a[w[i]-w[0]].push_back(v[i]);
    }
    rep(i,4)sort(a[i].rbegin(),a[i].rend());
    rep(i,4){
        sum[i].resize(a[i].size()+1,0);
        rep(j,a[i].size()){
            sum[i][j+1] = sum[i][j] + a[i][j];
        }
    }
    ll ans = 0;
    rep(i,a[0].size()+1){
        rep(j,a[1].size()+1){
            rep(k,a[2].size()+1){
                rep(l,a[3].size()+1){
                    if((ll)w[0]*(i+j+k+l)+j+k*2+l*3<=W){
                        // cerr << i << " " << j << " " << k << " " << l << endl;
                        ans = max(ans, sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

ll n;
void dfs(st dokei, char max){
  if(dokei.size() == n) {
    cout << dokei << endl;
    return;
  }
  for(char i = 'a'; i < max + 2; i++){
    st next = dokei;
    next.push_back(i);
    ll nmax = (max > i ? max : i);
    dfs(next, nmax);
  }
}

int main(){
  cin >> n;
  dfs("a", 'a');
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,k,ans=0;
  cin>>n>>k;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  rep(i,n){
    ans+=min(k-v[i],v[i]);
  }
  cout<<ans*2<<endl;
}
///////////////////////////

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner n=new Scanner(System.in);
		
		int w = n.nextInt();
		int h = n.nextInt();
		int x = n.nextInt();
		int y = n.nextInt();
		int r = n.nextInt();
		if ((x + r) > w || (y + r) > h || (x - r) < 0 || (y - r) < 0){
			System.out.println("No");
		}else{
		System.out.println("Yes");
		}}}

Measured memory_bytes: 17300
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var r = Reads();
            long R = r[0], G = r[1], B = r[2], N = r[3];
            long ans = 0;
            for (int i = 0; i <=3000; i++)
            {
                for (int j = 0; j <=3000; j++)
                {
                    if (N - (R * i + G * j) >= 0 && (N - (R * i + G * j)) % B == 0)
                        ans++;
                }
            }
            WriteLine(ans);
            

            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 18908
K = int(input())

a = [0 for i in range(K+1)]
a[1] = 7 % K
for i in range(2, K+1):
    a[i] = (10*a[i-1]+7) % K

flag = 1
for i in range(1, K+1):
    if a[i] == 0:
        print(i)
        flag = 0
        break
if flag:
    print(-1)

Measured memory_bytes: 48644
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-9
#define M_PI 3.141592653589793
#define bsize 300

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 1100031;

string st;
bool valid(char a,char b){
	int id=a-'0';
	id=id*10+b-'0';
	return (id>=1&&id<=12);
}

int main(){
//    freopen("apache.in","r",stdin);
//    freopen("apache.out","w",stdout);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    //cin.tie(0);

    cin>>st;
    int A=valid(st[0],st[1]);
    int B=valid(st[2],st[3]);

    if (A&&B)
    	cout<<"AMBIGUOUS"<<endl;
    else if (A)
    	cout<<"MMYY"<<endl;
    else if (B)
    	cout<<"YYMM"<<endl;
    else
    	cout<<"NA"<<endl;

//    cin.get(); cin.get();
    return 0;
}


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

using namespace std;

int main(){
    int N;
    cin >> N;
    
    int p[N];
    for(int i = 0; i < N; ++i){
        cin >> p[i];
    }
    int cnt = 0;
    
    for(int i = 0; i < N; ++i){
        if(p[i] == i+1){
            cnt++;
            i++;
        }
    }
    
    cout << cnt<< endl;
    
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF 1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second
#define setprecision(d) cout << fixed << setprecision(d);

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

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





signed main(){
	ll a,b;
	cin >> a >> b;
	cout << lcm(a,b) << endl;
    return 0;
}

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

int main(){
	long long A;
	cin>>A;
	double B;
	cin>>B;
	long long C=B*100+0.5;
	A*=C;
	A/=100;

	cout<<A<<endl;


    return 0;
}

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

using namespace std;

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

uint64_t gcd(uint64_t a, uint64_t b){return a ? gcd(b % a, a) : b;}

int main(){
  int n, m;
  cin >> n >> m;
  vector<uint64_t> a(n);
  REP(i, n) cin >> a[i];
  int c = 0;
  REP(i, n){
    int cc = 0;
    while(a[i] % 2 == 0){
      a[i] >>= 1;
      ++cc;
    }
    if(c != 0 && c != cc){
      cout << 0 << endl;
      return 0;
    }
    c = cc;
  }
  uint64_t l = 1 << (c - 1);
  REP(i, n){
    uint64_t g = gcd(l, a[i]);
    l *= a[i] / g;
    if(l > m){
      cout << 0 << endl;
      return 0;
    }
  }
  cout << (m / l + 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 1024
from math import sqrt

n = int(input())

points = [list(map(int, input().split())) for _ in range(n)]


sum_r = 0
for i in range(n):
    for j in range(i+1, n):
        a = points[i]
        b = points[j]
        sum_r += sqrt(pow(a[0]-b[0], 2) + pow(a[1] - b[1], 2))

print(sum_r*2/n)


Measured memory_bytes: 3060
#!/usr/bin/python3.6
import sys
input = sys.stdin.readline
INF = 10**9

a = [int(item) for item in list(input().rstrip())]
n = len(a)
# DP[i-th item][0:pay just / 1:pay over]
dp = [[INF] * 2 for _ in range(n + 1)] 
dp[0][0] = 0

for i, item in enumerate(a):
    dp[i+1][0] = min(dp[i+1][0], dp[i][0] + item, dp[i][1] + item)
    dp[i+1][1] = min(dp[i+1][1], dp[i][0] + 10 - item + 1, dp[i][1] + 10 - item - 1)

print(min(dp[n]))

Measured memory_bytes: 152888
#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(){
	int n;
	cin >> n;
	vector<int> t(n+1);
	vector<int> x(n+1);
	vector<int> y(n+1);
	rep(i,n) cin >> t[i+1] >> x[i+1] >> y[i+1];
	int prex = 0;
	int prey = 0;
	bool ok = false;
	rep(i,n+1){
		int dist = abs(x[i+1] -x[i]) + abs(y[i+1] - y[i]);
		int deltat = abs(t[i+1] - t[i]);
		if(dist > deltat){
			cout << "No" << endl;
			return 0;
		} 
		else{
			if(dist%2 == 1 && deltat%2 == 1) ok = true;
			// if(dist%2 == 0 && deltat%2 == 0) ok = true;
		}
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 4436
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

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

	vector<int> result(S.length());
	for (auto left = 0; left < S.length();)
	{
		auto right = left;
		while (S[right] == 'R')
		{
			++right;
		}

		auto numR = right - left;
		auto indexR = right - 1;
		auto indexL = right;

		left = right;
		while (S[right] == 'L' && right < S.length())
		{
			++right;
		}
		auto numL = right - left;

		auto add = min(numR, numL);
		auto diff = abs(numR - numL);
		add += diff / 2;
		result[indexR] = add;
		result[indexL] = add;
		if (diff % 2 != 0)
		{
			if (numR > numL)
			{
				if (numR % 2 == 0)
				{
					++result[indexL];
				}
				else
				{
					++result[indexR];
				}
			}
			else
			{
				if (numL % 2 == 0)
				{
					++result[indexR];
				}
				else
				{
					++result[indexL];
				}
			}
		}

		left = right;
	}

	for (auto i = 0; i < result.size(); ++i)
	{
		if (i > 0)
		{
			cout << " ";
		}
		cout << result[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>

int main(){
	char s1[100];  
	char s2[100];  
	char s3[100];   
	int len;        
	int flag=0;   
	char tmp;     
	int i;
	char *p;      
	
	scanf("%s",s1);
	strcpy(s3,s1);
	len=strlen(s3);
	scanf("%s",s2);
	
	while(1){       //  ????????????????????°??¶????????¢
		tmp=s3[0];
		for(i=1;i<len;i++){
			s3[i-1]=s3[i];
		}
		s3[len-1]=tmp;
		if((p=strstr(s3,s2))!=NULL){   
			flag=1;                     
			break;                     
		}
		else if(strcmp(s1,s3)==0){
			break;
		}
	}
	
	if(flag==1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 540