akhauriyash/Code-Regression huggingface dataset:
n, l = map(int, input().split())
sum,flag,mini = 0,0,10000
for i in range(1,n+1):
    hoge = l+i-1
    sum += hoge
    if abs(mini) >= abs(hoge):
        mini = hoge
    if (hoge == 0):
        flag = 1
if flag == 1:
    print(sum)
else:
    print(sum-mini)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int xx;
//bool is_prime(ll x){
//if(x<=1) return 0;
//for(int i=2;i*i<=x;i++){
//    if(x%i==0)return 0;
//}
//return 1;
//}
ll mod=1e7;
int main(){
ll x;
cin>>x;
vector<ll> v1(x+1,0);
for(ll i=1;i<=x;i++){
 for(ll j=0;j<=x;j+=i)
        v1[j]++;
}
ll total=0;
for(ll i=1;i<=x;i++){
total+=(i*(ll)v1[i]);
}
cout<<total;
}



Measured memory_bytes: 81348
# include <bits/stdc++.h>
# define ll long long int
# define pb push_back
# define pf push_front
# define mpi make_pair
# define pi pair<ll,ll>
# define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
# define mod 1000000007
# define endl "\n"
using namespace std;
int main()
{
  fast
  ll n,m,ans1=0,ans2=0;
  cin>>n>>m;
  vector <pi> v;
  for(ll i=0;i<n;i++)
  {
    v.pb(mpi(0,0));
  }
  while(m--)
  {
    ll x;
    string s;
    cin>>x>>s;
    if((v[x-1].second)==0)
    {
      if(s[0]=='W')
      {
        (v[x-1].first)++;
      }
      else
      {
        v[x-1].second=1;
      }
    }
  }
  for(ll i=0;i<v.size();i++)
  {
    if(v[i].second==1)
    {
    ans1+=v[i].first;
    }
    ans2+=v[i].second;
  }
  cout<<ans2<<" "<<ans1<<endl;
  return 0;
}


Measured memory_bytes: 2420
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	// A := complex(float64(a), 2)
	// B := complex(float64(b), 2)
	// C := complex(float64(c), 2)

	// // A := math.Sqrt(float64(a))
	// // B := math.Sqrt(float64(b))
	// // C := math.Sqrt(float64(c))
	// res := "No"
	// if real(A)+real(B) < real(C) {

	// 	res = "Yes"
	// }
	// fmt.Println(res)

	d := c - a - b
	res := "No"
	if d > 0 && d*d > 4*a*b {
		res = "Yes"
	}
	fmt.Println(res)
}


Measured memory_bytes: 512
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//222
	string s;
	cin>>s;
	int cnt=0;
	for(char c:s)if(c=='o')cnt++;
	cout<<700+cnt*100;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

typedef long long int ll;

int main()
{
	ios::sync_with_stdio(0);
	ll n,m,i,j;
	cin >> n >> m;
	char a[n][m];
	ll mo=1e9+7;
	ll dp[n][m];
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			cin >> a[i][j];
			dp[i][j]=0;
		}
	}	
	for(i=0;i<m;i++)
	{
		if(a[0][i]=='.')
			dp[0][i]=1;
		else
			break;
	}
	for(i=0;i<n;i++)
	{
		if(a[i][0]=='.')
			dp[i][0]=1;
		else
			break;
	}
	for(i=1;i<n;i++)
	{
		for(j=1;j<m;j++)
		{
			if(a[i][j]=='#')
				dp[i][j]=0;
			else
			{
				dp[i][j]=(dp[i-1][j]%mo+dp[i][j-1]%mo)%mo;
			}
		}
	}
	cout << dp[n-1][m-1] << "\n";
	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
using namespace std;
    
int main() {
  int N;
  cin >> N;

  vector<double> L;
  double sum = 0;
  for (int i=0; i < N; i++) {
    int n;
    cin >> n;
    L.push_back(n);
    sum += n;
  }

  for (int i=0; i < N; i++) {
    if (L[i] >= sum - L[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
def factorization(n):
    s = set()
    temp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            s.add(i)

    if temp != 1:
        s.add(temp)

    if len(s) == 0:
        s.add(n)

    return s


A, B = map(int, input().split())
mini = min(A, B)
maxi = max(A, B)

ss = factorization(mini)

res = 1
for i in ss:
    if maxi % i == 0:
        res += 1

if mini == 1:
    res = 1

print(res)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli mod=1000000007;
#define Jaldi_jaldi_kar_subha_panvel_ke_liye_nikalna_hai ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    Jaldi_jaldi_kar_subha_panvel_ke_liye_nikalna_hai
    lli n,r;
    cin>>n>>r;

    lli ans=0;
    while(n){
    	ans++;
    	n/=r;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> deg(n);
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    deg[x]++;
    deg[y]++;
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    // trace(i, deg[i]);
    if (deg[i] % 2) ++ret;
  }
  puts(ret > 1 ? "NO" : "YES");
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
const int N=100+10;
int n,m,w[N],c[N],f[N*1000],sum;
int mi(int a,int b){return a<b?a:b;}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&w[i],&c[i]);
		sum+=c[i]; 
	}
	memset(f,0x3f,sizeof(f));
	f[0]=0;
	for(int i=1;i<=n;i++)
		for(int j=sum;j>=c[i];j--)
			f[j]=mi(f[j-c[i]]+w[i],f[j]);
	for(int i=sum;i>=0;i--)
		if(f[i]<=m)
		{
			printf("%d",i);
			return 0;
		}
	return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  long long dp[2][n][16];
  for (int i = 0; i < 16; i++) {
    dp[0][n - 1][i] = i;
    dp[1][n - 1][i] = i;
  }

  for (int i = 0; i < 2; i++) {
    for (int j = n - 2; j >= 0; j--) {
      int j1 = 0;
      int j2 = 0;
      long long c1 = a[j];
      long long c2 = a[j + 1];
      while (c1 <= c2 && j1 < 16) {
        dp[i][j][j1] = dp[i][j + 1][0] + j1;
        c1 *= 4;
        j1++;
      }
      while (j2 < 16 && c2 < c1) {
        c2 *= 4;
        j2++;
      }
      while (j1 < 16) {
        if (j2 > 15) {
          dp[i][j][j1] = dp[i][j + 1][15] + (j2 - 15) * (n - 1 - j) + j1;
        }
        else {
          dp[i][j][j1] = dp[i][j + 1][j2] + j1;
        }
        j1++;
        j2++;
      }
    }
    reverse(a.begin(), a.end());
  }

  long long ans = 2 * dp[0][0][0];
  for (int i = 1; i < n; i++) {
    long long steps = dp[0][i][0] * 2 + dp[1][n - i][0] * 2 + i;
    ans = min(ans, steps);
  }
  cout << ans;
}


Measured memory_bytes: 51072
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        String[] ns1 = n.split("");
        List<String> s = Arrays.asList(ns1);
        List<String> kotae = new ArrayList<>();
        int x = 0;
        int y = 0;
        int z = 0;
        for(int i = 0; i < s.size(); i++){
            if (s.get(i).equals("1")){
                kotae.add("9");
            }
            else if(s.get(i).equals("9")){
                kotae.add("1");
            }
        }
        if(kotae.size() == 1){
            z = Integer.parseInt(kotae.get(0)) * 1;
        }
        else if(kotae.size() == 2){
            y = Integer.parseInt(kotae.get(0)) * 10;
            z = Integer.parseInt(kotae.get(1)) * 1;
        }
        else if(kotae.size() == 3){
            x = Integer.parseInt(kotae.get(0)) * 100;
            y = Integer.parseInt(kotae.get(1)) * 10;
            z = Integer.parseInt(kotae.get(2)) * 1;
        }

        System.out.println(x + y + z);
    }
}


Measured memory_bytes: 22100
#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>;

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

  vector<int> a(n);
  for (auto &e : a) { cin >> e; }
  sort(a.begin(), a.end());

  int m = a[n - 1];
  int k = a[0];
  int d = abs(m - 2 * a[0]);
  for (int i = 1; i < n - 1; ++i) {
    int _d = abs(m - 2 * a[i]);
    if (d > _d) {
      d = _d;
      k = a[i];
    } else {
      break;
    }
  }

  cout << m << " " << k << endl;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

const ll mod=1e9+7;
ll mu(ll a,ll b){
  return (ll)a*b%mod;
}
ll ad(ll a,ll b){
  if((a+=b)>=mod)a-=mod;
  return a;
}
ll pw(ll a,ll b,ll c=1LL){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
ll dv(ll a,ll b){
  return mu(a,pw(b,mod-2));
}
int main(){

  int n;
  cin >>n;
  int dp[4][4][4][n]; //a or not /a g not// agct
  
  rep(m3,4){
    rep(m2,4){
      rep(m1,4){
	dp[m3][m2][m1][0]=0;
      }
    }
  }
  rep(m1,4){
    dp[3][3][m1][0]=1;
  }
  
  rep1(i,n-1){
    rep(m3,4){
      rep(m2,4){
	dp[m3][m2][0][i]=0;
	dp[m3][m2][1][i]=0;
	dp[m3][m2][2][i]=0;
	dp[m3][m2][3][i]=0;
	rep(m1,4){
	  //a
	  dp[m3][m2][0][i] += dp[m1][m3][m2][i-1];
	  dp[m3][m2][0][i] %= mod;
	  //g
	  if(m3!=0 || m2!=2) dp[m3][m2][1][i] += dp[m1][m3][m2][i-1];
	  dp[m3][m2][1][i]%=mod;
	  //c
	  if((m3!=0 || m2!=1) &&(m3!=1 || m2!=0 )  &&(m1!=0 || m2!=1 ) &&(m1!=0 || m3!=1 ) ){
	    dp[m3][m2][2][i] += dp[m1][m3][m2][i-1];
	    dp[m3][m2][2][i]%=mod;
	  }
	  // t
	  dp[m3][m2][3][i] += dp[m1][m3][m2][i-1];
	  dp[m3][m2][3][i]%=mod;
	}
      }
    }
    //    cout << dp[0][0][0][i] << endl;
  }
  ll ans=0;
  rep(m1,4)rep(m2,4)rep(m3,4){
    ans = ad(ans,dp[m1][m2][m3][n-1]);
    //    cout << ans << endl;
  }
  cout << ans << endl;

  
  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
int main() {
    string s;
    int K;
    cin >> s;
    set<char>st;
    for (auto i : s)st.insert(i);
    cin >> K;
    if (st.size() == 1) {
        cout << (K*s.size()) / 2 << endl;
        return 0;
    }
    long long int a = 0;
    auto t = s;
    for (int i = 1; i < t.size(); i++) {
        if (t[i] == t[i - 1]) {
            a++;
            t[i] = '#';
        }
    }
    s += s;
    long long int b = 0;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] == s[i - 1]) {
            b++;
            s[i] = '#';
        }
    }
    b -= a;
    cout << (K-1) * b + a << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int max(int a, int b);
int lcs( char *, char *, int, int);
 
int lcs( char *X, char *Y, int m, int n ){
   int L[m+1][n+1];
   int i, j;
 
   for (i=0; i<=m; i++)
   {
     for (j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;
 
       else if (X[i-1] == Y[j-1])
         L[i][j] = L[i-1][j-1] + 1;
 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }
 
   return L[m][n];
}
 
int max(int a, int b){
    return (a > b)? a : b;
}
 
main(){
  char X[1001], Y[1001];
  int m, n, t, k, i;
 
  scanf("%d", &k);
  for(i = 0;i < k;i++){
    scanf("%s %s", X, Y);
    m = strlen(X);
    n = strlen(Y);
    t = lcs( X, Y, m, n );
    printf("%d\n", t);
  }
 
  return 0;
}

Measured memory_bytes: 4512
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_5-A: Exhaustive Search

#include <cstdio>
#include <numeric>

static bool solve(const int m, const int as[], const unsigned int n)
{
  if (m == 0) {
    return true;
  } else if (n == 0 || m < 0 || m > std::accumulate(as, as+n, 0)) {
    return false;
  } else {
    return solve(m-as[0], as+1, n-1) || solve(m, as+1, n-1);
  }
}

int main()
{
  unsigned int n;
  std::scanf("%d", &n);
  int as[n];
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%d", &as[i]);
  }

  unsigned int q;
  std::scanf("%d", &q);
  for (auto i = 0u; i < q; ++i) {
    int m;
    std::scanf("%d", &m);
    auto is_solved = solve(m, as, n);
    std::printf("%s\n", is_solved ? "yes" : "no");
  }
}

// eof

Measured memory_bytes: 2608
def find_ds(h, w):
    ans = h * w
    if h >= 3:
        if h % 3 == 0:
            return 0
        else:
            ans = w
    for i in range(1, w):
        x0 = h * i
        x1 = h // 2 * (w - i)
        x2 = h * w - x0 - x1
        ds = max(x0, x1, x2) - min(x0, x1, x2)
        ans = min(ans, ds)
    return ans

h, w = map(int, input().split())
print(min(find_ds(h, w), find_ds(w, h)))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define cs const
using namespace std;
typedef long long ll;
cs ll INF = 4e18;
int T; ll n, A, B, C, D;
map<ll, ll> dp;
ll work(ll x){
	if(!x) return 0;
	if(x == 1) return D;
	if(dp.count(x)) return dp[x];
	ll res = INF;
	if(res / D > x) res = x * D;
	if(x & 1){
		res = min(res, work((x-1)>>1) + A + D),
		res = min(res, work((x+1)>>1) + A + D);
	} else res = min(res, work(x>>1) + A);
	ll l = x - x % 3, r = x - x % 3 + 3;
	if(l != x){
		res = min(res, work(l/3) + B + (x - l) * D);
		res = min(res, work(r/3) + B + (r - x) * D);
	} else res = min(res, work(x/3) + B);
	l = x - x % 5; r = x - x % 5 + 5;
	if(l != x){
		res = min(res, work(l/5) + C + (x - l) * D);
		res = min(res, work(r/5) + C + (r - x) * D);
	} else res = min(res, work(x/5) + C);
	return dp[x] = res;
}
void Main(){
	scanf("%lld%lld%lld%lld%lld",&n,&A,&B,&C,&D);
	dp.clear(); cout<<work(n)<<'\n';
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d",&T);
	while(T--) Main();
	return 0;
} 

Measured memory_bytes: 4444
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 1000000005
#define NIL -1
int gcd(ll s, ll t){
    if(s < t){
        ll tmp = s;
        s = t;
        t = tmp;
    }
    ll r = s%t;
    while(r != 0){
        s = t;
        t = r;
        r = s%t;
    }
    return t;
}
int main(){
    ll n, x; cin >> n >> x;
    ll a[n];
    cin >> a[0];
    ll v = abs(a[0] - x);
    for(ll i = 1; i < n; i++){
        cin >> a[i];
        ll b = abs(a[i] - x);
        v = gcd(b, v);
    }
    cout << v << endl;
}

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

int X, A;

inline int Rd() {
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}
inline void ChkMax(int &aa, int bb) {
	if(aa < bb) aa = bb;
	return;
}
inline void ChkMin(int &aa, int bb) {
	if(aa > bb) aa = bb;
	return;
}

int main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	cin >> X >> A;
	if(X < A)
		puts("0");
	else
		puts("10");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n,i;
  int t=0;
  scanf("%d",&n);
  for(i=1;i<4;i++)
  {
      if((n%10)==7)
       {t=1;
        break;}
        n=n/10;
  }
  (t==1)?printf("Yes"):printf("No");
return 0;}


Measured memory_bytes: 1736
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

class UnionFind{
public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;

    //作る時はParentの値を全て-1にする
    //こうするとずべてバラバラになる
    UnionFind(int N){
      Parent = vector<int>(N,-1);
    }

    //Aがどのグループに属しているのか調べる
    int root(int A){
      if(Parent[A]<0) return A;
      return Parent[A] = root(Parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A){
      return -Parent[root(A)];//親を取ってきたい
    }

    //AとBをくっつける
    bool connect(int A,int B){
      //AとBを直すつつなぐのではなく、root(A)にroot(B)をくっつける)
      A = root(A);
      B = root(B);
      if(A==B){
        //すでにくっついているからくっつけない
        return false;
      }
      //大きい方(A)に小さい方(B)をくっつけたい
      //大小が逆だったらひっくり返しちゃう
      if(size(A)<size(B)) swap(A,B);

      //Aのサイズを更新する
      Parent[A] += Parent[B];
      //Bの親をAに変更する
      Parent[B] = A;

      return true;
    }
  };

int main(){
  ll N,M;cin>>N>>M;
  ll i,j;
  vector<pair<ll,ll> > a(M);
  rep(i,M) cin>>a[i].first>>a[i].second;
  rep(i,M){
    a[i].first--;
    a[i].second--;
  }

  UnionFind Uni(N);

  vector<ll> ans(M);
  ans[M-1] = N*(N-1)/2;

  for(i=M-1;i>=1;i--){
    ans[i-1] = ans[i];
    if(Uni.root(a[i].first) != Uni.root(a[i].second)){
      ans[i-1] -= Uni.size(a[i].first) * Uni.size(a[i].second);
      Uni.connect(a[i].first,a[i].second);
    }
    else continue;
  }

  rep(i,M){
    cout<<ans[i]<<endl;
  }

}


Measured memory_bytes: 4096
import java.lang.Integer;
import java.lang.Math;
import java.lang.String;
import java.lang.System;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            int input[] = new int[5];
            for(int i = 0; i < 5; i++) {
                input[i] = sc.nextInt();
            }

            // 並び替え
            Arrays.sort(input);

            // 配列 => String
            String outStr = "";
            for(int i = input.length; i > 0; i--) {
                outStr += input[i - 1];
                if(i != 1) {
                    outStr += " ";
                }
            }
            System.out.println(outStr);
        }
    }
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int dp[100010];

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

    return 0;
}



Measured memory_bytes: 256
#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(void){
    ll D, T, S;
    cin >> D >> T >> S;

    if(T*S >= D) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b){ if (a<b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if (b<a){ a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int N, M;
  cin >> N >> M;
  v(v(bool)) s(M, v(bool)(N, false));
  rep(mi, 0, M) {
    int k; cin >> k;
    rep(ki, 0, k) {
      int _s; cin >> _s;
      s[mi][_s-1] = true;
    }
  }
  vi p(M);
  rep(i, 0, M) cin >> p[i];

  int ans = 0;
  for (int bit = 0; bit < (1<<N); ++bit) {
    v(bool) st(N, false);
    rep(i, 0, N) st[i] = bit & 1<<i;

    bool f = true;
    rep(mi, 0, M) {
      int t = 0;
      rep(i, 0, N) if (st[i] && s[mi][i]) ++t;
      if (t % 2 != p[mi]) {
        f = false;
        break;
      }
    }
    if (f) ++ans;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
//_____
#define pb emplace_back
#define fi first
#define se second
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__)
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
#define let const auto
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3fLL
#define NIL -1
//_______

int N;
vector <pii> T[100010];
int d[100010];

//ret: mcos[] の最大値のインデックス
//s を始点としたとき、距離が最大になるノード番号
int bfs(let s)
{
   queue <int> Q;
   Q.emplace(s);
   memset( d, INF, sizeof(d) );
   d[s] = 0;
   int maxp = s;

   while (!Q.empty()) {
      let u = Q.front(); Q.pop();
      for (let e : T[u]) {
         if (d[e.se] == INF) {
            d[e.se] = d[u] + e.fi;
            Q.emplace(e.se);
            if( d[maxp] < d[e.se] ) maxp = e.se;
         }
      }
   }
   return (maxp);
}

int diameter()
{
   /*
   let p = bfs(0);   //適当なノードから幅探
   let ansp = bfs(p);
   return ( d[ansp] );
   */
   return ( d[ bfs(bfs(0)) ] );
}

signed main()
{
   FAST();
   cin >> N;
   rep(i, N-1) {
      int s, t, w;
      cin >> s >> t >> w;
      T[s].pb( pii(w,t) );
      T[t].pb( pii(w,s) );
   }

   outl( diameter() );
}




Measured memory_bytes: 9864
#include<iostream>

int main(void){
    std::string beforeContest;
    std::cin >> beforeContest;

    if(beforeContest == "ABC"){
        std::cout << "ARC" << std::endl;
    } else if(beforeContest == "ARC"){
        std::cout << "ABC" << std::endl;
    }

    return 0;

}

Measured memory_bytes: 3600
import java.util.Arrays;
import java.util.Scanner;

class Main{
    private static char[] input;
    private static final char[] starts = {'(', '['};
    private static final char[] ends = {')', ']'};
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String next;
        while(!(next = sc.nextLine()).equals(".")){
            input = next.toCharArray();
            System.out.println(calc() ? "yes" : "no");
        }
    }

    private static boolean calc(){
        int index;
        try{
            for(int i = 0; i < input.length; i++){
                if(Arrays.binarySearch(ends, input[i]) > -1) return false;
                if((index = Arrays.binarySearch(starts, input[i])) > -1) i = calc(i, index);
                if(i < 0) return false;
            }
        }catch (IndexOutOfBoundsException ignored){}
        return true;
    }

    private static int calc(int now, int target){
        int index;
        try{
            for(int i = now + 1; i < input.length; i++){
                if(input[i] == ends[target]) return i;
                if(input[i] == ends[(target + 1) % 2]) return -9;
                if((index = Arrays.binarySearch(starts, input[i])) > -1) i = ((index = calc(i, index)) == -1 ? input.length : index);
            }
        }catch (IndexOutOfBoundsException ignored){}
        return -9;
    }
}

Measured memory_bytes: 42596
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;
 
int main(){

	int n;
	cin >> n;
	
	vector<int> d(n);
	rep(i, n) cin >> d[i];
	
	vector<bool> used(1000000);
	
	rep(i, n){
		int num = 0;
		rep(j, min(6, n-i)){
			num += d[i + j];
			used[num] = true;
			num *= 10;
		}
	}
 
 	rep(i, 1000000){
 		if(!used[i]){
 			cout << i << endl;
 			break;
 		}
 	}
 
	return 0;
}

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

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

}


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

using namespace std;
using ll = long long;

string S;
int freq[101];
int main(){

    cin >> S;
    for(char ch : S){
        freq[ch - '0']++;
    }
    cout << min(freq[0], freq[1]) * 2 << endl;


    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int n, m;
vector<vector<int>> p;
vector<int> memo;

int get(int i) {
  if (memo[i])
    return memo[i];
  int ret = 0;
  for (auto &j : p[i]) {
    ret = max(ret, get(j));
  }
  return memo[i] = ret + 1;
}

int main() {
  cin >> n >> m;
  p.resize(n);
  memo.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p[a].push_back(b);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, get(i));
  }
  cout << ans - 1 << endl;
  return 0;
}


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

int main(void){
	int n,i;
	char summary[8];
	int ret[4];
	
	for(i=0;i<4;i++) ret[i]=0;
	scanf("%d",&n);
	while(n--){
		scanf("%s%*c",summary);
		if(strcmp(summary,"AC")==0){
			ret[0]++;
		}else if(strcmp(summary,"WA")==0){
			ret[1]++;
		}else if(strcmp(summary,"TLE")==0){
			ret[2]++;
		}else if(strcmp(summary,"RE")==0){
			ret[3]++;
		}else{
			printf("read error. n=%d\n",n);
		}
	}
	printf("AC x %d\n",ret[0]);
	printf("WA x %d\n",ret[1]);
	printf("TLE x %d\n",ret[2]);
	printf("RE x %d\n",ret[3]);
	return 0;
}


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

#define ll              long long
#define int             long long
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             (int)(1e18)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define rep(i,j,n)      for(int i=j;i<n;i++)
#define all(p)          p.begin(),p.end()
#define ub(a,b)         upper_bound(all(a),b)
#define lb(a,b)         lower_bound(all(a),b)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void run()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int32_t main()
{
	run();
	int n, w;
	cin >> n >> w;
	ll ans = 0;
	int dp[n + 1][w + 1];
	vector<int> wi(n + 1), v(n + 1);
	rep(i, 1, n + 1)
	{
		cin >> wi[i] >> v[i];
	}
	for (int j = 0; j <= w; j++)
	{
		dp[0][j] = 0;
	}
	for (int i = 0; i <= n; i++)
	{
		dp[i][0] = 0;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			if (wi[i] <= j)
			{
				dp[i][j] = max(dp[i - 1][j - wi[i]] + v[i], dp[i - 1][j]);
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	cout << dp[n][w] << endl;
	return 0;
}

Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

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;
}

double hoge(double x) {
	if (x == 1)return 1;
	return x * (hoge(x - 1));
}
int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;cin >> N;
	vector<tuple<int,double, double>>xy(N);
	rep(i, N) {
		double a, b;cin >> a >> b;
		xy[i] = make_tuple(i,a, b);
	}
	double sum = 0;
	SORT(xy);
	do {
		rep(i, N - 1) {
			double a = get<1>(xy[i]) - get<1>(xy[i + 1]);
			double b = get<2>(xy[i]) - get<2>(xy[i + 1]);
			sum += sqrt(a * a + b * b);
		}
	} while (next_permutation(xy.begin(), xy.end()));
	printf("%.10f\n", sum / hoge(N));

	return 0;
}


Measured memory_bytes: 256
D,G=map(int,input().split())
PC=[list(map(int,input().split())) for _ in range(D)]

E=[]
for i in range(2**D):
  tmp=0
  cnt=0
  for j in range(D):
    if (i>>(D-j-1))&1:
      tmp+=(j+1)*100*PC[j][0]+PC[j][1]
      cnt+=PC[j][0]
  E.append([cnt,tmp])
#print(E)

for i in range(2**D):
  if E[i][1]<G:
    tmp=0
    cnt=0
    for j in range(D-1,-1,-1):
      if (i>>(D-j-1))&1==0:
        for k in range(PC[j][0]):
          tmp+=100*(j+1)
          cnt+=1
          if E[i][1]+tmp>=G:
            break
      else:
        continue
      break
    E[i][0]+=cnt
    E[i][1]+=tmp
#print(E)

E.sort()
#print(E)

for i in E:
  if i[1]>=G:
    print(i[0])
    break

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#define N 12345
using namespace std;
int n,k,a[N],sum;
bool cmp(int a,int b) {
	return a > b;
}
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n,cmp);
	for(int i=0;i<k;i++) sum += a[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    k = kwargs["k"]

    res = n - (max(0, (n - 2 * k) // k)) * k

    while True:
        if res <= abs(k - res):
            break
        else:
            res = abs(k - res)

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    #kwargs["n"] = [int(i) for i in cin][0]
    kwargs["n"], kwargs["k"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

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

int main(){
    int N,K;
    string S;
    cin >> N >> K >> S;
    S[K-1] = (char(S[K-1]+32));
    cout << S << endl;
}

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

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << "\n";
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;

//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos( -1.0 );

//global-----------------------------------------------------------------------------------------------------------------------
int n;
VI a;
int ans;
char str[100];

//function---------------------------------------------------------------------------------------------------------------------
int main() {
	while ( scanf( "%d", &n ) ) {
		if ( !n ) {
			return 0;
		}
		int stage = 0;
		a.resize( n );
		rep( i, n ) {
			a[ i ] = 0;
		}
		scanf( "%s", str );
		rep( i, 100 ) {
			if ( str[ i ] == 'M' ) {
				a[ i % n ]++;
			}
			if ( str[ i ] == 'S' ) {
				stage += a[ i % n ] + 1;
				a[ i % n ] = 0;
			}
			if ( str[ i ] == 'L' ) {
				a[ i % n ] += stage + 1;
				stage = 0;
			}
		}
		SORT(a);
		rep( i, n ) {
			printf( "%d ", a[ i ] );
		}
		printf( "%d\n", stage );
	}
	return 0;
}

Measured memory_bytes: 1212
main = do
  s <- getContents
  let v = map (map read . words) . lines $ s
  let w = map solve v
  let x = map (\x-> if x then "YES" else "NO") $ w
  mapM_ putStrLn x

solve::[Double] -> Bool
solve [xa,ya,xb,yb,xc,yc,xd,yd] =
  abs(dot u v) < eps
  where u = (xb-xa, yb-ya)
        v = (xd-xc, yd-yc)
        dot (a,b) (c,d) = a*c + b*d
        eps=1e-12

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

int main() {
	int N;
	cin >> N;
	vector<int> a(N+2);
	a[0] = 0;
	int a_num = 0;
	for (int i = 1; i <= N; i++) {
		int b;
		cin >> b;
		if(a[a_num] != b){
			a_num++;
			a[a_num] = b;
		}
	}
	a.push_back(0);
	vector<int> kado;
	kado.push_back(0);
	for (int i = 1; i < a.size()-1; i++)
		if ((a[i] > a[i-1] && a[i] > a[i+1]) ||
			(a[i] < a[i-1] && a[i] < a[i+1]))
			kado.push_back(a[i]);
	vector<int> mountain;
	vector<int> valley;
	for (int i = 0; i < kado.size(); i++)
		if (i%2 == 1)
			mountain.push_back(kado[i]);
		else
			valley.push_back(kado[i]);
	sort(kado.begin(), kado.end());
	sort(mountain.begin(), mountain.end());
	sort(valley.begin(),valley.end());
	int ans = 0, max = 0;
	if(kado.size() == 1){
		max = 0;
		cout << max << endl;
		return 0;
	}
	int m = 0, b = 0;
	for(int i = 0; i < kado.size(); i ++){
		if (mountain[m] == kado[i]){
			m++;
			ans--;
		}
		if (valley[b] == kado[i]){
			b++;
			ans++;
		}
		if (kado[i] < kado[i+1])
			if (ans > max)max = ans;
	}
	cout << max << endl;
}


Measured memory_bytes: 4220
N = int(input())
S = input()
chars = list("abcdefghijklmnopqrstuvwxyz")
ans_lst = []
for cut in range(1, N):
    left = S[:cut]
    right = S[cut:]
    count = 0
    for char in chars:
        if char in left and char in right:
            count += 1
    ans_lst.append(count)
print(max(ans_lst))

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

ll choice(ll x){
    ll num;
    num = x * (x-1) /2;
    return num;
}

int main(){
    int n;
    cin >> n;
    vector<string> vec(n);
    for(int i=0;i<n;i++){
        cin >> vec.at(i);
    }
    for(int i=0;i<n;i++){
        sort(vec.at(i).begin(),vec.at(i).end());
    }
    sort(vec.begin(),vec.end());
    ll num=1;
    ll ans=0;
    for(int i=0;i<n-1;i++){
        if(vec.at(i)==vec.at(i+1)){
            num++;
        }else{
            ans+=choice(num);
            num=1;
        }
    }
    if(num>1){
        ans+=choice(num);
    }
    cout << ans << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<vector<int>> a(3, vector<int>(10));
  vector<vector<int>> b(3, vector<int>(10));
  vector<vector<int>> c(3, vector<int>(10));
  vector<vector<int>> d(3, vector<int>(10));
  for (int i = 0; i < n; i ++) {
    int w, x, y, z;
    cin >> w >> x >> y >> z;
    x --, y --;
    if (w == 1) a[x][y] += z;
    else if (w == 2) b[x][y] += z;
    else if (w == 3) c[x][y] += z;
    else if (w == 4) d[x][y] += z;
  }

  for (int i = 0; i < 4; i ++) {
    for (int j = 0; j < 3; j ++) {
      for (int k = 0; k < 10; k ++) {
        if (i == 0) cout <<  " " << a[j][k];
        else if (i == 1) cout << " " << b[j][k];
        else if (i == 2) cout << " " << c[j][k];
        else if (i == 3) cout << " " << d[j][k];
      }
      cout << endl;
    }
    if (i != 3) cout << "####################" << endl;
  }
}


Measured memory_bytes: 3156
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
D = {alpha[i]: [-1] for i in range(26)}
N = len(S)
for i in range(N):
  D[S[i]].append(i)
cnt = 0
for i in D:
  D[i].append(N)
  if D[i] != [-1, N]:
    cnt += 1
if cnt == 1:
  print(0)
else:
  m = int(1e9)
  for i in D:
    n = len(D[i])
    M = max(D[i][j+1] - D[i][j] for j in range(n-1))
    if m > M:
      m = M
  print(m-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	int arr[5][5];
	for(int i=1;i<=3; i++){
		for(int j=1;j<=3;j++) {
			cin>>arr[i][j];
		}
	}
	
	int n,num;
	cin>>n;
	for(int k=1;k<=n;k++) {
		cin>>num;
		for(int i=1;i<=3; i++){
			for(int j=1;j<=3;j++) {
				if(num == arr[i][j])
					arr[i][j] = -1;
			}
		}
	}
	
	bool isok = false;
	for(int i=1;i<=3;i++)
	{
		int ct = 0;
		for(int j=1;j<=3;j++)
			if(arr[i][j]==-1)
				ct++;
		if(ct == 3)
			isok = true;
	}
	if(!isok){
		for(int i=1;i<=3;i++)
		{
			int ct = 0;
			for(int j=1;j<=3;j++)
				if(arr[j][i]==-1)
					ct++;
			if(ct == 3)
				isok = true;
		}	
		if(isok)
			cout<<"Yes";
		else {
			int ct = 0;
			for(int i=1;i<=3;i++)
				if(arr[i][i] == -1)
					ct++;
			if(ct == 3)
				isok = true;
			
			if(isok)
				cout<<"Yes";
			else{
				int ct = 0;
				for(int i=1;i<=3;i++){
					if(arr[i][4-i] == -1)
						ct++;
				}
				
				if(ct == 3)
					isok = true;
				
				if(isok)
					cout<<"Yes";
				else
					cout<<"No";
			}		
		}	
	}
	else
		cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 25;
const int MAXS = 1 << 21;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXS];
int n, k, dp[MAXN][MAXS];
int main() {
	read(n), read(k);
	for (int i = 0, bit = 1 << i; i <= n; i++, bit <<= 1) {
		scanf("\n%s", s);
		for (int j = 0; j <= bit - 1; j++)
			dp[i][j + bit] = s[j] == '1';
	}
	for (int i = n, bit = 1 << i; i >= 1; i--, bit >>= 1) {
		for (int j = i, bjt = 1 << j; j <= n; j++, bjt <<= 1)
		for (int k = 0; k <= bjt - 1; k++) {
			int tmp = dp[i][k + bjt], p = -1, q = -1;
			for (int t = i; t >= 1; t--)
				if (k & (1 << (t - 1))) {
					p = t;
					break;
				}
			for (int t = i; t >= 1; t--)
				if ((k & (1 << (t - 1))) == 0) {
					q = t;
					break;
				}
			dp[0][(k + bjt) >> i] += tmp;
			int s = k & ((1 << i) - 1), t = k >> i;
			if (p != -1) dp[p - 1][(s & ((1 << (p - 1)) - 1)) + ((2 * t + 1) << (p - 1)) + (bjt >> (i - p))] += tmp;
			if (q != -1) dp[q - 1][(s & ((1 << (q - 1)) - 1)) + ((2 * t) << (q - 1)) + (bjt >> (i - q))] += tmp;
		}
	}
	for (int i = n, bit = 1 << i; i >= 0; i--, bit >>= 1) {
		for (int j = 0; j <= bit - 1; j++)
			//printf("%d %d %d\n", i, j, dp[0][j + bit]);
			if (dp[0][j + bit] >= k) {
				for (int k = i - 1; k >= 0; k--)
					if (j & (1 << k)) putchar('1');
					else putchar('0');
				puts("");
				return 0;
			}
	}
	assert(false);
	return 0;
}

Measured memory_bytes: 174336
"""
1. The initial character of S is an uppercase A.
2. There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).
3. All letters except the A and C mentioned above are lowercase.
"""
import collections
def f(r): return r[0] == 'A' and  collections.Counter(r[2:-1])['C'] == 1 and  all([l in set(['A', 'C']) or l.lower() ==l for l in r ])

print 'AC' if f(raw_input()) else 'WA'

Measured memory_bytes: 85940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20;
const int M=2e2+20;
ll v[N];
ll C[M][M]; 
void init()
{
	memset(C,0,sizeof(C));
	C[0][0]=1;
	for(int i=1;i<=50;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
}
int main()
{
	int n,A,B;
	init();
	while(cin>>n>>A>>B)
	{
		double ave=0;
		for(int i=0;i<n;i++)
			cin>>v[i];
		sort(v,v+n);
		reverse(v,v+n);//大->小
		for(int i=0;i<A;i++) 
			ave+=v[i];
		ave/=A;
		int num=0,k=0;
		for(int i=0;i<n;i++)
		{
			if(v[i]==v[A-1])
			{
				num++;
				if(i<A)
					k++;
			}
		}	
		ll ans=0; 
		if(k==A)//前A个相同,可以增加个数 
		{
			for(int i=A;i<=B;i++)
				ans+=C[num][i];
		}
		else
			ans+=C[num][k];
 
 		cout.precision(20);
 		cout<<fixed<<ave<<endl;
 		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  bool result = false;
  vector<vector<int>> data(9,vector<int>(9));
  
  for(int i=0;i<9;i++){
    for(int j=0;j<9;j++){
      int x = (i+1)*(j+1);
      if(N==x)
        result = true;
    }
  }

  if(result)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m, q;
	cin >>n >>m >>q;
	VL a(q), b(q), c(q), d(q);
	rep(i, q){ cin >>a[i] >>b[i] >>c[i] >>d[i]; a[i]--; b[i]--;}
	
	VI ks(n);
	auto rec=[&](auto rec, int z, int pi){
		ll ans = 0;
		if(z == n){
			ll sm = 0;
			rep(i, q){
				if(ks[b[i]] - ks[a[i]] == c[i]) sm += d[i];
			}
			return sm;
		}
		
		rep2(i, pi, m){
			ks[z] = i;
			ans = max(ans, rec(rec, z+1, i));
		}
		return ans;
	};
	cout << rec(rec, 0, 0) <<"\n";
	return 0;
}


Measured memory_bytes: 3616
from itertools import combinations_with_replacement

n,m,q = map(int,input().split())
L = [list(map(int,input().split())) for i in range(q)]

#重複組み合わせ
ans = 0
for i in combinations_with_replacement(range(m),n):
    t = 0
    for a,b,c,d in L:
        if i[b-1] - i[a-1] == c:
            t += d
    ans = max(ans,t)

print(ans)

Measured memory_bytes: 73512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N,K; cin>>N>>K;
  vector<int> H(N);
  for(auto& h : H) {
    cin >> h;
  }

  vector<int> dp(N+10, INT_MAX);
  dp[0] = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 1; j <= K; j++) {
      dp[i+j] = min(abs(H[i] - H[i+j]) + dp[i], dp[i+j]);
    }
  }

  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char x[100005],y;
int g,z;
int main()
{
    while(x[z]=getchar(),x[z]!='\n')
    {
        if(z==0)y=x[z];
        if(x[z]!=y)g++,y=x[z];
        z++;
    }
    cout<<g;
    return 0;
}

Measured memory_bytes: 384
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();
const int N=2e5;
vector<int>g[N];
map<pair<int, int>,int>edge;

// void dfs(int node,int p=-1,int col=-1)
// {
// 	int color=0;
// 	for(auto child:g[node])
// 	{
// 		if(child.ff==p)
// 		{
// 			continue;
// 		}
// 		color++;
// 		if(color==col)
// 		{
// 			color++;
// 		}
// 		dfs(child.ff,node,color);
// 		edge[child.ss]=color;
// 	}
// }

vector<int>vis(N,0);
vector<int>parentcolor(N,-1);
vector<pair<int, int>>vp;


void bfs(int node)
{
	queue<int>q;
	q.push(node);

	vis[node]=1;


	while(!q.empty())
	{
			int cur=1;
		int top=q.front();q.pop();

		for(int child:g[top])
		{
			if(vis[child])
			{
				continue;
			}
			if(cur==parentcolor[top])
			{
				cur++;
			}

			parentcolor[child]=edge[{child,top}]=edge[{top,child}]=cur++;
			vis[child]=1;
			q.push(child);
		}

	}
}

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int n;
	cin>>n;
	for(i=1;i<=n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
		vp.emplace_back(a,b);
	}

	int colors=INT_MIN;

	for(i=1;i<=n;i++)
	{
		colors=max(colors,(int)g[i].size());
	}

	d(colors);
	cout<<colors<<endl;

	bfs(1);

	for(auto it:vp)
	{
		cout<<edge[it]<<endl;
	}

}

Measured memory_bytes: 28828