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

int mo=1000000007;
int fct[300000];
int mi[200005];
int modInverse(int a, int m) 
{ 
    int m0 = m; 
    int y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        int q = a / m; 
        int t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
}

void do1(int c)
{
    for(int i=0;i<=c;i++)
        mi[i]=modInverse(fct[i],mo);
}
int slv(int x,int y)
{
    int ans=1;
    ans=(fct[x+y]*ans)%mo;
    ans=(ans*mi[x])%mo;
    ans=(ans*mi[y])%mo;
    return ans;
}
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,h,w;
    cin>>h>>w>>n;
    fct[0]=1;
    for(int i=1;i<=w+h+5;i++)
        fct[i]=(fct[i-1]*i)%mo;
    do1(w+h);
    int ans=slv(h-1,w-1);
    int dp[n+5];
    memset(dp,0,sizeof(dp));
    pair<int,int> a[n+5];
    for(int i=0;i<n;i++)
        cin>>a[i].first>>a[i].second;
    a[n].first=a[n].second=1;
    sort(a,a+n+1);
    dp[0]=1;
    //cout<<ans<<" \n";
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<i;j++)
            if(a[j].first<=a[i].first && a[j].second <=a[i].second)
                dp[i]=(dp[i] - (dp[j] * slv(a[i].first - a[j].first,a[i].second - a[j].second))%mo + mo)%mo;
        ans = (ans +(dp[i] * slv(h - a[i].first  , w - a[i].second ))%mo +mo)%mo;
    }
    cout<<ans;
}


Measured memory_bytes: 6804
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <utility>
#include <cmath>
using namespace std;
#define MAXSIZE 100005
#define PI 3.141592653589793
#define MOD_CONST 1000000007
using lli = long long int;
using PII = pair<int, int>;

lli n, a, b;

vector<lli> row(55);
vector<vector<lli>> comb(55, row);

lli calc_comb(lli n, lli r){
    if(n < r){
        return 0;
    }
    
    if(comb[n][r] > 0){
        return comb[n][r];
    }
    
    if(r == 0){
        return comb[n][r] = 1;
    }
    
    if(r * 2 > n){
        return comb[n][r] = calc_comb(n, n - r);
    }
    
    return comb[n][r] = calc_comb(n - 1, r) + calc_comb(n - 1, r - 1);
}

int main(){
    cin >> n >> a >> b;
    
    vector<lli> v(n);
    for(lli i = 0; i < n; ++i){
        cin >> v[i];
    }
    
    sort(v.begin(), v.end(), greater<lli>());
    
    lli num_upper_a_eq_ini = 0;
    lli num_eq_ini = 0;
    lli num_upper_a_eq_a1 = 0;
    lli num_eq_a1 = 0;
    
    lli v_sum = 0;
    for(lli i = 0; i < n; ++i){
        if(v[i] == v[0]){
            if(i < a){
                // 上位a個中何個が初項と等しいかをカウント
                num_upper_a_eq_ini++;
            }
            
            // 全要素中何個が初項と等しいかをカウント
            num_eq_ini++;
        }
        
        if(v[i] == v[a - 1]){
            if(i < a){
                // 上位a個中何個が第a-1項と等しいかをカウント
                num_upper_a_eq_a1++;
            }
            
            // 全要素中何個が第a-1項と等しいかをカウント
            num_eq_a1++;
        }
        
        if(i < a){
            // 上位a個の価値の合計を計算
            v_sum += v[i];
        }
    }
    
    printf("%.15lf\n", 1.0 * v_sum / a);
    
    if(v[0] != v[a - 1]){
        cout << calc_comb(num_eq_ini, num_upper_a_eq_ini) * calc_comb(num_eq_a1, num_upper_a_eq_a1)  << endl;
    }else{
        lli patterns_sum = 0;
        for(lli i = a; i <= min(b, num_eq_ini); ++i){
            patterns_sum += calc_comb(num_eq_ini, i);
        }
        cout << patterns_sum << endl;
    }
    return 0;
}


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

 int main() {
   int A,B;
   cin >> A >> B;
    
   int a = A;
   int b = B;
   if(A > B){
     a--;
     cout << A + a << endl;
   }else if(B > A){
     b--;
     cout << B + b << endl;
   }else if(A == B){
     cout << A + B << endl;
   }
  
  // cout << A << a << endl;
} 

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

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////
int h,w;
char s[21][21];
vector<int>a={1,0,-1,0};
vector<int>b={0,1,0,-1};
int dismax;
void dfs(int sx,int sy,vector<vector<int>>&dis){
  rep(i,4){
    int dx=a[i],dy=b[i];
    if(s[dx+sx][dy+sy]!='#'&&dx+sx<h&&dy+sy<w&&dx+sx>=0&&dy+sy>=0&&(dis[dx+sx][dy+sy]>dis[sx][sy]+1)){
      dis[dx+sx][dy+sy]=dis[sx][sy]+1;
      dfs(sx+dx,sy+dy,dis);
  }
}
}
signed main() {
  cin>>h>>w;
  rep(i,h)rep(j,w)cin>>s[i][j];
  int ans=0;
  rep(i,h)rep(j,w){
    int sx=i,sy=j;
    if(s[sx][sy]=='#')continue;
    dismax=0;
    vector<vector<int>>dis(h,vector<int>(w,INF));
    dis[sx][sy]=0;
    dfs(sx,sy,dis);
    rep(ii,h)rep(jj,w)if(dis[ii][jj]!=INF)dismax=max(dismax,dis[ii][jj]);
    ans=max(ans,dismax);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


string s;

int main(){
	cin >> s;
	
	if(s[0] != 'A'){
		cout << "WA" << endl;
		return 0;
	}
	bool b = 0;
	if(s[1] <= 'Z' || s[s.size()-1] <= 'Z') b = 1;
	int c = 0;
	for(int i = 2; i < s.size()-1; i++){
		if(s[i] == 'C') c++;
		else if(s[i] <= 'Z') b = 1;
	}
	if(c != 1 || b){
		cout << "WA" << endl;
		return 0;
	}
	cout << "AC" << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner scanner = new Scanner(System.in);
    String S = scanner.next();
    int n = S.length();
    byte[] nums = new byte[n];
    for(int i=0;i<n;i++) {
      nums[i] = (byte)(S.charAt(i)-'0');
    }

    int max = (int)Math.pow(2, n-1);
    long sum = 0;
    for(int i=0;i<max;i++) {
      sum += calc(nums, i);
    }
    System.out.println(sum);

    scanner.close();
  }

  private static long calc(byte[] nums, int p) {
    boolean[] plus = new boolean[nums.length-1];
    for(int i=0;i<plus.length;i++) {
      if((p>>i)%2 == 1) plus[i] = true;
    }

    String exp = "";
    for(int i=0;i<nums.length;i++) {
      exp += nums[i];
      if((i==nums.length-1) || plus[i]) {
        exp += "a";
      }
    }

    String[] values = exp.split("a");
    long sum = 0;
    for(String v : values) {
      sum += Long.parseLong(v);
    }
    
    return sum;
  }
}


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

int main(){
  int N,M;
  cin >> N >> M;
  int L[M];
  int R[M];
  for(int i=0;i<M;i++){
    cin >> L[i] >> R[i];
  }
  sort(L,L+M);
  sort(R,R+M);
  int ans = 0;
  if(R[0]-L[M-1] >= 0){
   ans = 1 + R[0] - L[M-1];
 }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
N, M, X = map(int, input().split())
cost_masses = map(int, input().split())

cost_ToZero = cost_ToEnd = 0

for cost_mass in cost_masses:
    if X < cost_mass:
        cost_ToEnd = cost_ToEnd + 1
    elif X > cost_mass:
        cost_ToZero = cost_ToZero + 1
else:
  print(min([cost_ToZero, cost_ToEnd]))

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

int main() {
  string S;
  cin >> S;
  int n = S.length();
  int A[n] = {}; int B[n] = {}; int C[n] = {}; int D[n] = {};
  rep(i, n) {
    if (S[i] == 'A') ++A[i];
    else if (S[i] == 'B') ++B[i];
    else if (S[i] == 'C') ++C[i];
    else {
      ++A[i]; ++B[i]; ++C[i]; ++D[i];
    }
  }

  int Suml[n] = {};
  int Sumr[n] = {};
  Suml[0] = D[0]; Sumr[n-1] = D[n-1];
  for (int i = 1; i < n; ++i) Suml[i] = Suml[i-1] + D[i];
  for (int i = n-2; i >= 0; --i) Sumr[i] = Sumr[i+1] + D[i];
  ll Pow[Sumr[0] + 1] = {1};
  for (int i = 1; i <= Sumr[0]; ++i) Pow[i] = Pow[i-1] * 3 % MOD;
  
  ll L[n], R[n];
  L[0] = A[0]; R[n-1] = C[n-1];
  for (int i = 1; i < n; ++i) {
    L[i] = L[i-1];
    if (D[i]) L[i] *= 3;
    if (A[i]) L[i] += Pow[Suml[i-1]];
    L[i] %= MOD;
  }
  for (int i = n-2; i >= 0; --i) {
    R[i] = R[i+1];
    if (D[i]) R[i] *= 3;
    if (C[i]) R[i] += Pow[Sumr[i+1]];
    R[i] %= MOD;
  }
  
  ll ans = 0;
  for (int i = 1; i < n-1; ++i) {
    if (B[i]) {
      ans += L[i-1] * R[i+1];
      ans %= MOD;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5120
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

class Dice {
public:
    Dice(int i_one, int i_two, int i_three, int i_four, int i_five, int i_six)
      : one(i_one)
      , two(i_two)
      , three(i_three)
      , four(i_four)
      , five(i_five)
      , six(i_six)
    {
    }

    inline void E() noexcept
    {
        int buf_one   = this->one;
        int buf_three = this->three;
        int buf_four  = this->four;
        int buf_six   = this->six;

        this->one   = buf_four;
        this->three = buf_one;
        this->four  = buf_six;
        this->six   = buf_three;
    }

    inline void N() noexcept
    {
        int buf_one   = this->one;
        int buf_two   = this->two;
        int buf_five  = this->five;
        int buf_six   = this->six;

        this->one   = buf_two;
        this->two   = buf_six;
        this->five  = buf_one;
        this->six   = buf_five;
    }

    inline void S() noexcept
    {
        int buf_one   = this->one;
        int buf_two   = this->two;
        int buf_five  = this->five;
        int buf_six   = this->six;

        this->one   = buf_five;
        this->two   = buf_one;
        this->five  = buf_six;
        this->six   = buf_two;

    }

    inline void W() noexcept
    {
        int buf_one   = this->one;
        int buf_three = this->three;
        int buf_four  = this->four;
        int buf_six   = this->six;

        this->one   = buf_three;
        this->three = buf_six;
        this->four  = buf_one;
        this->six   = buf_four;
    }

    inline void print() noexcept
    {
        std::cout << this->one << std::endl;
    }

private:
    int one;
    int two;
    int three;
    int four;
    int five;
    int six;
};

int main()
{
    int one, two, three, four, five, six;
    std::cin >> one >> two >> three >> four >> five >> six;
    Dice dice(one, two, three, four, five, six);

    std::string command;
    std::cin >> command;

    for (std::size_t i = 0; i < command.length(); ++i) {
        switch (command[i]) {
        case 'E':
        {
            dice.E();
            break;
        }
        case 'N':
        {
            dice.N();
            break;
        }
        case 'S':
        {
            dice.S();
            break;
        }
        case 'W':
        {
            dice.W();
            break;
        }
        default:
        {
            break;
        }
        }
    }

    dice.print();

    return 0;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
#define LL long long
#define M 1000005 
using namespace std;
const int P=1e9+7; 
int  A[M];
int main(){
	int n,m;
	cin>>n>>m;
	if(m-n>=2100)puts("0");
	else{
		vector<int>p;
		for(int i=n;i<=m;i++)p.push_back(i%2019);
		int ans=2019;
		for(int i=0;i<p.size();i++)
			for(int j=i+1;j<p.size();j++)
				if(p[i]*p[j]%2019<ans)ans=p[i]*p[j]%2019;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int a, b, c, d,e,f;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &d);

	if (c % b == 0) e = c / b;
	else  e = c / b + 1;


	if (a % d == 0) f = a / d;
	else  f = a / d + 1;


	if (e > f)printf("No");
	else printf("Yes");
	return 0;


}

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

int n, m;
int a[10000];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n, greater<int>());
  
  int sum = accumulate(a, a + n, 0);
  cout << (a[m - 1] * m * 4 >= sum ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main() {

    int N; cin >> N;

    ullong ans = 1;
    double ans_d = 1.0 / 1e18;
    bool over = false;

    for (int i=0; i<N; i++){
        ullong A; cin >> A;
        if (A == 0) {
            cout << 0 << endl;
            return 0;
        }

        if (!over) {
            ans_d = ans_d * A;
            if (ans_d > 1.1) {
                over = true;
            }
            ans *= A;
        }
        if (ans > static_cast<ullong>(1e18)) {
            over = true;
        }
    }

    if (over)
        cout << -1 << endl;
    else
        cout << ans << endl;
}



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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vi vector<int>
#define sl set<ll>
#define sc set<char>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mpi map<ll,ll>
#define mpc map<char,ll>
#define forn(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf        1000000000000

void solve()
{
    ll n;
    cin>>n;
    double dp[n+1]={0};
    double p;
    dp[0]=1;
    forn(i,n){
		cin>>p;
		for(ll j=i+1;j>=0;j--){
			dp[j]=(j==0?0:dp[j-1]*p)+dp[j]*(1-p);
		}
	}
	double ans=0;
	for(ll i=0;i<=n;i++){
		if(i>n-i){
			ans+=dp[i];
		}
	}
	cout<<fixed<<setprecision(10)<<ans;
}

int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        cout<<endl;
    }
}


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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using P = pair<int,int>;

// code starts
int main()
{
  int k;
  cin >> k;
  int now = 1;
  int mag = 7;
  mag %= k;
  while(now <= k*2 && mag != 0)
  {
    now++;
    mag = mag*10+7;
    mag %= k;
  }
  if(mag == 0) cout << now << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static int N;
    static int K;
    static string S;

    public static void Main(string[] args)
    {
        N = Input.NextInt();
        K = Input.NextInt();
        S = Input.NextString();

        S = S + "9";
        int s = 0;
        int t = 0;
        int len = 0;
        int shaku = 0;
        int ans = 0;
        while (S[s] == '1')
        {
            s++;
            len++;
        }
        while (true)
        {
            {
                while (S[s] == '0')
                {
                    s++;
                    len++;
                }
                while (S[s] == '1')
                {
                    s++;
                    len++;
                }
                shaku++;
                if (shaku <= K)
                    ans = Math.Max(ans, len);
                if (S[s] == '9')
                    break;
            }
            if (shaku >= K)
            {
                while (S[t] == '1')
                {
                    t++;
                    len--;
                }
                while (S[t] == '0')
                {
                    t++;
                    len--;
                }
                shaku--;
            }
        }

        Console.WriteLine(ans);
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 14292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



// youtube解説

struct Edge {
    int to, id;
};

vector<vector<Edge> > g;
vector<int> ans;

void dfs(int v, int c = -1, int p = -1) {
    int k = 1;
    rep(i, sz(g[v])) {
        int u = g[v][i].to, ei = g[v][i].id;
        if (u == p) continue;
        if (k == c) ++k;
        ans[ei] = k; ++k;
        dfs(u, ans[ei], v);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    g.resize(n);
    ans = vector<int>(n - 1);
    
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].eb((Edge){ b, i });
        g[b].eb((Edge){ a, i });
    }
    dfs(0);
    int mx = 0;
    rep(i, n) chmax(mx, sz(g[i]));
    cout << mx << endl;
    rep(i, n - 1) cout << ans[i] << endl;
}




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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n;
  vector<int> a(n + 1), v(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  int b = 1, c = 0;
  while (b != 2) {
    b = a[b];
    c++;
    if (v[b]) {
      cout << -1 << '\n';
      return 0;
    }
    v[b] = 1;
  }
  cout << c << '\n';
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<utility>
#include<map>
#include<stdio.h>
using namespace std;
int main()
{
	int a, b,k;
	cin >> a >> b>>k;
	int ans = 0;
	vector<int> ac(1000);
	int j = 0;
	for (int i = 1; i < 101;i++)
	{
		
		if (a%i == 0 &&b%i == 0)
		{
			ac.at(j)=i;
		}
		j++;
		
	}
	sort(ac.begin(), ac.end());
	reverse(ac.begin(), ac.end());
	cout << ac.at(k - 1) << endl;
}

Measured memory_bytes: 256
d, g = map(int, input().split())
pc = [0] + [list(map(int, input().split())) for _ in range(d)]

def solve(g, d):
  if d == 0:
    return 10**9
  n = min(g//(100*d), pc[d][0])
  t = n * d * 100
  if n == pc[d][0]:
    t += pc[d][1]
  if t < g:
    n += solve(g-t, d-1)
  return min(n, solve(g,d-1))

print(solve(g,d))

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

int rec(int a, int b, int c) {
  if( !a & !b ) return 0;
  if( c & 1 ) return( rec(a >> 1, b >> 1, c >> 1) );
  if( b & 1 ) return( rec(c >> 1, b >> 1, a >> 1) + rec((a|b|c) >> 1, 0, 0) + 1 );
  if( a & 1 ) return( rec(a >> 1, b >> 1, c >> 1) + 2 * rec((a|b|c) >> 1, 0, 0) + 2);
}

int main() 
{
  int n, m, data[3];

  while( cin >> n >> m, m ) {
    for(int i=0; i<3; i++) {
      data[i] = 0;
      int a;
      cin >> a;
      for(int j=0; j<a; j++) {
	int b;
	cin >> b; b--;
	data[i] |= 1 << b;
      }
    }

    int ret = min(rec(data[0], data[1], data[2]), rec(data[2], data[1], data[0]));
    if( ret <= m ) cout << ret << endl;
    else cout << -1 << endl;
  }
} 

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

using namespace std;
long long arr[200005];
long long pre[200005];
long long L, n;

long long S(int l, int r){
	long long res = pre[r];
	if(l != 0) res -= pre[l - 1];
	return res;
}

long long solve(){
	long long ans = 0;
	pre[0] = arr[0];
	for(int i = 1;i < n;i++){
		pre[i] = pre[i-1] + arr[i];
	}
	
	for(long long cut = 0;cut < n;cut++){
		
		long long res = arr[cut];
		int dis = (n - cut) / 2;
		
		long long O = 0;
		O += 2LL * S(n - dis, n-1);
		O -= S(cut, cut + dis - 1);
		O -= S(cut + 1, cut + dis); 
		O = (n - cut - 1) * L - O;
		res += O;
		
		ans = max(ans, res);
		//cout << dis << " " << res << "\n";
	}
	
	
	return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> L;
	cin >> n;
	
	long long ans = 0;
	for(int i = 0;i < n;i++) cin >> arr[i];
	ans = max(ans, solve()); 
	reverse(arr,arr+n);
	
	for(int i = 0;i < n;i++) arr[i] = L - arr[i];
	ans = max(ans, solve()); 
	cout << ans;
}


Measured memory_bytes: 3328
<?php

fscanf(STDIN, "%d %d", $N, $M);
$X = [];
for ($i = 0; $i < $N; ++$i) {
    fscanf(STDIN, "%d %d %d", $x, $y, $z);
    $X[] = [$x, $y, $z];
}

$total_ans = 0;
for ($i = 0; $i < 1<<3; ++$i) {
    $pq = new SplPriorityQueue();

    for ($j = 0; $j < $N; ++$j) {
        $tmp = [];
        $cost = 0;
        for ($k = 0; $k < 3; ++$k) {
            if ($i & 1<<$k) {
                $a = -1 * $X[$j][$k];
            } else {
                $a = $X[$j][$k];
            }
            $tmp[] = $X[$j][$k];
            $cost += $a;
        }
        $pq->insert($tmp, $cost);
    }

    $ans = [0, 0, 0];
    for ($j = 0; $j < $M; ++$j) {
        $tmp = $pq->extract();

        for ($k = 0; $k < 3; ++$k) {
            $ans[$k] += $tmp[$k];
        }
    }
    $tmp = 0;
    foreach ($ans as $val) {
        $tmp += abs($val);
    }
    $total_ans = max($total_ans, $tmp);
}

echo $total_ans, PHP_EOL;


Measured memory_bytes: 16980
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
ll po(ll x,ll y){
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x%mod;
	x=x*x%mod;
    }
    return res;
}
ll f[44][(1<<18)];
bool ok[(1<<18)];
int main(){
  ll n,x,y,z;
  cin>>n>>x>>y>>z;
  ll m=18;
  for(int i=0;i<(1<<m);i++){
      ok[i]=1;
    /*
      ll cnt=0;
      for(int j=0;j<m;j++){
	  if(i&(1<<j))cnt=0;
	  else cnt++;
	  if(cnt>=10)ok[i]=0;
      }*/
      bool th=0;
      th|=(i&(1<<(m-1-x-y-z)))==0;
      th|=(i&(1<<(m-1-y-z)))==0;
      th|=(i&(1<<(m-1-z)))==0;
      if(th==0)ok[i]=0;
  }
  for(int j=0;j<=n;j++)for(int i=0;i<(1<<m);i++)f[j][i]=0;
  ll p=(1<<(m-1));
  //if(m-8>=0)p+=(1<<(m-8));
  f[0][p]=1;
  for(int i=0;i<n;i++){
      for(int j=0;j<(1<<m);j++){
        for(int k=1;k<=10;k++){
          int r=j>>k;
          r+=(1<<(m-1));
          if(ok[r])mad(f[i+1][r],f[i][j]);
        }
      }
  }
  ll ans=po(10,n);
  for(int i=0;i<(1<<m);i++)mad(ans,-f[n][i]);
  if(ans<0)ans+=mod;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 86272
A, B = map(int, input().split())
S = str(input())

number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
flag = True
for i in range(A+B+1):
    if i == A:
        if S[i] != '-':
            flag = False
    else:
        if S[i] in number:
            pass
        else:
            flag = False

if flag:
    print ('Yes')
else:
    print ('No')




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

//

// int edit(string a, string b) {
// 	int n = a.size(), m = b.size();
// 	vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

// 	rep(i, n + 1) dp[i][0] = i;
// 	rep(j, m + 1) dp[0][j] = j;

// 	rep(i, 1, n + 1)rep(j, 1, m + 1) {
// 		int cost = 1;
// 		if (a[i - 1] == b[j - 1]) cost = 0;
// 		dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost});
// 	}

// 	return dp[n][m];
// }

// int query(const string &s) {
// 	return edit(s, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
// }

int query(const string &s) {
	cout << "? " << s << endl << flush;
	int ret;
	cin >> ret;
	return ret;
}


string concat(string a, string b, int n) {
	string cur = "";
	int pa = 0, pb = 0;

	while(pa < a.size() and pb < b.size()) {
		string tar = cur + a[pa] + b.substr(pb);
		if(tar.size() + query(tar) == n) {
			cur += a[pa++];
		} else {
			cur += b[pb++];
		}
	}

	while(pa < a.size()) cur += a[pa++];

	while(pb < b.size()) cur += b[pb++];

	return cur;
}

int main(void){
	const int T = 128;
	const int A = 62;
	string base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

	vector<string> ary;

	using pis = pair<int, string>;
	priority_queue<pis, vector<pis>, greater<pis>> pq; 

	int tlen = 0;
	rep(i, A) {
		string s = string(T, base[i]);
		const int len = T - query(s);
		if(len != 0) {
			pq.push(pis(len, string(len, base[i])));
		}
		tlen += len;
	}

	while(pq.size() >= 2) {
		pis s = pq.top(); pq.pop();
		pis t = pq.top(); pq.pop();
		string u = concat(s.second, t.second, tlen);
		pq.push(pis(u.size(), u));
	}


	const string ans = pq.top().second;
	cout << "! " << ans << endl;

	return 0;
}

Measured memory_bytes: 3800
module Main where

import Control.Monad
import Control.Applicative
import Data.List

showingList :: [Int] -> String
showingList (x:[]) = show x
showingList (x:xs) = (show x) ++ " " ++ (showingList xs)


main :: IO ()
main = do
    a <- getLine
    putStrLn $ if a >= "a" then "a" else "A"


Measured memory_bytes: 3768
#include<iostream>
#include<string>
#include<array>
#include<algorithm>
using namespace std;

int main() {
	string a;
	cin >> a;
	int s = 1000;
	for (int i = 0; i < a.size() - 2;i++) {
		int MIN = min(s, abs(753 - stoi(a.substr(i, 3))));
		s = MIN;
	}
	cout << s << endl;
}

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

int main() {
  int a,b,c =0;

  cin >> a >> b;
  if((a+b)%2==0){
  	c=(a+b)/2;
  }
  else
    c=(a+b)/2+1;
  cout << c << endl;
}


Measured memory_bytes: 3648
//#include<iostream>
#include<algorithm>
using namespace std;
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int n,K;
#define maxn 100011
int a[maxn];
int gcd(int a,int b) {return b?gcd(b,a%b):a;}
int main()
{
	scanf("%d%d",&n,&K);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int g=a[1],M=a[1];
	for (int i=2;i<=n;i++)
	{
		M=max(M,a[i]);
		g=gcd(g,a[i]);
	}
	if (K%g || M<K) printf("IMPOSSIBLE\n");
	else printf("POSSIBLE\n");
	return 0;
}

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

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

using namespace std;

void File(){
    freopen("ARC99D.in","r",stdin);
    freopen("ARC99D.out","w",stdout);
}

double cal(ll x){
    ll y=10,len=1,sum=0,ret=x;
    while(y<=x)y=(y<<1)+(y<<3),++len;
    while(len--){
        y/=10;
        sum+=x/y;
        x%=y;
    }
    return ret*1.0/sum;
}

bool judge(ll x){
    ll a=1;
    while(a<=x){
        if(cal(x+a)<cal(x))return false;
        a=(a<<1)+(a<<3);
    }
    return true;
}

ll k,now;


int main(){
    cin>>k;
    while(k--){
        ll a=1;
        while(true){
            if(judge(now+a)){
                now+=a;
                break;
            }
            a=(a<<1)+(a<<3);
        }
        cout<<now<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
cs   = list(map(int, input().split()))
t    = -1
i    = 0

while i + k <= len(cs) and cs[i] < 0:
    if cs[i + k - 1] < 0:
        x = abs(cs[i])
    else:
    	x = cs[i + k - 1] - cs[i] + min(abs(cs[i + k - 1]), abs(cs[i]))

    if t == -1 or x < t:
        t = x

    i += 1

if t == -1 or i + k <= len(cs) and cs[i + k - 1] < t:
    t = cs[i + k - 1]

print(t)

Measured memory_bytes: 14568
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
    int a;
    int b;
    cin >> a >> b;
    int d = a / b;
    int r = a % b;
    double f = (double)a/ b;
    printf("%d %d %f",d,r,f);
    
    return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    // freopen("tc.txt", "r" ,stdin);
    int n;
    cin >> n;
    map<string, int> mp;
    for(int i=0 ; i < n ;i++){
        string s;
        cin >> s;
        mp[s] += 1;
    }

    cout << mp.size() << endl;
    return 0;
}


Measured memory_bytes: 19252
#include <stdio.h>
#include <math.h>

int main()
{
    long long int n, i, tmp;
    scanf("%lld", &n);
    tmp = n;
    for (i = 2; i <= sqrt(n); ++i)
    {
        if (n % i == 0)
            tmp = n / i;
    }

    for (i = 1; tmp > 9; ++i)
        tmp = tmp / 10;
    printf("%lld\n", i);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <climits>

using namespace std;

int main(){
	
	int cnt[2000]={0};
	
	for(int k=2; k<=1000; ++k){
		
		for(int t=1; t<=1000; ++t){
			
			int sum=0;
			
			for(int s=t; (s-t<k && sum<=1000); ++s){
				sum += s;
			}
			
			cnt[sum]++;
		}
	}	
	
	int n;
	
	while(cin >>n, n){
		
		cout << cnt[n] << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;

bool IsPrime(int num)
{
  // 合成数とは？→　素数以外の数のこと
  // xが合成数ならば、√x以下の約数を持つ
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
    {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

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

  int l[q];
  vector<int> r(q);
  for(int i = 0; i < q; i++) {
    cin >> l[i] >> r[i];
  }

  // 累積和の配列の範囲を特定
  int max = *max_element(r.begin(), r.end());

  // 累積和の配列を生成
  int s[max+1];
  s[0] = 0;
  for(int i = 1; i < max+1; i++) {
    s[i] = s[i-1] + ((IsPrime(i) && IsPrime((i+1)/2))? 1 : 0);
  }

  // ラムダ式
  auto partSum = [&](int l, int r) -> int {
    if(l==0) return s[r];
    return s[r] - s[l-1];
  };

  for(int i = 0; i < q; i++) {
    cout << partSum(l[i], r[i]) << endl;
  }
}


Measured memory_bytes: 1792
s = input()
A = [chr(i) for i in range(97,97+26)]
ans = float('inf')
for a in A:
    count = 0
    a_count = 0
    for i in range(len(s)):
        if s[i] == a:
            a_count = max(count,a_count)
            count = 0
        else:
            count += 1
        if i == len(s)-1:
            a_count = max(count,a_count)
    ans = min(ans,a_count)
print(ans)

Measured memory_bytes: 3064
n = int(input())
b = [int(i) for i in input().split()]
ans = []

for i in range(n):
    for j in range(n-i)[::-1]:
        k = j+1
        if b[j] == k:
            del b[j]
            ans.append(k)
            break
    else:
        ans = [-1]
        break

for i in ans[::-1]: print(i)

Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
  int r,g,b,sum;
  scanf("%d%d%d",&r,&g,&b);
  sum=r*100+g*10+b;
  if(sum%4==0)
  {
    printf("YES\n");
  }
  else
  {
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
// head

int dp[66][3010][66];
int n,k,a[66],b[66],c[66],sb,sc;
int main() {
	scanf("%d%d",&n,&k);
	memset(dp,0x20,sizeof(dp));
	dp[0][0][0]=0;
	rep(i,0,n) scanf("%d",a+i);
	rep(i,0,k) scanf("%d",b+i),sb+=b[i];
	rep(i,0,k) scanf("%d",c+i),sc+=c[i];
	sort(a,a+n); reverse(a,a+n);
	sort(b,b+k); reverse(b,b+k);
	sort(c,c+k); reverse(c,c+k);
	int ps=0,ans=0x20202020;
	for (int i=0;i<=n;i++) {
		for (int s=0;s<=ps;s++) for (int l=0;l<=i;l++) if (dp[i][s][l]<0x20202020) {
			//printf("%d %d %d %d\n",i,s,l,dp[i][s][l]);
			if (i==n) {
				ans=min(ans,dp[i][s][l]);
				continue;
			}
			// put in 1
			if (l<k&&s+a[i]<=sb) {
				dp[i+1][s+a[i]][l+1]=min(dp[i+1][s+a[i]][l+1],dp[i][s][l]+max(0,a[i]-b[l]));
			}
			if (i-l<k&&ps-s+a[i]<=sc) {
				dp[i+1][s][l]=min(dp[i+1][s][l],dp[i][s][l]+max(0,a[i]-c[i-l]));				
			}
		}
		ps+=a[i];
	}
	if (ans<=(1<<20)) printf("%d\n",ans); else puts("-1");
}


Measured memory_bytes: 54496
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define PII pair<int,int>
#define VS vector<string>
#define VI vector<int>
#define ll long long
#define ull unsigned long long
#define FST first
#define SEC second
int main(){
  int a[50],b[50],c[50],d[50];
  int n,m;
  cin>>n>>m;
  REP(i,n)cin>>a[i]>>b[i];
  REP(i,m)cin>>c[i]>>d[i];
  REP(i,n){
    int s=1e9,t=-1;
    REP(j,m){
      int l=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(l<s){
        s=l;t=j;
      }
    }
    cout<<t+1<<endl;
  }
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(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()
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 ll mod = 1000000007;
const ll inf = 1LL << 60;

int main(){
  ll n, m;
  cin >> n >> m;
  vvll graph(n);
  rep(i, 0, m){
    ll a, b;
    cin >> a >> b;
    a--; b--;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
  }

  vll v(n);
  iota(all(v), 0);
  ll ans = 0;
  do{
    ll check = true;
    rep(i, 0, n - 1) if(find(all(graph.at(v.at(i + 1))), v.at(i)) == graph.at(v.at(i + 1)).end()) check = false;
    if(check) ans++;
  }while(next_permutation(v.begin() + 1, v.end()));
  cout << ans << endl;
}

Measured memory_bytes: 256
import math
a,b=[int(s) for s in input().split(" ")]

b2=b
count=0
for i in range(3):
    b2=b2//10
    count+=1
    if b2==0:
        break
Prob=(10**(count))*a+b
Ans=math.sqrt(Prob)
print("Yes" if int(Ans)==Ans else "No")

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

const double pi = acos(-1);

int main() {
  int len, ang;
  double ax = 0, ay = 0;
  double vis = 90;

  while(scanf("%d,%d", &len, &ang)) {
    if(len+ang == 0) break;

    ax += len * cos(pi*vis/180);
    ay += len * sin(pi*vis/180);
    vis -= ang; 
  }

  cout << (int)ax << endl;
  cout << (int)ay << endl;
}

Measured memory_bytes: 1212
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
using namespace std;

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


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j,ii,jj;
  ll result=0,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n;cin>>n;
  for(i=1;i*i<=n;i++);
  cout<<(i-1)*(i-1)<<endl;


  return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18



int main() {
	
	while (1) {
		string s; cin >> s;

		if (s == "0")break;

		int sum = 0;

		for (char c : s) {
			sum += (c - '0');
		}

		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 3164
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N;
int V[100], C[100];

int main()
{
  scanf( "%d", &N );
  rep( i, N )
    scanf( "%d", V+i );
  rep( i, N )
    scanf( "%d", C+i );

  int ans = 0;

  rep( i, 1<<N )
  {
    int cnt = 0;

    rep( j, N ) if( i >> j & 1 )
      cnt += V[j]-C[j];

    ans = std::max( ans, cnt );
  }

  printf( "%d\n", ans );

  return 0;
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  ll a, b, n;
  cin >> a >> b >> n;

  ll ans = min(n, b - 1);
  cout << a * ans / b - a * (ans / b) << endl;
}


Measured memory_bytes: 3576
#include"bits/stdc++.h"

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

using namespace std;

int main(void) {
	string S; cin >> S;
	S.erase(S.length() - 1);

	while (S.substr(0, S.length() / 2) != S.substr(S.length() / 2, S.length() - 1)) {
		S.erase(S.length() - 1);
	}

	cout << S.length() << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import deque

h, w = map(int, input().split())
c = [input() for _ in range(h)]
ans = -1

def bfs(sx, sy):
    que = deque([[sy, sx]])
    d = [[-1] * w for _ in range(h)]
    d[sy][sx] = 0
    res = 0
    while que:
        y, x = que.popleft()
        res = max(res, d[y][x])
        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            nx, ny = x+i, y+j
            if 0 <= nx and nx < w and 0 <= ny and ny < h and d[ny][nx] == -1 and c[ny][nx] != "#":
                nx_, ny_ = nx-i, ny-j
                d[ny][nx] = d[ny_][nx_] + 1
                que.append([ny, nx])
    return res

for i_ in range(h):
    for j_ in range(w):
        if c[i_][j_] != "#":
            ans = max(ans, bfs( j_, i_))

print(ans)

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

int main() {
	int n;
	int h[20];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int ans=1;
	for (int i = 1; i < n; i++) {
		int count = 0;
		for (int j = i-1; j >= 0; j--) {
			if (h[i] - h[j] >= 0)count++;
          else{
            count=0;
            break;
          }
		}
		if (count >0 )ans++;
	}
		cout << ans << endl;
	return 0;
}


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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    n,m,k = LI()
    d = LI_()
    v = [LI_() for _ in range(n)]
    dd = collections.defaultdict(lambda: None)
    for i in range(m):
        dd[d[i]] = i
    ii = [2**_ for _ in range(m)]
    vv = [[ii[dd[v[c][i]]] if not dd[v[c][i]] is None else 0  for c in d] for i in range(k)]
    m2 = 2**m
    u = [None] * m2
    u[-1] = 1
    q = [m2-1]
    r = 0
    while q:
        r += 1
        nq = []
        for qd in q:
            qdi = [di for di in range(m) if qd & ii[di]]
            for vi in range(k):
                t = 0
                vvi = vv[vi]
                for di in qdi:
                    t |= vvi[di]
                if not u[t] is None:
                    continue
                if t == 0:
                    return r
                u[t] = 1
                nq.append(t)
        q = nq

    return -1



print(main())



Measured memory_bytes: 11340
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int cnt = 0;
	set<int> s;
	for(int i=1,val;i<=n;i++) {
		cin >> val;
		if(s.count(val) == 1)	cnt++;	
		s.insert(val);
	}
	int ans = (int)s.size();
	while(cnt >= 3)		cnt -= 2;
	if(cnt == 1)	ans--;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h1,m1,h2,m2,k; cin >> h1 >> m1 >> h2>>m2>>k;
  int min = (h2-h1)*60 + (m2-m1) - k;
  cout << min << endl;
}

Measured memory_bytes: 3636
import math
n = int(input())
a = input().split()
a = list(map(int,a))

a.sort()

q = int(a[-1])

a.pop(-1)

max_p = 0
index = 0
for i in range(len(a)):
	p = min(a[i],(q-a[i]))
	if(max_p<p):
		max_p = int(p)
		index = i

print(q,a[index])

Measured memory_bytes: 14180
#include "bits/stdc++.h"
#include <random>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int D;

int c[27];
int s[366][27];
int last[27];

vector<int> ans;
ll ans_score;

ll calcScore(){
    rep(i,27) last[i] = 0;
    ll score = 0;
    for(int d = 1; d <= D; ++d){
        int t = ans[d];
        score += s[d][t];
        last[t] = d;
        for(int i = 1; i <= 26; ++i){
            score -= c[i] * (d - last[i]);
        }
    }
    return score;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> D;
    for(int i = 1; i <= 26; ++i) cin >> c[i];
    for(int i = 1; i <= D; ++i){
        for(int j = 1; j <= 26; ++j){
            cin >> s[i][j];
        }
    }
    ans.resize(D, 1);
    ans_score = calcScore();
    //local search
    std::random_device rnd;
    std:: mt19937 mt(rnd());
    std::uniform_int_distribution<> randD(1,D);
    std::uniform_int_distribution<> randA(1,26);
    rep(_,200000){
        int d = randD(mt);
        int q = randA(mt);
        int old = ans[d];
        ans[d] = q;
        ll score = calcScore();
        if(ans_score > score) ans[d] = old;
        else ans_score = score;
    }
    rep(i,D) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    string s, t;
    cin >> s >> t;
    for(int i = s.size()-t.size(); i >=0 ; i--){
        bool flag = true;
        for(int j = 0; j < t.size(); j++){
            int now = i + j;
            if(s[now] == '?') continue;
            if(s[now] != t[j]){
                flag = false;
                break;
            }
        }
        if(flag){
            rep(k,t.size()){
                s[i+k] = t[k];
            }
            rep(k,s.size()){
                if(s[k]=='?') cout << 'a';
                else cout << s[k];
            }
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
    
}

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

int main() {
	string A, B, C;
	cin >> A >> B >> C;
	if ((A[A.size() - 1] == B[0]) && (B[B.size() - 1] == C[0])) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3616