akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    vi a(n);
    map<ll, ll> mp;
    ll sum = 0;
    rep(i, n){
        cin >> a[i];
        mp[a[i]]++;
        sum += a[i];
    }

    ll q; cin >> q;
    rep(i, q){
        ll b, c; cin >> b >> c;
        sum = sum - mp[b]*b + mp[b]*c;
        cout << sum << endl;
        mp[c] += mp[b];
        mp[b] = 0;
    }
}

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

int main() {
  long long n,m;
  cin >>n>>m;
  vector<long long>a(n),b(n);
  for(long long i=0;i<n;i++)cin>>a[i]>>b[i];
  vector<long long>c(m),d(m);
  for(int i=0;i<m;i++)cin>>c[i]>>d[i];
  long long kyori=0;
  long long kotae=0;
  rep(i,n){
    kyori=LLONG_MAX;
    rep(j,m){
      long long tmp=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(tmp<kyori){
         kyori=tmp;
        kotae =j+1;
      }
    }
    cout<<kotae<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int H,N,i;
    	cin >> H >> N;
  	vector<int> A(N);
  	string Ans = "Yes";
  	for(i=0;i<N;i++){
  	cin >> A.at(i);
  	}
  for(i=0;i<N;i++){
  H -= A.at(i);
  }
  if(H>0){
  Ans = "No";
  }
  
  
  cout << Ans << endl;
}


Measured memory_bytes: 640
/*
    Author - Param Kothari
    Ah shit, here we go again
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    int n = 0;
    cin >> n;
    vector<int> a(n);
    int suma = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        suma += a[i];
    }
    int p1 = suma / n;
    int p2 = p1 + 1;
    int p3 = p1 - 1, res1 = 0, res2 = 0, res3 = 0;
    for(int i = 0; i < n; i++){
        res1 += ((a[i] - p1) * (a[i] - p1));
    }
    for(int i = 0; i < n; i++){
        res2 += ((a[i] - p2) * (a[i] - p2));    
    }
    for(int i = 0; i < n; i++){
        res3 += ((a[i] - p3) * (a[i] - p3));    
    }
    cout << min(min(res1, res2), res3) << "\n";
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int x, y;
    cin >> x >> y;
    int b = (y - 2 * x) / 2;
    int a = x - b;
//    cout << a << " " << b << endl;
    if(a < 0 || b < 0)return cout << "No", 0;
    if(a + b == x && 2 * a + 4 * b == y)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3552
import java.util.Scanner;

// A - Cookie Exchanges
// https://atcoder.jp/contests/agc014/tasks/agc014_a
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = Integer.parseInt(scanner.next());
        int B = Integer.parseInt(scanner.next());
        int C = Integer.parseInt(scanner.next());
        scanner.nextLine();

        int count = 0;
        while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
            int hA = A / 2;
            int hB = B / 2;
            int hC = C / 2;

            A = hB + hC;
            B = hA + hC;
            C = hA + hB;
            count++;

            if (A == B && B == C) {
                System.out.println("-1");
                return;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 21716
import math

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

lower = 0
upper = max(A)
mid = math.ceil((lower + upper) / 2)
while lower < upper:
    mid = math.ceil((lower + upper) / 2)
    if mid == upper:
        break
    # print(lower, mid, upper)
    cut = 0
    for a in A:
        cut += math.ceil(a / mid) - 1
    if cut <= K:
        upper = mid
    else:
        # K < cut
        lower = mid

print(mid)

Measured memory_bytes: 31008
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int p, q, a, n;

void dfs(int num, int mul, int last, int x, int y, int &ans){
    

    if(x * q == p * y){ 
        ans++;
        return;
    }

    if(p * y < x * q) return;

    if(num == n) return;

    for(int i = last;; i++){
        if(i * mul > a) break;
        int m = i * y;
        int c = y + i * x;

        if(p * m < c * q) continue;
        dfs(num + 1, mul * i, i, c, m, ans);
    }

    return;
}

signed main(){
    
    while(1){
        
        cin >> p >> q >> a >> n;
        if(a == 0) break;
        
        int ans = 0;
        dfs(0, 1, 1, 0, 1, ans);

        cout << ans << endl;
    }

    return 0;
}




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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int N; cin >> N;
    int t = N%10;
    set<int> s1{2,4,5,7,9}, s2{0,1,6,8};
    if(s1.find(t) != s1.end()) cout << "hon" << en;
    else if(s2.find(t) != s2.end()) cout << "pon" << en;
    else cout << "bon" << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t = 1; //cin >> t;
    REP(_,t){
        Main();
    }
    return 0;
}

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

typedef pair<int,int> P;
typedef pair<int,pair<int,int>> PP;
int hs(int w, int h, P p){
	return w - p.first + h - p.second;
}
int main(){
	for(int w,h;;){
		cin>>w>>h;
		if(w+h==0)break;
		vector<vector<vector<P>>> g(w,vector<vector<P>>(h,vector<P>()));
		for(int d,i=1; i<=h; i++){
			for(int j=1; j<w; j++){
				cin>>d;
				if(!d){
					g[j-1][i-1].push_back(P(1,0));
					g[j][i-1].push_back(P(-1,0));
				}
			}
			if(i!=h){
				for(int j=0; j<w; j++){
					cin>>d;
					if(!d){
						g[j][i-1].push_back(P(0,1));
						g[j][i].push_back(P(0,-1));
					}
				}
			}
		}
		vector<vector<int>> d(w,vector<int>(h,INT_MAX));
		priority_queue<PP, vector<PP>, greater<PP>> q;
		q.push(PP(d[0][0]=1,P(0,0)));
		for(;q.size();){
			P now = q.top().second;
			int cost = d[now.first][now.second];
			q.pop();
			for(P v : g[now.first][now.second]){
				v.first += now.first;
				v.second += now.second;
				if(cost+1 < d[v.first][v.second]){
					q.push(PP(hs(h,w,v)+(d[v.first][v.second]=cost+1),v));
				}
			}
		}
		cout<<(d[w-1][h-1] < INT_MAX ? d[w-1][h-1] : 0)<<endl;
	}
}

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

using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#ifdef LL
const ll inf = 1e9;
#else 
const ll inf = 1e18;
#endif

const int mod = 1e9 + 7;
const int mod2 = 998244353;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

high_resolution_clock::time_point curTime() { return high_resolution_clock::now(); }
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);} //Just add this as a third argument to sort() while sorting an array of pairs; NO NEED FOR ANY ARGUMENTS;
template <typename T>
T fact(T a, T mod){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=mod;} return res; }
template <typename T>
ll powmod(T a,T b,ll m){ ll ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
ll power(T a, T b){ ll ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}
template <typename T>
T gcd(T a,T b){ return (b?__gcd(a,b):a); }
template <typename T>
T lcm(T a, T b){ return (a*(b/gcd(a,b))); }
template <typename T>
T cl(T a, T b){ return (a+b-1)/b; }
template <typename T>
T set_bits(T a)
{ return __builtin_popcount(a); }
template <typename T>
T add_self(T& a, T b, T mod){ a+=b; if(a>=mod){ a-=mod; } }
template <typename T>
T to_upper(T s){ transform(s.begin(), s.end(), s.begin(), ::toupper); return s; }
template <typename T>
T to_lower(T s){ transform(s.begin(), s.end(), s.begin(), ::tolower); return s; }



int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    auto startTime = curTime();

    int n,k;
    cin>>n>>k;

    vi a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    vi dp(k+1);
    for(int i=1;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i>=a[j]) dp[i] = !dp[i-a[j]];
            if(dp[i]==1) break;
        }
    }

    cout<<(dp[k]==1? "First" : "Second")<<endl;

    auto stopTime = curTime();
    auto duration = duration_cast<microseconds>(stopTime - startTime);
    //cout<<"Program ran for "<<(ld)duration.count()/1e6<<" "<<"seconds"<<endl;
}


Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
ll const MOD=1000000007;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double a,b,x;
    cin>>a>>b>>x;
    if(a*a*b/2<=x)printf("%.10f\n",atan((2*a*a*b-2*x)/(a*a*a))*45/atan(1));
    else printf("%.10f\n",atan(a*b*b/(2*x))*45/atan(1));
}

Measured memory_bytes: 384
while True:
    n=int(input())
    if n==0:break
    m=int(input())
    s=input()
    count=0
    req=0
    i=0
    while i<m:
        if s[i]=='I':
            i+=1
            while s[i:i+2]=="OI":
                if req==n-1:count+=1
                else:req+=1
                i+=2
            req=0
        else:i+=1
    print(count)

Measured memory_bytes: 9408
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N);
	for (ll i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	ll count = 0;
	ll flag = 0;
	for (ll i = 0; i < N - 1; i++)
	{
		if (i == 0 || flag == 0) {
			if (a[i + 1] > a[i]) {
				flag = 1;
				count++;
			}
			else if (a[i + 1] == a[i]) {
				flag = 0;
			}
			else {
				flag = -1;
				count++;
			}
		}
		else if (flag == 1) {
			if (a[i + 1] < a[i]) {
				flag = 0;
				continue;
			}
		}
		else if (flag == -1) {
			if (a[i + 1] > a[i]) {
				flag = 0;
				continue;
			}
		}
	}
	if (flag == 0) {
		count += 1;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int A11 = scanner.nextInt();
        int A12 = scanner.nextInt();
        int A13 = scanner.nextInt();
        int A21 = scanner.nextInt();
        int A22 = scanner.nextInt();
        int A23 = scanner.nextInt();
        int A31 = scanner.nextInt();
        int A32 = scanner.nextInt();
        int A33 = scanner.nextInt();

        int N = scanner.nextInt();
        Set<Integer> b = new HashSet<>();
        for(int i=0; i<N; i++){
            b.add(scanner.nextInt());
        }

        boolean result = false;
        if(b.contains(A11) && b.contains(A12) && b.contains(A13)){result = true;}
        if(b.contains(A21) && b.contains(A22) && b.contains(A23)){result = true;}
        if(b.contains(A31) && b.contains(A32) && b.contains(A33)){result = true;}
        if(b.contains(A11) && b.contains(A21) && b.contains(A31)){result = true;}
        if(b.contains(A12) && b.contains(A22) && b.contains(A32)){result = true;}
        if(b.contains(A13) && b.contains(A23) && b.contains(A33)){result = true;}
        if(b.contains(A11) && b.contains(A22) && b.contains(A33)){result = true;}
        if(b.contains(A13) && b.contains(A22) && b.contains(A31)){result = true;}

        if(result){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  void solve() {
    int n, k;
    cin >> n >> k;
    map<int, queue<int>> mp;
    mp[0].push(0);
    i64 ans = 0, sum = 0;
    for (int i = 1; i <= n; ++i) {
      int t;
      cin >> t;
      sum += t;
      int v = (sum - i) % k;
      while (mp[v].size() && i - mp[v].front() >= k) {
        mp[v].pop();
      }
      ans += mp[v].size();
      mp[v].push(i);
    }
    cout << ans << '\n';
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 144000
N,Y=map(int,input().split())
A=[]
for i in range(Y//10000+1):
    for j in range((Y-i*10000)//5000+1):
        c1=(Y-10000*i-5000*j)/1000
        c2=N-i-j
        if c1==c2:
            A=[i,j,c1]
            break
        if c1!=c2:
            continue
if len(A)==0:
    print("-1 -1 -1")
else:
    A[2]=int(A[2])
    print(str(A[0])+" "+str(A[1])+" "+str(A[2]))

Measured memory_bytes: 40556
def main():
    n = int(input())
    rain = list(map(int,input().split()))
    mountains = []
    total = 0
    for i in range(1,n+1):
        if i%2 != 0:
            total += rain[i-1]
        else:
            total -= rain[i-1]

    #total += rain[-1]
    a1 = total
    #print(a1)
    mountains.append(a1)
    for i in range(n-1):
        mountains.append((2*rain[i])-mountains[-1])

    for i in mountains:
        print(i,end = ' ')


main()


Measured memory_bytes: 14616
def num2(n: int) -> int:
    """n を素因数分解した時の 2 の指数
    """
    s = 0
    while n % 2 == 0:
        s += 1
        n //= 2
    return s


def multiple3_or_divide2(N: int, A: list) -> int:
    return sum(num2(a) for a in A)


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = multiple3_or_divide2(N, A)
    print(ans)


Measured memory_bytes: 4148
#include<bits/stdc++.h>
using namespace std;
int main(){
  char ch,a;
  cin>>ch;
  switch(ch){
    case 'A':
      a='T';
      break;
    case 'T':
      a='A';
      break;
    case 'C':
      a='G';
      break;
    case 'G':
      a='C';
      break;
  }
  cout<<a;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(void){
  int n, k; 
  long int sum=0;
  scanf("%d", &n);
  scanf("%d", &k);
  int s[n];
  for(int i=0; i<n; i++){
    scanf("%d", &s[i]);
  }
  if(n <= k){
    printf("0");
  }else{
    qsort(s, n, sizeof(int), compare_int);
    for(int m=k;m<n;m++){
      sum += s[m];
    }    
    printf("%ld", sum);
  }
  return 0;
}

Measured memory_bytes: 3028
using System;

namespace ABC124_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int j = 0;
            int k = 0;
            int l = 0;
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);
            j = 2 * a - 1;
            k = a + b;
            l = 2 * b - 1;
            if(a > b)
            {
                Console.WriteLine(j);
            }
            else if(a < b)
            {
                Console.WriteLine(l);
            }
            else
            {
                Console.WriteLine(k);
            }
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> fruit(N);
  
  for(int i = 0; i < N; i++) {
    cin >> fruit.at(i);
  }
  
  sort(fruit.begin(), fruit.end());
  int ans = 0;
  
  for(int i = 0; i < K; i++) {
    ans += fruit.at(i);
  }
  
  cout << ans << endl;
}

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

using namespace std;

int main() {
    int A[3][3], N, B[110];
    
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A[i][j];
        }
    }

    cin >> N;

    for (int i = 0; i < N; i++) cin >> B[i];

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (B[k] == A[i][j]) A[i][j] = 0;
            }
        }
    }
    string result = "No";
    for (int i = 0; i < 3; i++) {
        if ((A[i][0]==A[i][1]&&A[i][1]==A[i][2]&&A[i][2]==0) || A[0][i]==A[1][i]&&A[1][i]==A[2][i]&&A[2][i]==0){
            result = "Yes";
            break;
        } else if ((A[0][0]==A[1][1]&&A[1][1]==A[2][2]&&A[2][2]==0) || (A[2][0]==A[1][1]&&A[1][1]==A[0][2]&&A[0][2]==0)) {
            result = "Yes";
            break;
        }
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
N, X = map(int, input().split())

a, p = [None] * (N + 1), [None] * (N + 1)
a[0], p[0] = 1, 1
for i in range(1, N + 1):
    a[i], p[i] = 2 * a[i - 1] + 3, 2 * p[i - 1] + 1


def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= a[N - 1] + 1:
        return f(N - 1, X - 1)
    else:
        return p[N - 1] + 1 + f(N - 1, X - a[N - 1] - 2)

print(f(N, X))


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

int main() {
  int a,b,c,d,s;
  cin >> a >> b >>c >>d ;
s=a+b-c-d;
  if(s>0){
    cout << "Left" << endl ;
  }
  else if(s<0){
    cout << "Right" << endl ;
  }
  else {
    cout << "Balanced" <<endl ;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
//ちんちん
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String p = sc.next();
        char[] characterS = s.toCharArray();
        char[] characterC = p.toCharArray();
        int i,j,l;
        int count = 0; 
        top: for(i=0;i<s.length();i++){
            for(j=0,l=0;j<p.length();){
                try{
                    if (characterC[j] == characterS[j + i]) {
                        count++;
                    }
                } catch (java.lang.ArrayIndexOutOfBoundsException e) {
                    if (characterC[j] == characterS[l]) {
                        count++;
                        l++;
                    }
                } finally {
                    j++;
                }
            }
            if (count == p.length()) {
                break top;
            } else {
                count = 0;
            }
        }
        if (count == p.length()) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s, ans;
  cin >> s;
  cout << s;
  if (s.back() != 's')
    cout << "s" << endl;
  else
    cout << "es" << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<stdio.h>
#include<cstdio>
#include<math.h>
using namespace std;
int main(){
    string name[9];
    int am[9],pm[9],sum[9],syuunyuu[9];
    for(int i=0;i<9;i++){
        cin>>name[i]>>am[i]>>pm[i];
        sum[i]=am[i]+pm[i];
        syuunyuu[i]=(am[i]*200)+(pm[i]*300);
    }
    for(int i=0;i<9;i++){
        cout<<name[i]<<" "<<sum[i]<<" "<<syuunyuu[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3132
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = Input.num;
        var ab = new int[num][];
        var cd = new int[num][];
        for (var i = 0; i < 2 * num; i++)
            if (i < num)
                ab[i] = Input.ar;
            else cd[i % num] = Input.ar;
        cd = cd.OrderBy(v => v[1]).ToArray();
        var ct = 0;
        var bo = new bool[2 * num];
        for (var i = 0; i < num; i++)
        {
            var max = -1;
            for (var j = 0; j < num; j++)
                if (!bo[ab[j][0]] && ab[j][1] < cd[i][1] && ab[j][0] < cd[i][0] && max < ab[j][0])
                    max = ab[j][0];
            if (max != -1)
            {
                ct++;
                bo[max] = true;
            }
        }
        WriteLine(ct);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13524
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int P = 1e9 + 7;
inline int mul(int a,int b) {return ll(a) * b % P;}

bool ispalindomic(string s) {
  string t = s;
  reverse(all(t));
  return s == t;
}
const int N = 220;
int h , w , fac[10];
string s[N];
int fa[N];
int F(int x) {return fa[x] == x ? x : fa[x] = F(fa[x]);}

int main(){
  rep(i,0,10) fac[i] = i ? fac[i-1] * i : 1;
  cin >> h >> w;
  rep(i,0,h) cin >> s[i];
  int ans = 1;
  if(h & 1) {
    int mid = h >> 1;
    ans = mul(ans , ispalindomic(s[mid]) ? 1 : 2);
    rep(i,mid,h) s[i] = s[i + 1];
    --h;
  }
  if(w & 1) {
    int mid = w >> 1;
    string t = "";
    rep(i,0,h) t += s[i][mid];
    ans = mul(ans , ispalindomic(t) ? 1 : 2);
    rep(i,0,h) s[i].erase(s[i].begin() + mid);
    --w;
  }
  int half_h = h >> 1;
  int half_w = w >> 1;
  rep(i,0,half_h + half_w) fa[i] = i;
  rep(i,0,half_h) rep(j,0,half_w) {
    map<char,int> times;
    times[s[i][j]]++;
    times[s[h-1-i][j]]++;
    times[s[i][w-1-j]]++;
    times[s[h-1-i][w-1-j]]++;
    if(sz(times) == 4) {
      ans = mul(ans , 12);
      fa[F(j + half_h)] = F(i);
    } else {
      int cof = 24;
      for(auto e : times)
        cof /= fac[e.se];
      ans = mul(ans , cof);
    }
  }
  int cof = half_h + half_w;
  rep(i,0,half_h + half_w) cof -= F(i) == i;
  rep(i,0,cof) ans = mul(ans , 2);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define double long double
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment
const double EPS = 1e-10;
const double eps = 1e-10;
double dot(P a, P b){ return real(conj(a)*b);}
double cross(P a, P b){ return imag(conj(a)*b);}
bool eq(double a,double b){return abs(a-b)<eps;}
bool eq(P a,P b){return eq(a.real(),b.real())&&eq(a.imag(),b.imag());}
double getDistanceLP(L s, P p){

  assert( !eq( s.first, s.second) );

  return abs(cross(s.second - s.first, p - s.first) / abs(s.second - s.first));
}
bool isParalell(L a,L b){return  eq(0,cross(a.second-a.first,b.second-b.first));}

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}

vector<L> A;
bool check(P a){
  double dis = getDistanceLP(A[0],a);

  for(int i=0;i<(int)A.size();i++)
    if(!eq(dis,getDistanceLP(A[i],a))) return 0;

  return  1;
}

L calc(P o,P a,P b){
  a-=o,b-=o;
  return L(o,(a/abs(a) + b/abs(b)) + o);
}

/*
L StoL(L a){
  P t=a.second - a.first;
  t = (t/abs(t)) * (double)1e6;
  return L(-t+a.first,t+a.first);
}
*/

P gv(L l){
  return l.second-l.first;
}

int main(){
  int n;
  while(cin>>n,n){
    A.resize(n);
    for(int i=0,x1,y1,x2,y2;i<n;i++){
      cin>>x1>>y1>>x2>>y2;
      A[i] = L(P(x1,y1),P(x2,y2));
    }


    if(n<=2){cout<<"Many"<<endl;continue;}
    
    vector<L> B; 
    for(int i=0;i<n;i++)
      for(int j=0;j<i;j++){
	L a = A[i], b = A[j];

	if(isParalell(a,b)||B.size()>100)continue;

	P o = crossPoint(a,b);

	//printf("%.8Lf %.8Lf\n", (double)o.real(), (double)o.imag() );

	//cout<<"ij"<<i<<j<<endl;
	//printf("o=(%Lf,%Lf)\n",o.real(),o.imag());
	//cout<<"o="<<o<<endl;
	//cout<<"a="<<a.first<<" "<<a.second<<endl;
	//cout<<"b="<<b.first<<" "<<b.second<<endl<<endl;

	P va=a.second-a.first;
	P vb=b.second-b.first;
	va /= abs(va);
	vb /= abs(vb);

	B.push_back( L( o , o+va+vb) );
	B.push_back( L( o , o+va-vb ) );

      }


    //  for(int i=0;i<B.size();i++)cout<<B[i].first<<" "<<B[i].second<<endl;
       
    vector<P> ans;
    for(int i=0;i<(int)B.size();i++)
      for(int j=i+1;j<(int)B.size();j++){


	L a = B[i], b = B[j];

	if(isParalell(a,b)) continue;

	P c = crossPoint(a,b);

	if(check(c)&&(ans.empty()||!eq(ans[0],c))) ans.push_back(c);

      }
    
    if(ans.size()>=2) cout<<"Many"<<endl;
    else if(ans.empty()) cout<<"None"<<endl;
    else printf("%Lf %Lf\n",ans[0].real(),ans[0].imag());
  }
  return 0;
}

Measured memory_bytes: 3292
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han Elmuzaffer Daima
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

lo n,m,cev,b,a[li],k;
string s;
vector<lo> v;

inline lo solve(){
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&a[i]);
	}
	//////////////////////////negatif///////////////////////////////////
		lo sum=0;
		FOR{
			sum+=a[i];
			if(i%2==1 && sum>=0){cev+=sum+1;sum=-1;}
			if(i%2==0 && sum<=0){cev+=abs(sum-1);sum=1;}
		}
	//////////////////////////negatif///////////////////////////////////
	
	//////////////////////////pozitif///////////////////////////////////
		lo sum1=0,cev1=0;
		FOR{
			sum1+=a[i];
			if(i%2==0 && sum1>=0){cev1+=sum1+1;sum1=-1;}
			if(i%2==1 && sum1<=0){cev1+=abs(sum1-1);sum1=1;}
		}
		cev=min(cev,cev1);
	//////////////////////////pozitif///////////////////////////////////
	printf("%lld\n",cev);
	return 0;
}

int main(void){
	solve();
	
	return 0;
}


Measured memory_bytes: 1024
using System;
class Program{
	static int[] s;
	static int b,ans=0;
	static int[] h;
	static void Main(){
		s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		h=new int[s[0]+1];
		for(int i=0;i<s[1];i++){
			int[] q=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			h[q[0]]|=1<<(q[1]-1);
			h[q[1]]|=1<<(q[0]-1);
		}
		fu(1);
		Console.WriteLine("{0}",ans);
	}
	static void fu(int n){
		b|=1<<(n-1);
		if(b==(1<<s[0])-1){ans++;}
		else{
			for(int i=0;i<s[0];i++){
				if(((h[n]&(1<<i))!=0)&&((b&(1<<i))==0)){fu(i+1);}
			}
		}
		b-=1<<(n-1);
	}
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define MOD 1000000007
#define fi(i,a,b) for(ll i = a; i < b; i++)
#define fd(i,a,b) for(ll i = a; i >= b; i--)
#define cfi(container,it) for(auto it = container.begin(); it != container.end(); it++)
#define cfd(container,it) for(auto it = container.rbegin(); it != container.rend(); it++)
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pbx(num) ll temp; cin>>temp; num.pb(temp) 

using namespace std;
typedef long long ll;

struct modll {
	ll num;
	operator ll() {return num;}
};
modll operator *(modll x, modll y) {return {(x.num * y.num) % MOD} ;}
modll operator +(modll x, modll y) {return {(x.num + y.num + MOD) % MOD} ;}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int h, w;
	char x;
	cin>>h>>w;

	vector<vector<bool>> a(h + 1, vector<bool>(w + 1));
	fi(i, 1, h + 1) {
		fi(j, 1, w + 1){
			cin>>x;
			a[i][j] = (x == '.');
		}
	}

	vector<vector<modll>> dp(h + 1, vector<modll>(w + 1));
	dp[1][1].num = 1;

	fi(i, 1, h + 1) {
		fi(j, 1, w + 1){

			if(i == 1 && j == 1)
				continue;

			if(a[i][j]){
				if(a[i][j-1])
					dp[i][j] = dp[i][j] + dp[i][j-1];

				if(a[i-1][j])
					dp[i][j] = dp[i][j] + dp[i-1][j];
				
			}
			
		}
	}

	// for(i = 1; i<=h;i++){
	// 	for(j=1;j<=w;j++)
	// 		cout<<dp[i][j]<<"  ";
	// 	cout<<'\n';
	// }

	cout<<dp[h][w]<<'\n';

	return 0;
}

Measured memory_bytes: 8320
<?php
list($A, $B, $N) = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$c = floor($N / $B);

$max = 0;
$XmodB = 0;
/*
for ($i = 0; $i <= min($B, $N); $i ++) {
    $maximize = floor(($A * $i) / $B);
    if ($maximize > $max) {
        $max = $maximize;
    }
}
*/
$d = min($B - 1, $N);
echo floor($A / $B) * $d + floor(($A % $B) * $d / $B);

Measured memory_bytes: 16028
// inputに入力データ全体が入る
const Main = (input) => {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  	var k = parseInt(input[5], 10); 
	//文字列から10進数に変換するときはparseIntを使います
	//const a = parseInt(input[0], 10);
  	var flg = false;
  	var i, j;
  	for (i=0; i<input.length; i++) {
      for (j=i+1; j<input.length; j++) {
        if (parseInt(input[j], 10) - parseInt(input[i], 10) > k) {
          flg = true;
          break;
        }
      }
    }
	//出力
	console.log((flg) ? ":(" : "Yay!");
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;
#define For(i,l,r) for (int i = l; i <= r; ++i)
#define Cor(i,l,r) for (int i = l; i >= r; --i)
#define UPD(a,b) { if (a > b) { a = b; } }

const int INF = 0x3f3f3f3f;
int n, m;
char A[333][333];
int dp[666][666];
int cost[666][666];
int main() {
	cin >> n >> m;
	For(i,1,n) scanf("%s", A[i] + 1);
	int ans = 0;
	For(i,1,m - 1) {
		memset(cost, 0, sizeof cost);
		For(j,1,n) For(k,1,n) if (A[j][i] == A[k][i + 1]) {
			++cost[j + n - k][n + n - j - k];
		}
		For(j,0,n + n) Cor(k,n + n,0) cost[j][k] += cost[j][k + 1];
		memset(dp, INF, sizeof dp);
		dp[0][n] = 0;
		For(j,0,n + n - 1) For(k,0,n + n) if (dp[j][k] < INF) {
			if (k > 0) UPD(dp[j + 1][k - 1], dp[j][k] + cost[k][j]);
			if (k < n + n) UPD(dp[j + 1][k + 1], dp[j][k] + cost[k][j]);
		}
		ans += dp[n + n][n];
		//cout << dp[n + n][n] << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3840
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

def chmax(a, b):
    if a < b:
        return b
    else:
        return a

def main():
    n, k = map(int, input().split())
    h = tuple(map(int, input().split()))
    dp = [inf] * 110000

    dp[0] = 0
    for i in range(n-1):
        for j in range(1, min(k+1, n-i)):
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i+j] - h[i]))
    print(dp[n-1])

if __name__ == '__main__':
    main()



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

int main() {
  char right[11] = {'y', 'u', 'i', 'o', 'p', 'h', 'j', 'k', 'l', 'n', 'm'};
  char left[15] = {'q', 'w', 'e', 'r', 't', 'a', 's', 'd', 'f', 'g', 'z', 'x', 'c', \
'v', 'b'};
  string str;
  bool r;
  int count;

  while(1) {
    cin >> str;
    if(str[0] == '#') break;

    r = false;
    for(int i = 0; i < 11; i++) {
      if(str[0] == right[i])
        r = true;
    }

    count = 0;
    for(int i = 1; i < str.size(); i++) {
      //前が右手のキー                                                               
      if(r == true) {
	for(int j = 0; j < 15; j++) {
          if(str[i] == left[j]) {
            r = false;
            count++;
            break;
          }
        }
      }
      //前が左手のキー                                                               
      else {
	for(int j = 0; j < 11; j++) {
          if(str[i] == right[j]) {
            r = true;
            count++;
            break;
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}


Measured memory_bytes: 3120
def left2right(formula):
    ans = int(formula[0])
    for i in range(1,len(formula),2):
        ans = eval(str(ans) + formula[i:i+2])
    return ans

formula = input()
val = int(input())
if left2right(formula) == val:
    print('U' if eval(formula) == val else 'L')
else:
    print('M' if eval(formula) == val else 'I')

Measured memory_bytes: 5604
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int n;
	vector<int> c,s,f;
	cin >> n;
	n--;
	for(int i=0;i<n;++i){
		int cc,ss,ff;
		cin >> cc >> ss >> ff;
		c.push_back(cc);
		s.push_back(ss);
		f.push_back(ff);
	}
	for(int i=0;i<n;++i){
		int time = c[i] + s[i];
		for(int j=i+1;j<n;++j){
			if(s[j] >= time){
				time = s[j] + c[j];
			}else{
				while(time % f[j] != 0)time++;
				time += c[j];
			}
		}
		cout << time << endl;
	}
	cout << 0 << endl;
}

Measured memory_bytes: 256
// JavaScript source code
"use strict";

let myFunc = (input) => {
    input = input.split(" ");
    let a, b;
    a = parseInt(input[0]);
    b = parseInt(input[1]);
    if((a * b) % 2 === 1) console.log("Odd");
    if((a * b) % 2 === 0) console.log("Even");
};

myFunc(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29488
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		int R = 700;
		int T = 0;
		for (int i = 0; i < S.length(); i++) {
			if ("o".equals(S.substring(i, i + 1))) {
				T += 100;
			}
		}
		System.out.println(T + R);
	}
}

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

const double pi=acos(-1.0);
double ans1,ans2,nn;
int n,L,T[3010];

int main()
{
	scanf("%d%d",&n,&L),ans1=ans2=0,nn=(1ll*n*(n-1)*(n-2)/6);
	for (int i=1; i<=n; i++) scanf("%d",&T[i]);
	for (int i=1; i<=n; i++)
		for (int j=i+1; j<=n; j++)
		{
			double x=cos((pi*(T[i]+T[j]))/L),y=sin((pi*(T[i]+T[j]))/L);
			ans1-=x*(j-i-1),ans2-=y*(j-i-1),ans1+=x*(n-j+i-1),ans2+=y*(n-j+i-1);
		}
	ans1/=nn,ans2/=nn;
	printf("%.10lf %.10lf\n",ans1,ans2);
	return 0;
}

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

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}

int main()
{
  int n;
  int x[100];
  int ret;
  int i,j;
  int cost[100];
  int count;
  int min,max;
  int min_sum;
  
  ret=scanf("%d", &n);
  for (i=0;i<n;++i){
    ret=scanf("%d", &x[i]);
  }
  qsort(x,n,sizeof(int),cmp);

  min=x[0];
  max=x[n-1];

  count=-1;
  for(i=min;i<=max;++i){
    ++count;
    cost[count]=0;
    for(j=0;j<n;++j){
      cost[count]+=(x[j]-i)*(x[j]-i);
    }
  }


  min_sum=cost[0];
  for(i=1;i<count;++i){
    if (cost[i] < min_sum){
      min_sum=cost[i];
    }
  }
  
  printf("%d\n", min_sum);

  return 0;
}


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

int main(){
    int N,D;
    cin >> N >> D;
    double X[N][D];
    for(int i = 0;i< N;i++){
        for(int j=0;j<D;j++){
            cin >> X[i][j];
        }
    }
//    cout <<endl;
    double sub[D],SUM;
    int cnt = 0;
    for(int i = 0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int k=0;k<D;k++){
                SUM += pow(X[i][k] - X[j][k],2);
            //cout << SUM << endl;
            }
            SUM = sqrt(SUM);
            //cout << "\n" << SUM << endl;
            if(SUM == (int)SUM) cnt++;

        SUM = 0;
        }
    }
    cout << cnt << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    vector<int> es[N][2];
    int num[N][2];
    rep(i, M){
        int a, b; cin >> a >> b; a--, b--;
        es[a][S[b]-'A'].pb(b);
        es[b][S[a]-'A'].pb(a);
    }
    rep(i, N){
        rep(j, 2) num[i][j] = sz(es[i][j]); 
    }
    queue<int> que;
    vector<bool> rem(N, false);
    rep(i, N){
        if(!num[i][0] || !num[i][1]) que.push(i);
    }
    while(!que.empty()){
        int i = que.front();
        que.pop();
        if(rem[i]) continue;
        if(num[i][0] && num[i][1]) continue;
        rem[i] = true;
        int k = S[i]-'A';
        rep(j, 2){
            for(auto &e: es[i][j]){
                num[e][k]--;
                que.push(e);
            }
        }
    }
    bool res = true;
    rep(i, N) res &= rem[i];
    if(!res) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 18948
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  
  ll lcm_me=c*d/__gcd(c,d);
  ll ac=(a-1)/c;
  ll ad=(a-1)/d;
  ll alcm=(a-1)/lcm_me;
  ll bc=b/c;
  ll bd=b/d;
  ll blcm=b/lcm_me;

  //cout<<floor(b/d)<<" "<<b/d<<endl;
  cout<<(b-(bc+bd-blcm))-(a-(ac+ad-alcm))+1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pq priority_queue
using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2; typedef pair<int, P2> P3;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<1010> fact; constexpr Prime<10> prime;
constexpr long long comb(int a, int b){if(a < b) return 0LL;if(!a or !b) return 1LL; long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b]; return pos * pot % MOD * por % MOD;}
template<int n> struct Bernoulli{long long arr[n+1];constexpr Bernoulli():arr(){arr[0]=1;for(int i=1;i<=n;i++){long long sum=0;for(int j=0;j<i;j++){(sum+=comb(i+1,j)*arr[j]%MOD)%=MOD;}arr[i]=(MOD-mod_pow(i+1,MOD-2,MOD))%MOD*sum%MOD;}}};
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr long double PI = abs(acos(-1));
constexpr int sqrtN = 512, logN = 32;
constexpr long long LINF=1e18;

int main(){
	int n; cin >> n; vector<int> vec(n + 2, 0);
	for(int i = 1; i <= n; i++) cin >> vec[i];
	
	long long s = 0;
	for(int i = 1; i <= n + 1; i++) s += abs(vec[i - 1] - vec[i]);
	
	for(int i = 1; i <= n; i++){
		long long d = abs(vec[i - 1] - vec[i]) + abs(vec[i] - vec[i + 1]);
		long long D = abs(vec[i - 1] - vec[i + 1]);
	
		cout << s - d + D << endl;
	}
	return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int Pow(int n, int m);
int Max(int N[], int n);
int Min(int N[], int n);
int Sum(int N[], int n);



int main()
{
	int H = 0, W = 0;
	scanf("%d%d", &H, &W);

	char** A = (char**)calloc(H, sizeof(char*));
	for (int i = 0; i < H; i++) {
		A[i] = (char*)calloc(W + 1, 2 * sizeof(char));
	}

	for (int i = 0; i < H; i++) {
		scanf("%s", A[i]);
	}

	//
	//
			//printf("debug:\n");
			//for (int i = 0; i < H; i++) {
			//	for (int j = 0; j < W; j++) {
			//		printf("%c", A[i][j]);
			//	}
			//	printf("\n");
			//}
			//printf("\n");
	//
	//

	int flag_h[100] = { 0 };
	int flag_w[100] = { 0 };


	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A[i][j] == '#'){
			flag_h[i] = 1;
			flag_w[j] = 1;
			}
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if ((flag_h[i] == 1) && (flag_w[j] == 1)) {
				printf("%c", A[i][j]);
			}

			if (j == W - 1)  printf("\n");
		}
	}




	return 0;
}

int Pow(int n, int m) {
	int ret = 1;

	for (int i = 0; i < m; i++) {
		ret *= n;
	}

	return ret;
}

int Max(int N[], int n) {
	int max = N[0];

	for (int i = 0; i < n; i++) {
		max = max < N[i] ? N[i]: max;
	}

	return max;
}

int Min(int N[], int n) {
	int min = N[0];

	for (int i = 0; i < n; i++) {
		min = min > N[i] ? N[i] : min;
	}

	return min;
}

int Sum(int N[], int n) {
	int sum = 0;

	for (int i = 0; i < n; i++) {
		sum += N[i];
	}

	return sum;
}

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

int main() {
    string N;
    int onazi;
    cin >> N;
    onazi=0;

     if(N.at(0)==N.at(1)&&N.at(1)==N.at(2)){
            onazi=1;
        }

     if(N.at(1)==N.at(2) &&N.at(2)==N.at(3)){
            onazi=1;
     }

     if(onazi==1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5;
const int mod=1e9+7;
int a[maxn+5],num[maxn+5],dp[maxn+5];
int x[1<<20],y[1<<20];
int n;
void update(int &x,int y)
{
	x=(x+y)%mod;
}
int main()
{

	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]),a[i]^=a[i-1],num[i]=num[i-1]+(a[i]==0);
	for(int i=1;i<=n;++i) dp[i]=1;
	for(int i=1;i<=n;++i)
	{
		update(dp[i],(1LL*x[a[i]]*num[i]-y[a[i]])%mod);
		update(x[a[i]],dp[i]);
		update(y[a[i]],1LL*dp[i]*num[i]%mod);
	}
	if(dp[n]<0) dp[n]+=mod;
	if(a[n]>0) cout<<dp[n];
	else
	{
		int ans=1;
		for(int i=1;i<=num[n-1];++i) ans=ans*2%mod;
		for(int i=1;i<=n;++i)
			if(a[i]>0) update(ans,dp[i]);
		if(ans<0) ans+=mod;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int W, H, N;
  cin >> W >> H >> N;
  int min_x = 0;
  int max_x = W;
  int min_y = 0;
  int max_y = H;
  for(int ii=0; ii<N; ii++){
    int x, y, a;
    cin >> x >> y >> a;
    switch(a){
      case 1:
        min_x = max(min_x, x);
        break;
      case 2:
        max_x = min(max_x, x);
        break;
      case 3:
        min_y = max(min_y, y);
        break;
      case 4:
        max_y = min(max_y, y);
        break;
    }
  }
  max_x = max(max_x, min_x);
  max_y = max(max_y, min_y);
  cout << (max_x-min_x)*(max_y-min_y) << endl;
  return 0;
}

Measured memory_bytes: 256