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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

char ch;
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n; cin >> n;
    vii s(n, vi(n));
    vii graph(n);
    rep(i,n) rep(j,n) {
        cin >> ch;
        s[i][j] = (int)(ch-'0');
        if(s[i][j]) {
            graph[i].push_back(j);
            graph[j].push_back(i);
        }
    }

    // 2部グラフ判定
    bool can = 1;
    vi typ(n);
    queue<i32> que;
    typ[0] = 1;
    que.push(0);
    while(que.size()) {
        i32 u = que.front(); que.pop();
        i32 next_typ = (typ[u]==1 ? 2 : 1);
        for(auto v : graph[u]) {
            if(typ[v] == 0) {
                typ[v] = next_typ;
                que.push(v);
            }
            else if(typ[v] == typ[u]) can = 0;
        }
    }

    if(!can) {
        cout << -1 << '\n';
        return 0;
    }

    // calc diameter with Warshall_Floyd
    vii dist(n, vi(n, inf));
    rep(i,n)rep(j,n) if(s[i][j] == 1) dist[i][j] = 1;

    rep(k,n)rep(i,n)rep(j,n) {
        if(dist[i][k] == inf) continue;
        if(dist[k][j] == inf) continue;
        chmin(dist[i][j], dist[i][k]+dist[k][j]);
    }

    i32 ans = 0;
    for(int i = 0; i < n-1; ++i) {
        for(int j = i + 1; j < n; ++j) {
            if(dist[i][j] == inf) continue;
            chmax(ans, dist[i][j]);
        }
    }

    cout << ans+1 << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};


int main() {
    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, 0, m) {
        ll x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        uf.merge(x, y);
    }
    set<ll> se;
    rep(i, 0, n) se.insert(uf.root(i));

    cout << se.size() << endl;
}

Measured memory_bytes: 5376
using System;

class A{
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    int temp = 0;
    string isthis = "No";
    int[] inp = new int[2];
    for (int i = 0; i < N; i++){
      inp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
      if (inp[0] == inp[1]){
        temp += 1;
      }
      else temp = 0;
      if (temp >= 3) {
        isthis = "Yes";
        break;
      }
      
    }
    Console.WriteLine(isthis);
  }
}

Measured memory_bytes: 27484
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int K, X;
    cin >> K >> X;
    for(int i=X-K+1; i<K+X; ++i){
        if(i==K+X-1){
            cout << i;
        }
        else cout << i << " ";
    }
    return 0;

}


Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int l = sc.nextInt();
        int r = sc.nextInt();
        int d = sc.nextInt();

        int ans = 0;
        for (int i = l; i <= r; i++) {
            if (i % d == 0)
                ans++;
        }

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


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

int main(){
    double a,b,c,d,e,f,x,y;
    while(cin >> a >> b >> c >> d >> e >> f){
        double detA;
        detA = a * e - b * d;
        x = (c * e - f * b) / detA;
        y = (a * f - c * d) / detA;
        cout << fixed << setprecision(3) << x + 0.0001 << " " << setprecision(3) << y + 0.0001 << '\n';
    }
}

Measured memory_bytes: 3256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		long x = long.Parse(Console.ReadLine());//long.Parseはstringをlongに変換。
    Console.WriteLine((x==3||x==5||x==7) ? "YES" : "NO");
	}
}

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

int abs(int x) {
  if(x < 0) x *= -1;
  return x;
}

int main() {
  int game = 1;
  while(1) {
    string str;
    getline(cin, str);
    if(str == "0") break;

    int A = 0;
    int B = 0;
    for(int i = 1; i < str.length(); i++) {
      if(str[i] == 'A') A++;
      else if(str[i] == 'B') B++;
    }

    A++;
    if((A >= 11 || B >= 11) && abs(A-B) >= 2) {
    } else {
      A--;
      B++;
    }
    cout << A << ' ' << B << endl;

    game++;
  }
  return 0;
}

Measured memory_bytes: 0
S = input()
L = len(S)
if S[0] == ">":
    S = "<"+S
else:
    S = ">"+S
if S[L] == ">":
    S = S+"<"
else:
    S = S+">"
count = 0
ans = 0
kari = 0
for i in range(L+1):
    if S[i] == "<" and S[i+1] == ">":
        kari = count
        count = 1
    elif S[i] == ">" and S[i+1] == "<":
        ans += max(kari, count)
        count = 1
    else:
        ans += count
        count += 1

if S[L] == "<" and S[L+1] == ">":
    ans += kari
print(ans)


Measured memory_bytes: 9912
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int ans = 0;
    int s = 1;
    while( s < m )
    {
        s += n - 1;
        ans ++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long N, long long K, std::vector<long long> A) {
  vector<ll> v(N + 1);
  vector<ll> B(N);
  REP(i, K) {
    REP(j, N) {
      v[max(0ll, -A[j] + j)] += 1;
      v[min(N, +A[j] + j + 1)] -= 1;
    }
    ll cur = 0;
    REP(j, N) {
      cur += v[j];
      B[j] = cur;
    }
    bool same = true;
    REP(j, N) {
      if (A[j] != B[j]) {
        same = false;
      }
    }
    A.swap(B);
    if (same) {
      break;
    }
    fill(ALL(v), 0);
  }
  REP(i, N) { cout << A[i] << " "; }
  cout << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}


Measured memory_bytes: 8036
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#pragma endregion

long double calc_eucdist(pair<long double, long double> a, pair<long double, long double> b){
    return sqrt(pow((a.first-b.first), 2)+pow((a.second-b.second), 2));
}

int main(){
    int n;
    cin >> n;
    vector<pair<long double, long double>> towns(n);
    REP(i, n) cin >> towns[i].first >> towns[i].second;

    vector<int> idx(n);
    iota(ALL(idx), 0);

    long double ans=0;
    do {
        long double dist=0;
        REP(i, n-1) dist += hypot(towns[idx[i]].first-towns[idx[i+1]].first, towns[idx[i]].second-towns[idx[i+1]].second);
        ans += dist;
    } while (next_permutation(ALL(idx)));

    FORS(i, 2, n) ans/=i;

    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}

Measured memory_bytes: 384
//
//  main.cpp
//  1
//
//  Created by RISHAV SINGH MEHTA on 01/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <set>
#define ll long long
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,N,M,a,b,c;
    
    cin>>N;
    if (N%2==0) {
        cout<<N/2;
    }else{
        cout<<N/2+1;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(){
    string str;
    cin>>str;
    int sum=0;
    for(int i=0;i<str.size();++i){
        sum+=str[i]-'0';
    }
    if(sum%9) cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 3720
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<algorithm>
using namespace std;

char ch(int a){
	if(a=='A')
		return 10;
	if(a=='B')
		return 11;
	if(a=='C')
		return 12;
	if(a=='D')
		return 13;
	if(a=='E')
		return 14;
	if(a=='F')
		return 15;
}

long long scf_16(int a){
	long long sum=1;
	for(int i=1;i<=a;i++)
		sum*=16;
	return sum;
}

long long z_16_10(string s){					//十六进制转十进制 
	long long jz_16=0;
	int sum=-1;
	for(int i=s.size()-1;i>=0;i--){
		sum++;
		if(s[i]>=0&&s[i]<='9'){
			jz_16+=(s[i]-48)*scf_16(sum);
		}
		else{
			int b=ch(s[i]);
			jz_16+=b*scf_16(sum);
		}
	}
	return jz_16;
}

int main(){
	string A,B;
	cin>>A>>B;
	int a=z_16_10(A),b=z_16_10(B);
	//cout<<a<<' '<<b<<endl;
	if(a>b)
		cout<<">";
	else
		if(a<b)
			cout<<"<";
		else
			cout<<"=";
	return 0;
}

Measured memory_bytes: 256
import numpy as np
n,k = map(int,input().split())

a = np.array([0]*n,dtype ='int64')
a[0] += n
for i in range(1,n):
    c = n // (1+i)
    d = n % (1+i)
    a[1:i+1] += c
    a[0] +=c
    if d > 0:
        a[1:d+1] +=1
print(np.sum(a[k:]))


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

int main() {
  ll sum=0;
  int x,y,a,b,c;
  cin>>x >> y >> a >> b >> c;
  vector<ll> v1(a+1),v2(b+1),v3(c);
  v1[0]=v2[0]=1000000001;
  r(i,a)cin>>v1[i+1];
  r(i,b)cin>>v2[i+1];
  r(i,c)cin>>v3[i];
  sort(v1.begin(),v1.end());
  sort(v2.begin(),v2.end());
  sort(v3.begin(),v3.end());
  reverse(v1.begin(),v1.end());
  reverse(v2.begin(),v2.end());
  reverse(v3.begin(),v3.end());
  int shikiri1=x,shikiri2=y,shikiri3=0;
  while(1){
    if(v1[shikiri1]>=v3[shikiri3]&&v2[shikiri2]>=v3[shikiri3])break;
    else{
      if(v1[shikiri1]<=v2[shikiri2]){
        shikiri1--;
        shikiri3++;
      }
        else{
          shikiri2--;
          shikiri3++;
        }
    }
  }
  r(i,shikiri1)sum+=v1[i+1];
  r(i,shikiri2)sum+=v2[i+1];
  r(i,shikiri3)sum+=v3[i];
  cout<<sum<<endl;
}

Measured memory_bytes: 2560
N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
s = A1.pop(0)
g = A2.pop(-1)
sum_ = s + g
for i in range(N-1):
  for j in range(i+1,N):
    l1 = [A1[k] for k in range(i,j)]
    l2 = [A2[k] for k in range(i,j)]
    if sum(l1) > sum(l2):
      sum_ += A1[i]
      break
    elif j == N-1:
      sum_ += sum(l2)
      print(sum_)
      exit()
print(sum_)

Measured memory_bytes: 3064
n=int(input())
h=list(map(int,input().split()))
ans=0
cnt=0
prev=0
for i in range(n):
    if h[i]<=prev:
        cnt+=1
    else:
        ans=max(ans,cnt)
        cnt=0
    prev=h[i]
ans=max(ans,cnt)
print(ans)

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

long long N, K;
vector<long long> V;

int main(){
	cin >> N >> K;
	for(long long i = 0; i < N; i++){
		long long v;
		cin >> v;
		V.push_back(v);
	}

	long long ans = 0;
	for(long long left = 0; left <= min(K, N); left++){
		for(long long right = 0; right <= min(K-left, N-left); right++){
			long long rest = K - left - right;
			vector<long long> have;

			for(long long i = 0; i < left; i++){
				have.push_back(V[i]);
			}
			for(long long i = 0; i < right; i++){
				have.push_back(V[V.size() - 1 - i]);
			}
			sort(have.begin(), have.end());

			long long tmp = 0;
			for(long long i = 0; i < have.size(); i++){
				if(have[i] >= 0 || i >= rest){
					tmp += have[i];
				}
			}
			ans = max(ans, tmp);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
s=input()
a=int(s[0:2])
b=int(s[2:4])
if 1<=a<=12 and 1<=b<=12:
    print('AMBIGUOUS')
elif 1<=a<=12 and not 1<=b<=12:
    print('MMYY')
elif not 1<=a<=12 and 1<=b<=12:
    print('YYMM')
elif not 1<=a<=12 and not 1<=b<=12:
    print('NA')



Measured memory_bytes: 38384
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;
import java.lang.Object;
 
public class Main {
    Scanner sc = new Scanner(System.in);
   
    public static void main(String[] args) {
        new Main(); 
    }
   
    public Main() {
        new C().doIt();
    }
    class C{
    	long dp_table(int num[],int max,int ans,int cnt){
    		long dp[][] = new long[51][2501];
    		long result = 0;
    		for(int i = 0;i < max;i++){
    			dp[i][num[i]]++;
    			if(num[i] == ans)result++;
    		}
    		for(int i = 0;i < max - 1;i++){
    			long dp2[][] = new long[51][2501];
    			ans = ans + cnt;
    			for(int l = i;l < max - 1;l++){
    			for(int j = 0;j < 50*(l+1) + 1;j++){
    				for(int k = l + 1;k < max;k++){
    					dp2[k][j + num[k]] = dp[l][j] + dp2[k][j + num[k]];
    				}
    			}
    			}
    			for(int j = i+1;j < max;j++){
        			for(int k = 0;k < 2501;k++){
        				dp[j][k] = dp2[j][k];
        				if(k == ans){
        					result = result + dp[j][k];
        				}
        			}
        		}
//    			for(int j = i+1;j < max;j++){
//        			for(int k = 0;k < 40;k++){
//        				System.out.print(dp[j][k]+" ");
//        			}
//        			System.out.println();
//    			}
//    			System.out.println(result+" "+ans+" "+max+" "+i);
    		}
    		return result;
    	}
    	void doIt(){
    		int n = sc.nextInt();
    		int ans = sc.nextInt();
    		int num[] = new int[n];
    		for(int i = 0;i < n;i++){
    			num[i] = sc.nextInt();
    		}
    		long sum = 0;
    		sum = dp_table(num,n,ans,ans);
    		System.out.println(sum);
    	}
    }
}

Measured memory_bytes: 19636
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<vector<int>> g(n, vector<int>());
    int a, b;
    REP(i, n - 1) {
        cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    vector<int> c(n);
    int p, x;
    while (q--) {
        cin >> p >> x;
        p--;
        c[p] += x;
    }

    function<void(int, int)> dfs = [&](int cur, int par) {
        if (par != -1) {
            c[cur] += c[par];
            if (sz(g[cur]) == 1) return;
        }
                    
        for (int nxt : g[cur]) {
            if (nxt == par) continue;
            dfs(nxt, cur);
        }
    };
    dfs(0, -1);
    REP(i, n) cout << c[i] << (i == n - 1 ? endl : ' ');
}



Measured memory_bytes: 26624
n = int(input())
a = [int(v) for v in input().split()]

cnt_plus = 0
cnt_minus = 0
cnt_zero = 0
for i in range(n):
    a[i] -= i + 1
    if a[i] == 0:
        cnt_zero += 1
    elif a[i] > 0:
        cnt_plus += 1
    else:
        cnt_minus += 1

ans = 0
if cnt_plus <= (cnt_minus + cnt_zero) and cnt_minus <= (cnt_plus + cnt_zero):
    for v in a:
        ans += abs(v)
elif cnt_plus > (cnt_minus + cnt_zero):
    c = [v for v in a if v > 0]
    c.sort()
    b = c[(cnt_plus - (cnt_minus + cnt_zero) - 1) // 2]
    for v in a:
        ans += abs(v - b)
else:
    c = [v for v in a if v < 0]
    c.sort(reverse=True)
    b = c[(cnt_minus - (cnt_plus + cnt_zero) - 1) // 2]
    for v in a:
        ans += abs(v - b)

print(ans)

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

int main() {
    vector<string> s(3);
    for (int i = 0; i < 3; i++)
        cin >> s[i];
    int pos[3] = {0};
    int cur = 0;
    while (true) {
        if (pos[cur] == s[cur].size()) {
            cout << (char)('A' + cur) << endl;
            return 0;
        }
        cur = s[cur][pos[cur]++] - 'a';
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>

#define MAX_N 20001

using namespace std;

uint64_t N,M,K,A[MAX_N],T[MAX_N];

uint64_t min(uint64_t a,uint64_t b)
{
	if(a < b)
		return a;
	else
		return b;
}

uint64_t max(uint64_t a,uint64_t b)
{
	if(a > b)
		return a;
	else
		return b;
}
int prev_end_min,prev_begin_min,prev_end_max,prev_begin_max,prev_min,prev_max;
uint64_t getmin(int begin,int end)
{
	if(prev_end_min == end && prev_begin_min == begin + 1)
	{
		if(prev_min > A[begin])
		{
			prev_min = A[begin];
		}
		prev_begin_min = begin;
		return prev_min;
	}
	else
	{
		uint64_t res = UINT64_MAX;
		for(int i = begin;i <= end;i++)
			res = min(res,A[i]);
		prev_begin_min = begin;
		prev_end_min = end;
		prev_min = res;
		return res;
	}
}

uint64_t getmax(int begin,int end)
{
	if(prev_end_max == end && prev_begin_max == begin + 1)
	{
		if(prev_max < A[begin])
		{
			prev_max = A[begin];
		}
		prev_begin_max = begin;
		return prev_max;
	}
	else
	{
		uint64_t res = 0;
		for(int i = begin;i <= end;i++)
			res = max(res,A[i]);
		prev_begin_max = begin;
		prev_end_max = end;
		prev_max = res;
		return res;
	}
}

int main(void)
{
	cin >> N >> M >> K;
	for(int i = 0;i < MAX_N;i++)
	{
		T[i] = UINT64_MAX;
	}
	for(int i = 0;i < N;i++)
	{
		cin >> A[i];
	}
	T[N] = 0;
	for(int i = N-1;i >= 0;i--)
	{
		for(int k = 1;k <= M && (i + k) <= N ;k++)
		{
			uint64_t cost = K + (k * (getmax(N-(i+k),(N-i)-1) - getmin(N-(i+k),(N-i)-1)));
			T[i] = min(T[i],T[i+k]+cost);
		}
	}
	cout << T[0] << endl;
}

Measured memory_bytes: 3396
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back


int MOD=1000000007;
int H,W,K;
char M[305][305];
int stb[305];
int ans[305][305];
int S[200005];
signed main(){
    scanf("%lld %lld %lld",&H,&W,&K);
    int firststraw=H;
    rep(i,H){
        stb[i]=W;
        rep(j,W){
            char m='c';
            while(m!='#'&&m!='.'){
                scanf("%c",&m);
                M[i][j]=m;
                if(m=='#'){
                    stb[i]=min(stb[i],j);
                    firststraw=min(firststraw,i);
                }
            }
        }
    }
    int counter=1;
    rep(i,H){
        rep(j,W){
            if(i<firststraw){//いちごなし
            //保留
            }else if(stb[i]==W){//いちごなし
                ans[i][j]=ans[i-1][j];
            }else{
                if(M[i][j]=='#'){
                    ans[i][j]=counter;
                    counter++;
                }else{
                    if(j<stb[i]){
                        ans[i][j]=counter;
                    }else{
                        ans[i][j]=counter-1;
                    }
                }
            }

        }
    }
    rep(i,firststraw){
        rep(j,W){
            ans[i][j]=ans[firststraw][j];
        }
    }
    rep(i,H){
        rep(j,W){
            printf("%lld",ans[i][j]);
            if(j!=W-1)printf(" ");
        }
        printf("\n");
    }
    
    return 0;
}


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

const int M = (int)2e5;

int a[M + 5];

int main()
{
    int k, n; scanf("%d %d", &k, &n);
    for(int i = 0; i < n; ++i)  scanf("%d", &a[i]);
    int mx = k - a[n - 1] + a[0]; for(int i = 1; i < n; ++i)    mx = max(mx, a[i] - a[i - 1]);
    printf("%d\n", k - mx);
    return 0;
}


Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    a11, a12, a13 = LI()
    a21, a22, a23 = LI()
    a31, a32, a33 = LI()
    n = I()
    b = IR(n)
    if a11 in b and a12 in b and a13 in b:
        print('Yes')
    elif a21 in b and a22 in b and a23 in b:
        print('Yes')
    elif a31 in b and a32 in b and a33 in b:
        print('Yes')
    elif a11 in b and a21 in b and a31 in b:
        print('Yes')
    elif a12 in b and a22 in b and a32 in b:
        print('Yes')
    elif a13 in b and a23 in b and a33 in b:
        print('Yes')
    elif a11 in b and a22 in b and a33 in b:
        print('Yes')
    elif a13 in b and a22 in b and a31 in b:
        print('Yes')
    else:
        print('No')
    return


# Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define rep(i,strt,end) for(long long i = strt;i < end;i++)


int main(){
    long long x,n;
    cin >> x >> n;
    long long p[n+1];
    map<long long,long long> amt;
    long long maxVl = 101;
    rep(i,1,n+1){
        cin >> p[i];
        amt[p[i]]++;
    }
    long long result = 1000;
    long long rsltpos = 0;
    rep(i,-200,300){
        if(0 == amt[i]){
            if(abs(x-i) < result){
                result = abs(x-i);
                rsltpos = i;
            }
        }
    }
    cout << rsltpos << endl;
    //--------------
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>

#define lli long long int
#define ld long double
#define endl "\n"

using namespace std;

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

	#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("D:\\My Folder\\Programming\\[code] Competetive Programming\\input.txt", "r", stdin);
	// for writing the output to output.txt
	freopen("D:\\My Folder\\Programming\\[code] Competetive Programming\\output.txt", "w", stdout);
	#endif

	string s;
	cin>>s;

	if (s[(s.size())-1] == 's') cout<<s<<"es";
	else cout<<s<<"s";

	return 0;
}

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

int main(void) {
    int n;
    cin >> n;
    
    int which_joushi[n - 1];
    
    int joushies[n];
    
    for (int i = 0; i < n; i++) {
        joushies[i] = 0;
    }
    
    for (int i = 0; i < n - 1; i++) {
        cin >> which_joushi[i];
    }
    
    for (int j = 0; j < n - 1 ; j++) {
        joushies[which_joushi[j] - 1]++;
    }
    
    for (int k = 0; k < n; k++) {
        cout << joushies[k] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 5216
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	vi isprime(1000001,1);
	isprime[0]=isprime[1]=0;
	repi(i,2,isprime.size())
		if(isprime[i])
			for(int j=i+i;j<isprime.size();j+=i)
				isprime[j]=0;
	for(int n,x;cin>>n>>x,n|x;){
		vi price(n);
		rep(i,n)
			cin>>price[i];
		vi dp(x+1);
		dp[0]=1;
		rep(i,n)
			repi(j,price[i],dp.size())
				if(dp[j-price[i]])
					dp[j]=1;
		bool flg=false;
		rep(i,dp.size())
			if(dp[x-i] && isprime[x-i]){
				printf("%d\n",x-i);
				flg=true;
				break;
			}
		if(!flg)
			puts("NA");
	}
	
	return 0;
}

Measured memory_bytes: 9116
# 定数
INF = float("inf")
MOD = int(1e9 + 7)

import math

def comb(a, b):
	return math.factorial(a) // math.factorial(a - b) // (math.factorial(b))

N, K = map(int, input().split())

num_blue = K
num_red = N - K

for k in range(1, K + 1):
	if num_red + 1 < k:
		print(0)
		continue
	comb_blue = comb(num_blue - 1, k - 1)
	comb_red = comb(num_red + 1, k)
	print((comb_blue * comb_red) % MOD)


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

int main() {
  
  string s;
  
  cin >> s;
  int n=s.size();
  int m=0;
  int r=0;
  for(int i=0;i<n;i++){
    if(s.at(i)=='A'|| s.at(i)=='T' || s.at(i) == 'C' || s.at(i) == 'G') {
       m++;
	   r=max(r,m);
	}   
	else m=0;
  
  }		
  
  cout << r << endl;
  
}


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

#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
int n;
vector<vector<int>>d;
void floyd() {
	rep(k, 0, n) {
		rep(i, 0, n) {
			if (d[i][k] == INF)continue;
			rep(j, 0, n) {
				if (d[k][j] == INF)continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}
signed main() {
	int e, u, v, c;
	cin >> n >> e;
	d = vector<vector<int>>(n, vector<int>(n, INF));
	rep(i, 0, n)d[i][i] = 0;
	rep(i, 0, e) {
		cin >> u >> v >> c;
		d[u][v] = c;
	}
	floyd();
	bool negative = false;
	rep(i, 0, n)if (d[i][i] < 0)negative = true;
	if (negative) {
		cout << "NEGATIVE CYCLE" << endl;
	}
	else {
		rep(i, 0, n) {
			rep(j, 0, n) {
				if (j)cout << " ";
				if (d[i][j] == INF)cout << "INF";
				else cout << d[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3232
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

string s;

int main() {
    fast_io; cout_precision;
    cin >> s;
    cout << (((s.length() & 1) ^ (s.front() != s.back())) ? "Second" : "First") << endl;
}

Measured memory_bytes: 512
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

using ld = long double;

int main() {
    ll N;
    cin >> N;
    V<pair<ld, ld>> vtx(N);
    for (auto &&e : vtx) cin >> e.first >> e.second;

    auto pow2 = [](ld x) { return x * x; };

    auto dist2 = [&](ld x, ld y, ll i) {
        ld vx, vy;
        tie(vx, vy) = vtx[i];
        return pow2(x - vx) + pow2(y - vy);
    };

    ld maxx = 1000, minx = 0;
    ld ans = 5e15;
    for (ll lx = 0; lx < 300; lx++) {
        ld x1 = (minx * 2 + maxx) / 3;
        ld x2 = (minx + maxx * 2) / 3;

        auto calc = [&](ld x) {
            ld maxy = 1000, miny = 0;
            ld xans = 5e15;
            for (ll ly = 0; ly < 300; ly++) {
                ld y1 = (miny * 2 + maxy) / 3;
                ld y2 = (miny + maxy * 2) / 3;
                ld ans1 = 0, ans2 = 0;
                for (ll i = 0; i < N; i++) {
                    chmax(ans1, dist2(x, y1, i));
                    chmax(ans2, dist2(x, y2, i));
                }
                if (ans1 < ans2) maxy = y2;
                else miny = y1;
                chmin(xans, ans1, ans2);
            }
            return xans;
        };

        ld ans1 = calc(x1), ans2 = calc(x2);
        if (ans1 < ans2) maxx = x2;
        else minx = x1;
        chmin(ans, ans1, ans2);
    }

    cout << sqrt(ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const int INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
int x[10003],y[10003];
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
map<int,int>q;
int main()
{

int n;
cin>>n;
int x,y;x=y=0;
for(int i=1;i<=n;i++)
{
    int a;
    cin>>a;
    q[a]++;
    if(q[a]>=2)
    {
        if(x==0)x=a;
        else if(y==0){
           y=a;
        }
        else {
            if(x<a)
                q[a]-=2,x=a;
        }
        if(x&&y&&x>y)swap(x,y);
    }
}
cout<<(ll)x*y;
}



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

using namespace std;

int main()
{
    long long int i,x,y,m=0,n,a,b;
    cin >> n >> a >>b;
    cin >> x;
    for(i=2;i<=n;i++)
    {
        cin >> y;
        if(a*(y-x)>b)
        {
            m+=b;
        }
        else
        {
            m+=a*(y-x);
        }
        x=y;
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 384
function main(_stdin) {
    const stdin = _stdin.split('\n');
    const len = Number(stdin.shift());
    const arr = stdin.shift().split(' ').map(Number);

    let count = 0;
    let sorted = 0;
    let flag =  1;
    while (flag) {
        flag = 0;

        for (let i = len - 1; i > sorted; i--) {
            if (arr[i] < arr[i - 1]) {
                const t = arr[i];
                arr[i] = arr[i - 1];
                arr[i - 1] = t;
                flag = 1;
                count++;
            }
        }
        sorted++;
    }
    console.log(arr.join(' '));
    console.log(count);
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 15408
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main{

public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        StringBuilder sb=new StringBuilder();
       int n=s.nextInt();
       int[] arr=new int[n];
       for(int i=0;i<n;i++){arr[i]=s.nextInt();}
       	int res=0;
       for(int i=0;i<n;i++){
       	for(int j=i+1;j<n;j++){
       		res+=arr[i]*arr[j];
       	}
       }
       System.out.println(res); 
    }
}
    
  












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

typedef long long int ll;

ll fib[100];

ll solve(ll n){
    if(fib[n] != -1)
        return fib[n];
    else
        return fib[n] = solve(n-1) + solve(n-2);
}

int main() {
    memset(fib, -1, sizeof fib);
    fib[0] = 2;
    fib[1] = 1;
    ll n;
    cin >> n;
    cout << solve(n) << endl;

    return 0;
}


Measured memory_bytes: 256
N=input()
N=int(N)
if N<=3 :
    print('No')
elif N%4 == 0:
    print('Yes')
elif N%7==0 :
    print('Yes')
elif (N-7)%4==0 and N-7>=0:
    print('Yes')
elif (N-14)%4==0 and N-14>=0:
    print('Yes')
elif (N-21)%4==0 and N-21>=0:
    print('Yes')
else :
    print('No')


Measured memory_bytes: 3060
/*input
10 10
10 9 8 7 6 5 4 3 2 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define YY cout<<"YES\n"
#define NN cout<<"NO\n"
#define yy cout<<"Yes\n"
#define nn cout<<"No\n"
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
ll a[maxn];
ll ans=0;
ll dd[maxn],dx[maxn];
ll d=0,x=0;
ll cnt[maxn];

int main()
{
	IOS;
	int n,m;
	cin>>n>>m;
	REP(i,n) cin>>a[i];
	REP(i,n) a[i]--;
	REP(i,n-1){
		int u=a[i],v=a[i+1];
		if(u>v) v+=m;

		ans+=v-u;
		dd[u+1]--;
		dx[v]+=v-u-1;
		dd[v]++;
	}
	//cout<<ans<<'\n';
	//REP(i,m+m) cout<<dd[i]<<" \n"[i==m+m-1];
	//REP(i,m+m) cout<<dx[i]<<" \n"[i==m+m-1];
	REP(i,m+m){
		x+=d;
		cnt[i]=x;
		d+=dd[i];
		x+=dx[i];
	}
	//REP(i,m+m) cout<<cnt[i]<<" \n"[i==m+m-1];
	REP(i,m) cnt[i]+=cnt[i+m];
	cout<<ans+*min_element(cnt,cnt+m)<<'\n';

	return 0;
}


Measured memory_bytes: 7936
mod = 10 ** 9 + 7

def bekizyo(x, n): #べき乗x**n(nが大きいとき)
    n2 = format(n, "b")
    l_n2 = len(n2)
    ass = 1
    y = x
    for i in range(l_n2):
        if n2[l_n2 - 1 - i] == "1":
            ass *= y
            ass %= mod
        y **= 2
        y %= mod
    return ass


n,k = map(int, input().split())

l = [0] * (k+1)

for i in range(k, 0, -1):
    num = bekizyo(k//i, n)
    for j in range(k//i - 1):
        num -= l[i * (j+2)]
        num %= mod
    l[i] = num

ans = 0

for i in range(1, k+1):
    ans += i * l[i]
    ans %= mod

print(ans)

Measured memory_bytes: 70232
n=input()
a=[0 for i in range(n)]
s=raw_input().split()
c2=0
c1=0
c=0
for i in range(n):
    t=int(s[i])
    if t%4==0:
        a[i]=2
        c2+=1
    else:
        if t%2==0:
            a[i]=1
            c1+=1
        else:
            a[i]=0
            c+=1
print "Yes" if (c2>=c) or (c2==c-1 and c1==0) else "No"

Measured memory_bytes: 41124
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int s;
    cin>>s;
    int a = s/500;
    s=s%500;
    int b = s/5;
    cout<<a*1000+b*5<<endl;
    
return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
p = list(map(int, input().split()))
par = [i for i in range(n)]

def root(x):
	tmp = par[x]
	if tmp == x:
		return x
	else:
		a = root(tmp)
		par[x] = a
		return a

def merge(x, y):
	x = root(x)
	y = root(y)
	if x != y:
		par[x] = y
		return

for i in range(m):
	x, y = map(int, input().split())
	merge(x-1, y-1)

ans = 0

for i in range(n):
	if p[i]-1 == i:
		ans += 1
	elif root(p[i]-1) == root(i):
		ans += 1

print(ans)

Measured memory_bytes: 13812
#include <iostream>
#include "string"

using namespace std;


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

		if(s1==".") break;

		string s2;
		cin>>s2;

		if(s1==s2){
			cout<<"IDENTICAL"<<endl;
			continue;
		}

		string t1=s1;
		string t2=s2;

		while (1) {
			size_t d1b=t1.find('\"');
			if(d1b==string::npos) break;
			t1.replace(d1b,1,"@");

			size_t d1e=t1.find('\"');
			t1.replace(d1e,1,"@");

			size_t d2b=t2.find('\"');
			if(d2b==string::npos) break;
			t2.replace(d2b,1,"@");

			size_t d2e=t2.find('\"');
			t2.replace(d2e,1,"@");

			string u1=s1;
			u1.replace(d1b+1,d1e-d1b-1,"");
			string u2=s2;
			u2.replace(d2b+1,d2e-d2b-1,"");

			if (u1==u2) {
				t1=u1;
				t2=u2;
				break;
			}
		}
		if(t1==t2) cout<<"CLOSE"<<endl;
		else cout<<"DIFFERENT"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3180
import java.util.Scanner;


public class Main {

	public static void main(String []args){
		//????????£??????????????£?¨?
		Scanner sc = new Scanner(System.in);
		//??°?????????
		while(true){

			//???????????????
			int H = sc.nextInt();
			//?¨??????????
			int W = sc.nextInt();


		//?????¶??????0????????°??????
		if(H ==0 && W==0){
			break;
		}
		//???????????????
		for(int i =0; i<H;i++){
			for(int j = 0; j<W; j++){
				System.out.print("#");

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

		}
	}
}

Measured memory_bytes: 33252
N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))

maxA=max(A)
countNumber=A.count(maxA)

for i in range(N):
  if A[i]<maxA:
    print(maxA)
  elif countNumber>1:
    print(maxA)
  else:
    B=A[:]
    del B[i]
    print(max(B))


Measured memory_bytes: 14068
mod = 998244353
n, m, k = map(int, input().split())


def modpow(a, n, mod):
    y = 1
    while n:
        if n & 1:
            y = y * a % mod
        a = a * a % mod
        n >>= 1
    return y

MAX = 500000
fac = [0]*MAX
facinv = [0]*MAX
inv = [0]*MAX

def modinv(a, mod):
    b = mod
    x, u = 1, 0
    while b:
        q = a//b
        a, b = b, a-q*b
        x, u = u, x-q*u
    x %= mod
    return x


def mod_nCr_init(n, mod):
    fac[0] = fac[1] = 1
    facinv[0] = facinv[1] = 1
    inv[1] = 1
    for i in range(2, n):
        fac[i] = fac[i-1] * i % mod
        inv[i] = -inv[mod % i] * (mod // i) % mod
        facinv[i] = facinv[i-1] * inv[i] % mod


def mod_nCr(n, r, mod):
    if n < r or n < 0 or r < 0:
        return 0
    return fac[n] * (facinv[r] * facinv[n-r] % mod) % mod


mod_nCr_init(MAX, mod)


ans = 0
for i in range(0, k+1):
    ans += m * modpow(m-1, n-1-i, mod) * mod_nCr(n-1, i, mod)
    ans %= mod

print(ans)


Measured memory_bytes: 68300
N = int(input())
a = list(map(int, input().split()))
left = []
for i in range(N):
    if left:
        if a[i] == left[-1] + 1:
            left.append(a[i])
    else:
        if a[i] == 1:
            left.append(a[i])
if left:
    print(N - len(left))
else:
    print(-1)

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A + B == 3)
    cout << 3 << endl;
  else if (A + B == 4)
    cout << 2 << endl;
  else if (A + B == 5)
    cout << 1 << endl;
}

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

namespace Shuffle
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> results = new List<string>();

            while (true)
            {
                string card = Console.ReadLine();
                if (card.Equals("-"))
                {
                    break;
                }
                int time = int.Parse(Console.ReadLine());
                int times = 0;
                for (int i = 0; i < time; ++i)
                {
                    times += int.Parse(Console.ReadLine());
                }


                int cardSum = 0;
                List<string> cards = new List<string>();
                foreach (char item in card)
                {
                    cards.Add(item.ToString());
                    cardSum++;
                }

                List<string> newCards = new List<string>();

                if (cardSum < times)
                {
                    times = times % cardSum;
                }
    
                for (int i = times; i < cards.Count; ++i)
                {
                    newCards.Add(cards[i]);
                }
                for (int i = 0; i < times; ++i)
                {
                    newCards.Add(cards[i]);
                }

                string result = "";

                foreach (string item in newCards)
                {
                    result += item;
                }
                results.Add(result);
            }

            foreach (string item in results)
            {
                Console.WriteLine(item);
            }
        }
    }
}



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

int n;
int x[8],y[8];

double dist(int i,int j){
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}

int main() {
    cin >> n;
    for(int i=0;i<n;i++) cin >> x[i] >> y[i];
    double ans=0.0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=dist(i,j)*2/n;
        }
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

Measured memory_bytes: 384