akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;


int main(){
    int N,Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    vector<int> memo(s.length()+1,0);
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'A' && s[i+1] == 'C'){
            memo[i+1] = memo[i] + 1;
        }else{
            memo[i+1] = memo[i];
        }   
    }
    vector<int> res;
    rep(i,Q){
        int l,r;
        cin >> l >> r;
        l--;r--;
        res.push_back(memo[r] - memo[l]);
    }
    for(auto e : res){
        cout << e << endl;
    }
    return 0;
}

Measured memory_bytes: 1912
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {

            {
                var read = Console.ReadLine();
                var temp_string = read.Split(' ');
                int a = int.Parse(temp_string[0]), b = int.Parse(temp_string[1]),c=int.Parse(temp_string[2]),ans=0;

                for (int i = a; i <= b;i++ )
                {
                    if(c%i==0)
                    {
                        ans++;
                    }
                }

                Console.WriteLine(ans);
            }
        }
    }
}

Measured memory_bytes: 9180
import copy

N, M = [ int(x) for x in input().split() ]

class Node:
    def __init__(self, id):
        self.id = id
        self.path = []
    def __str__(self):
        return "id: " + str(self.id) + " path: " + str(self.path)

nodes = []
for i in range(N):
    nodes.append(Node(i))

for i in range(M):
    from_id, to_id = [ int(x) - 1 for x in input().split() ]
    nodes[from_id].path.append(to_id)
    nodes[to_id].path.append(from_id)

def if_all_passed(passed_nodes):
    if len(passed_nodes) == N:
        return True
    else:
        return False

def go_child(id_new, passed_nodes):
    passed_nodes.append(id_new)
    if if_all_passed(passed_nodes):
        return 1

    count = 0
    for i in nodes[id_new].path:
        if not i in passed_nodes:
            count += go_child(i, copy.deepcopy(passed_nodes))
    return count

count = go_child(0, [])
print(count)


Measured memory_bytes: 3572
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 13, 2020 04:11:55 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


import math
from sys import stdin
input = stdin.readline


def main():
  A, B, C, D = list(map(int, input().split()))

  # divisible by C
  dc = B//C - (A-1)//C

  # divisible by D
  dd = B//D - (A-1)//D

  lcm = C * D // math.gcd(C, D)
  # divisible by (C and D)
  dcd = B//lcm - (A-1)//lcm

  # print(f'B-A+1: {B-A+1}')
  # print(f'dc   : {dc}')
  # print(f'dd   : {dd}')
  # print(f'lcm  : {lcm}')
  # print(f'dcd  : {dcd}')
  print((B-A+1) - dc - dd + dcd)


if(__name__ == '__main__'):
  main()


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

int main()
{
    long long int n,i,x;
    cin>>n;

    int a[n];

    for(i=1;i<=n;i++)
        a[i]=0;

    for(i=1;i<n;i++)
    {
        cin>>x;
        ++a[x];
    }


    for(i=1;i<=n;i++)
    {
        cout<<a[i]<<endl;
    }
}


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

int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long test=1;
// 	cin>>test;	
	while(test--)
	{
	    long a,b=0,c=0,k,i,n,j,mini,maxi,ans,q,sum,x,y,count=0,next,prev;
	   
	    string s1,s2,s3;
	    cin>>s1>>s2>>s3;
	    cout<<"A"<<s2[0]<<"C";
	
    }
    
}


Measured memory_bytes: 256
#include<stdio.h>

int zetai(int num);

int main() {
    
    long n,k,ans,a;
    scanf("%ld %ld",&n,&k);
    if(n > k) {
        a = n % k;
    } else {
        a = n;
    }
    if(a < k - a) {
        ans = a;
    } else {
        ans = k-a;
    }

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

    return 0;
}

int zetai(int num) {
    if(num < 0) {
        num *= -1;
    }
    return num;
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

void chmin(int &a, int b){
  if(a > b)
    a = b;
}
void chmax(int &a, int b){
  if(a < b)
    a = b;
}

void llchmin(ll &a, ll b){
  if(a > b)
    a = b;
}
void llchmax(ll &a, ll b){
  if(a < b)
    a = b;
}

int main(){
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  
  rep(i, 0, s.size()){
    if(s[i] != t[i])
      cnt++;
  }
  
  cout << cnt << endl;
  
  return 0;
  
}

Measured memory_bytes: 3924
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0; i<n; i++){
			int b = 0;
			int c = 0;
			for(int j=0; j<10; j++){
				int read = sc.nextInt();
				if( (b>c ? b : c) < read ){
					if(b > c) b = read;
					else c = read;
				}
				else if(b < read && c > read) b=read;
				else if(c < read && b < read) c=read;
				else { System.out.println("NO"); break; }
				if(j==9) System.out.println("YES");
			}
		}
	}
}

Measured memory_bytes: 12000
#define TEST_MODE false
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long
 
#ifdef LOCAL_ENV
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << endl
#else
const bool test = false;
#define dump(x) 
#endif
 
#else
const bool test = false;
#define dump(x) 
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}
 
void solve();
 
class Solver {
public:
  int N, P;
  int a[105];
  int dp[10005];
  
  void solve() {
	cin >> N >> P;
	rep(i, N) dp[i] = 0;
	rep(i, N) cin >> a[i];
	dp[0] = 1;
	rep(i, N) {
	  rrep2(j, 10005, a[i]) {
		dp[j] += dp[j - a[i]];
	  }
	}
	int res = 0;
	rep(i, 10005) {
	  if (i % 2 == P) {
		res += dp[i];
	  }
	}
	cout << res << endl;
  }
};
 
signed main()
{
    cout << fixed << setprecision(20);
    auto ptr = new Solver();
    ptr->solve();
    delete ptr;
    // while (true) {
    //     solve();
    // }
    return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'
 


Measured memory_bytes: 384
<?php
fgets(STDIN);
$t=[];$st=true;
while($i = trim(fgets(STDIN))){
  $o = explode(" ",$i);
  array_shift($o);
  if($st){
    $t=$o;
    $st=false;
  }else{
    $t = array_intersect($t,$o);
  }
}
echo sizeof($t);

Measured memory_bytes: 4732
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<ll> v(n+1, 0);
    for(int i=1; i<=n; i++){
        ll a;
        cin >> a;
        v[i] = v[i-1] + a;
    }

    ll ans = INF;
    for(int i=1; i<n; i++){
        ans = min(ans, abs(v[n] - 2*v[i]));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int64_t V[3010][3010];
int64_t dp[3010][3010][3];

void init()
{
  for (int i = 0; i < 3010; i++)
  {
    for (int j = 0; j < 3010; j++)
    {
      for (int k = 0; k < 3; k++)
      {
        dp[i][j][k] = -1;
      }
    }
  }
  dp[0][0][0] = 0;
}

int main()
{
  int64_t R, C, K, r, c, v;
  cin >> R >> C >> K;
  for (int i = 0; i < K; i++)
  {
    cin >> r >> c >> v;
    r--, c--;
    V[r][c] = v;
  }
  init();
  for (int i = 0; i < R; i++)
  {
    for (int j = 0; j < C; j++)
    {
      for (int k = 0; k < 3; k++) // NOTE: 行iで、既にk個拾った状態
      {
        if (dp[i][j][k] == -1)
          continue;
        dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
        dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
        if (k < 2)
        {
          if (V[i][j] > 0)
          {
            dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1], dp[i][j][k] + V[i][j]);
            dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k] + V[i][j]);
          }
        }
        else
        {
          if (V[i][j] > 0)
          {
            dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k] + V[i][j]);
          }
        }
      }
    }
  }
  int64_t ans = 0;
  for (int i = 0; i <= R; i++)
  {
    for (int j = 0; j <= C; j++)
    {
      for (int k = 0; k < 3; k++) // NOTE: 行iで、既にk個拾った状態
      {
        ans = max(ans, dp[i][j][k]);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 286368
import math
from math import factorial
from operator import mul
from functools import reduce
from numpy.linalg import solve
 
X, Y = map(int, input().split())
 
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a
 
def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod
 
def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod
 
 
if ((X + Y) %3!=0):
    print(0)
else :
    min_za = min(X, Y)
    max_za = max(X, Y)
    left = [[1, 2],
            [2, 1]]
 
    right = [X, Y]
    diff = (solve(left, right))
    diff_1 = int(diff[0])
    diff_2 = int(diff[1])

    sum = diff_1 + diff_2

    if (diff_1 >=0 and diff_2 >=0):
        print(comb(sum,diff_1,10**9+7))
    else:
        print(0)

Measured memory_bytes: 14504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct UnionFind
{
    vector<ll> par;
    vector<ll> rank;
    vector<ll> sz;
    UnionFind(ll n) : par(n), rank(n), sz(n)
    {
        for(ll i = 0; i < n; i++)
        {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }
    ll root(ll x)
    {
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }
    void unite(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y])
        {
            par[x] = y;
            sz[y] += sz[x];
        }
        else
        {
            par[y] = x;
            sz[x] += sz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    bool same(ll x, ll y)
    {
        return root(x) == root(y);
    }
    ll size(ll x)
    {
        x = root(x);
        return sz[x];
    }
};
struct edge {ll u, v, cost;};
bool comp(const edge& e1, const edge& e2)
{
    return e1.cost < e2.cost;
}
int main()
{
    ll n;
    cin >> n;
    using P = pair<ll, ll>;
    vector<P> x(n);
    vector<P> y(n);
    for(int i = 0; i < n; i++)
    {
        ll a, b;
        cin >> a >> b;
        x[i] = P(a, i);
        y[i] = P(b, i);
    }
    vector<edge> es;
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    for(int i = 0; i < n-1; i++)
    {
        ll cost = x[i+1].first - x[i].first;
        edge e = {x[i+1].second, x[i].second, cost};
        es.push_back(e);
    }
    for(int i = 0; i < n-1; i++)
    {
        ll cost = y[i+1].first - y[i].first;
        edge e = {y[i+1].second, y[i].second, cost};
        es.push_back(e);
    }

    // kruscal start
    ll V = n;
    UnionFind tree(V);
    ll E = es.size();
    sort(es.begin(), es.end(), comp);
    ll res = 0;
    for(int i = 0; i < E; i++)
    {
        edge e = es[i];
        if(!tree.same(e.u, e.v))
        {
            tree.unite(e.u, e.v);
            res += e.cost;
        }
    }
    cout << res << endl;
    // kruscal end
}


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

typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
  int N, X;
  cin >> N >> X;

  std::vector<int> v(N);
  std::vector<int> d(N);
  for(int i = 0; i < N; i++) {
    cin >> v.at(i);
    d.at(i) = abs(X - v.at(i));
  }

  int D = 0;
  for(int i = 0; i < N; i++) {
    D = GCD(D, d.at(i));
    if(D == 1) break;
  }

  cout << D << endl;
}


Measured memory_bytes: 1024
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;

bool Compare(int a, int b)
{
   return a < b;
}
std::priority_queue<int, std::vector<int>, std::function<bool(int, int)>> pq(Compare);

vi pr;
void seive(){
	int p[100005]={0};
	f(i,2,100005){
		if(p[i]==0){
			pr.pb(i);
			for(int j=i*2;j<100005;j+=i) p[j]=1;
		}
	}
}


void solve(){
	int a,b,c; cin>>a>>b>>c;
	int a1=a*10+b+c;
	a1=max(a1,a+b*10+c);
	
	a1=max(a1,a+c*10+b);
	a1=max(a1,a+c*10+b);
	
	
	a1=max(a1,b+a*10+c);
	a1=max(a1,b+a*10+c);
	
	a1=max(a1,b+c*10+a);
	a1=max(a1,b+c*10+a);
	
	a1=max(a1,c+a*10+b);
	a1=max(a1,c+a*10+b);
	
	a1=max(a1,c+b*10+a);
	a1=max(a1,c+b*10+a);
	
	cout<<a1;
}


int32_t main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int t=1; //cin>>t;
  while(t--) solve();
  return 0;
}
// check for overflows dummy !!!

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

using namespace std;
int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int k = a / d;
    if(d<a)
    {
	if (a - k * d == 0 && c-k*b>0)
	{
		cout << "No";
	}
	else
	{
		if (c - (k + 1)*b <= 0)
		{
			cout << "Yes";
		}
		else
		{
			cout << "No";
		}
	}
    }
    else
    {
      if(c-b>0)
      {
        cout<<"No";
      }
      else
      {
        cout<<"Yes";
      }
    }
}


Measured memory_bytes: 3636
import copy
N,H=map(int,input().split())

A=[]
B=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if A[-1]>=B[-1]:
    print((H-1+A[-1])//A[-1])
    exit()

cnt=0
ans=[]

while B[-1]>A[-1]:
    H-=B[-1]
    cnt+=1
    if H<=0:
        ans.append(cnt)
        print(min(ans))
        exit()
    elif cnt==N:
        break
    B.pop()

ans.append(cnt+(H-1+A[-1])//A[-1])
print(min(ans))


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

const int INF = 1 << 28;

int m, n;
int p[10010], c[510], e[510];
int dp[510][10010];

int calc(int i, int j)
{
	if (j <= 0) return 0;
	if (i == n) return INF;
	if (~dp[i][j]) return dp[i][j];
	return dp[i][j] = min(calc(i + 1, j), e[i] + calc(i + 1, j - c[i]));
}

int main()
{
	cin >> m >> n;
	
	for (int i = 0; i < m; i++){
		cin >> p[i];
	}

	sort(p, p + m, greater<int>());
	
	for (int i = 0; i < n; i++){
		cin >> c[i] >> e[i];
	}
	
	memset(dp, -1, sizeof(dp));
	int res = 0, s = 0;
	for (int i = 0; i < m; i++){
		s += p[i];
		res = max(res, s - calc(0, i + 1));
	}
	
	cout << res << endl;
}

Measured memory_bytes: 21180
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <math.h>
#include <utility>

using namespace std;

int main(){

    int N, ans = 1;
    string S;
    cin >> N >> S;

    char old = S[0];

    for (int i = 1; i < N; i++){
        if (old != S[i]){
            ans++;
            old = S[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
n = int(input())
al = list(map(int,input().split()))

import itertools
al_ac = list(itertools.accumulate(al))

ans = float("inf")

for a in al_ac:
    if ans > abs( (al_ac[-1] - a) -a) :
        ans = abs( (al_ac[-1] - a) -a)

print(ans)

Measured memory_bytes: 100304
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
ll dfs(int index, ll sum) {
  ll sum_a = 0;
  FOR(i, index, s.length()) {
    ll now = stoll(s.substr(index, (i - index + 1)));
    sum_a += dfs(i + 1, sum + now);
  }

  return sum_a == 0 ? sum : sum_a;
}

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

  cin >> s;

  cout << dfs(0, 0) << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = readline().rstrip().decode()
if len(s) % 2 == 1:
    print('No')
    exit()
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] != 'h':
            print('No')
            exit()
    else:
        if s[i] != 'i':
            print('No')
            exit()
print('Yes')


Measured memory_bytes: 3060
/*
   给出  n 个人 ， m 句话
   
   每句话说 ：给你 l , r , dis 表示 l 在 r 左边的 dis 个距离单位
   
   （里面有假话，有真话）
    
   问 ： 是否上面都是真话
   
 ----------------------------------------------------------------------  
   题解：   
      假设 n 个人 为 n 个点， 然后距离看做 权值，
	  
	  作为一个单向图进行dfs 判断
	  
	  
	  从 1 到 N 每个点进行判断 
	  
	  如果某个值没被访问 ， 以这个点进行 一次深搜，判断是否冲突
	  
	  dfs内容 : 进行标记 访问过 表示已经存在了距离，然后看 能通往这个地方的一些人 （节点）
	  
	  如果这个点被访问过那么通往他的值都会被确定 只要验证
	  
	  如果这个点没被访问，就奖通完他的地方的值进行赋值 ，继续搜索能通往这个没被访问过的节点， 
	  
*/


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>

using namespace std;

#define   M             100005
#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   inf           1e9
#define   rush()        int T;scanf("%d",&T);while(T--)

typedef   pair<int,int> P;

vector< P > E[M];
P temp;
int d[M],n,m,l,r,dis;
bool  vis[M],f;

bool dfs(int now) {
	vis[now]=1;
	if(f) return false;
	
	for(int i=0;i<E[now].size();i++) {
		temp=E[now][i];
		
		if(!vis[temp.first]) {
			d[temp.first]=d[now]+temp.second;
			dfs(temp.first);
		}
		else {
			if(d[temp.first] != d[now] + temp.second) {
				f=1;
				return false;
			}
		}
	}
	return true;
}


int main() {

	scanf("%d %d",&n,&m);
	
	while(m--) {
		scanf("%d %d %d",&l,&r,&dis);
		E[l].push_back(make_pair(r,dis));
		E[r].push_back(make_pair(l,-dis));
	}
	
	f=0;
	for(int i=1;i<=n;i++) {
		if(!vis[i]) {
			if(!dfs(i)) {
				f=1;
				break;
			}
		}
	}
	
	puts(f?"No":"Yes");
}



Measured memory_bytes: 12032
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val A = IntArray(N) { sc.next().toInt() }
        val L = IntArray(N + 1)
        val R = IntArray(N + 1)
        var l = 0
        var r = 0
        for (i in 1..N) {
            l = max(l, A[i - 1])
            L[i] = l
            r = max(r, A[N - i])
            R[i] = r
        }
        for (i in 0 until N) {
            pw.println(max(L[i], R[N - i - 1]))
        }
    }
}


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

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

    if (S == "Sunny") {
        cout << "Cloudy";
    } else if (S == "Cloudy") {
    	cout << "Rainy";
    } else {
    	cout << "Sunny";
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> x, y;
    vector<int> x1(n), y1(n), x2(n), y2(n);
    for (size_t i=0; i<n; ++i) {
        scanf("%d %d %d %d", &x1[i], &y1[i], &x2[i], &y2[i]);
        x.push_back(x1[i]);
        x.push_back(x2[i]);
        y.push_back(y1[i]);
        y.push_back(y2[i]);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    size_t xl=unique(x.begin(), x.end())-x.begin();
    size_t yl=unique(y.begin(), y.end())-y.begin();

    vector<size_t> xi1(n), xi2(n), yi1(n), yi2(n);
    for (size_t i=0; i<n; ++i) {
        xi1[i] = lower_bound(x.begin(), x.begin()+xl, x1[i])-x.begin();
        xi2[i] = lower_bound(x.begin(), x.begin()+xl, x2[i])-x.begin();
        yi1[i] = lower_bound(y.begin(), y.begin()+yl, y1[i])-y.begin();
        yi2[i] = lower_bound(y.begin(), y.begin()+yl, y2[i])-y.begin();
    }

    vector<vector<int>> imos(yl+1, vector<int>(xl+1));
    for (size_t i=0; i<n; ++i) {
        ++imos[yi1[i]][xi1[i]];
        --imos[yi1[i]][xi2[i]];
        --imos[yi2[i]][xi1[i]];
        ++imos[yi2[i]][xi2[i]];
    }

    long long res=0;
    vector<vector<int>> sum(yl+1, vector<int>(xl+1));
    for (size_t i=0; i<yl; ++i)
        for (size_t j=0; j<xl; ++j) {
            sum[i+1][j+1] = sum[i+1][j] + sum[i][j+1] - sum[i][j] + imos[i][j];
            if (sum[i+1][j+1] > 0)
                res += 1LL * (x[j+1]-x[j]) * (y[i+1]-y[i]);
        }

    printf("%lld\n", res);
    return 0;
}

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

typedef long long ll;
ll mod = 1000000007;
const double PI = 3.141592653589793238460;
const int INF = 1e9+5;

ll power(ll x, ll y)
{
    ll res = 1;
    x = x%mod;
    while (y)
    {
        if (y&1) res = ((res%mod)*(x%mod))%mod;

        y>>=1;
        x = ((x%mod)*(x%mod))%mod;
    }
    return res;
}

int main(){

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

    int n, a, b, c;
    cin >> n;    
    vector<int> dp(3);

    for(int i=1; i<=n; i++){
        vector<int> new_dp(3);
        vector<int> temp(3);
        cin >> temp[0] >> temp[1] >> temp[2];
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(i!=j){
                    new_dp[i] = max(new_dp[i],dp[j] + temp[j]);
                }
            }
        }
        dp = new_dp;
    }

    cout<<max(dp[0],max(dp[1],dp[2]))<<'\n';

    return 0;
}

Measured memory_bytes: 3664
#!/usr/bin/env python3

S = input()
s_list = list(S)
w_list = [0]
min_n = 0
s_l = len(s_list)
totsu_list = [False]

if s_list[0] == "<":
    ou_list = [True]
else:
    ou_list = [False]

t_list = []
if ou_list[0]:
    t_list = ["ou"]
else:
    t_list = ["totsu"]

for i, char in enumerate(s_list):
    # 凹であるかどうか
    is_ou = False
    is_totsu = False
    if i == s_l - 1:
        if char == ">":
            is_ou = True
    else:
        if s_list[i] == "<" and s_list[i + 1] == ">":
            is_totsu = True
        elif s_list[i] == ">" and s_list[i + 1] == "<":
            is_ou = True

    ou_list.append(is_ou)
    totsu_list.append(is_totsu)
    if is_ou:
        t = "ou"
    elif is_totsu:
        t = "totsu"
    elif char == "<":
        t = "up"
    else:
        t = "down"
    t_list.append(t)

    if char == "<":
        w_list.append(w_list[i] + 1)
    else:
        w_list.append(w_list[i] - 1)
        min_n = min(w_list[i] - 1, min_n)

x_list = []
d = abs(min_n)
w_len = len(w_list)
for i, w in enumerate(w_list):
    t = t_list[i]
    if t == "ou":
        x = 0
    elif t == "up" or i == w_len - 1:
        x = x_list[i - 1] + 1
    else:
        x = w_list[i] + d
    x_list.append(x)

x_len = len(x_list)
y_list = x_list[:]

total = 0

for i in range(x_len):
    idx = x_len - (i + 1)
    t = t_list[idx]
    if t == "down":
        y_list[idx] = y_list[idx + 1] + 1
    elif t == "ou" or t == "down":
        pass
    elif t == "totsu":
        if idx == 0 or idx == x_len:
            pass
        else:
            a = y_list[idx - 1]
            b = y_list[idx + 1]
            y_list[idx] = max(a, b) + 1
    total += y_list[idx]

if len(y_list) >= 3:
    if t_list[0] == "totsu":
        total -= y_list[0]
        total += y_list[1] + 1
    if t_list[-1] == "totsu":
        total -= y_list[-1]
        total += y_list[-2] + 1

# ans = sum(z_list)
ans = total
print(ans)


Measured memory_bytes: 79296
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;


int main() {

    double r;
    cin >> r;

    // 12 * sin(30°)  * r * r * 2 = 6 * r * r * sin(30)
    double answer = 6 * r * r * sin(30 * M_PI / 180.0);
    cout << answer << endl;

    return 0;
}

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

    #define all(v) v.begin(),v.end()
    #define rall(v) v.rbegin(),v.rend()
    #define trav(i,a) for(auto i: a)
    #define ff first
    #define ss second
    #define pb push_back
    #define tc(t) ll t; cin>>t; while(t--)
    #define prec(n) fixed<<setprecision(n)
    #define mst(arr,value) memset(arr,value,sizeof(arr))
    #define sz(a) a.size()
    #define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    
    const long long inf = (long long)1e18;
    const long long M = (long long)1e9+7;
    
    #define fab(i,a,b) for(ll i=a; i<b; i++)
    #define fba(i,b,a) for(ll i=b; i>=a; i--)

    ll mpw(ll a, ll b, ll M = inf) {
        if(b == 0) return 1;
        if(b % 2 == 1) 
            return a * mpw((a * a) % M, b / 2, M) % M;
        return mpw((a * a) % M, b / 2, M);        
    }    

    int main() {
        fio


        ll n;
        cin >> n;
        ll a[n][3], dp[n][3];
        
        fab(i, 0, n) 
            cin >> a[i][0] >> a[i][1] >> a[i][2];
        
        dp[0][0] = a[0][0];
        dp[0][1] = a[0][1];
        dp[0][2] = a[0][2];

        fab(i, 1, n) {
            dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0];
            dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1];
            dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + a[i][2];
        }

        cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
        
        return 0;
    }

Measured memory_bytes: 8212
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mp make_pair
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
class Edge {
public:
    ll t;
    ll w;
    Edge() {}
    Edge(ll t, ll w): t(t), w(w) {}
};


int main(void) {
    ll N, T;
    cin >> N >> T;
    ll i;
    ll c, t, ans=INF;
    for(i=0; i<N; i++) {
        cin >> c >> t;
        if(t<=T) {
            ans=min(ans, c);
        }
    }
    
    if(ans==INF) {
        cout << "TLE" << endl;
    }else {
        prin(ans);
    }
    
}

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

inline ll gsc(ll a,ll b,ll p)
{
    ll ans=0;
    while(b)
    {
        if(b&1) ans=(ans+a)%p;
        a=(a+a)%p;
        b>>=1;
    }
    return ans%p;
}

inline ll qp(ll a,ll b,ll p)
{
    ll res=1;
    while(b)
    {
        if(b&1) { res=gsc(res,a,p); }
        a=gsc(a,a,p);
        b>>=1;
    }
    return res%p;
}

inline ll ol(ll x)
{
    ll res=x;
    for(ll i=2;i*i<=x;i++)
    {
        if(x%i==0)
        {
            res=res/i*(i-1);
            while(x%i==0) x/=i;
        }
    }
    if(x!=1) res=res/x*(x-1);
    return res;
}

int main()
{
    ll l;
    ll ans;
    scanf("%lld",&l);
    ll t=__gcd(7ll,l);
    ll c=9ll*l/t;
        if(__gcd(c,10ll)!=1)
        {
            printf("-1\n");
        }
        else
        {
            ll cnt=ol(c);
            ll ans=cnt;
            for(ll i=1;i*i<=cnt;i++)
            {
                if(cnt%i==0)
                {
                    if(qp(10ll,i,c)==1)     ans=min(ans,i);
                    if(qp(10ll,cnt/i,c)==1) ans=min(ans,cnt/i);
                }
            }
            printf("%lld\n",ans);
        }
    return 0;
}

Measured memory_bytes: 3824
#include <stdio.h>

int main()
{
  int n, a;
  int last_a = 1000000000;
  int min = 0;

  scanf("%d", &n);
  int max = n;
  
  while (n--) {
    scanf("%d", &a);
    if (a <= last_a) min++;
    last_a = a;
  }

  printf("%d\n%d\n", min, max);

  return 0;
}
  



Measured memory_bytes: 2140
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll a, b;
  cin >> a >> b;
  string ans = "Odd";
  if ((a * b) % 2 == 0) {
    ans = "Even";
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long 
#define pb push_back
#define fo(i,N) for(int i = 0 ; i < N ; i++)
#define foo(i,x,N) for (int i = x; i < N ; i++)
#define fill(a,val) memset(a,val,sizeof(a))
#define fastio()  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define MAX 1234567
#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define all(a) a.begin(),a.end()
int dp[100005];
int arr[100005];
int n;

ll solve(int i )
{ 
  if ( i >= n)
    return INT_MAX;

  if ( i == n-1)
  {
    return 0;
  }

  if ( dp[i] != -1)
    return dp[i];

  dp[i] = min(solve(i+1)+abs(arr[i+1]-arr[i]),solve(i+2)+abs(arr[i+2]-arr[i]));

  return dp[i];


}

int main()
{ 
  cin >> n;
  fo(i,n)
  cin >> arr[i];
  fill(dp,-1);

  cout << solve(0) << endl;
 
        

}

    

  




Measured memory_bytes: 2560
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    map<string, int> S;
    int N, i, maxnum=0;
    string str;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> str;

        S[str]++; // strが出てきた回数を増やす
    }

    for(auto p : S){ // 出てきた回数の最大値を求める
        auto v = p.second;

        chmax(maxnum, p.second);
    }

    for(auto p : S){
        auto k = p.first;
        auto v = p.second;

        if(v == maxnum){ // 出てきた回数が最大だったとき
            cout << k << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 25216
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include <cassert>
using namespace std;

bool sosu(int n){
    bool flag = true;
    for(int i = 2; i < sqrt(n)+1; i++){
        if(n%i == 0){
            flag = false;
            break;
        }
    }
    return flag;
}

 
int main(){
    char c;
    cin >> c;
    c++;
    cout << c << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> xy;
    for(int i = 0;i < n;i++){
        int x, y;
        cin >> x >> y;
        xy.emplace_back(x, y);
    }
    double res = 0;
    for(int i = 0;i < n;i++){
        for(int j = i + 1;j < n;j++){
            res += hypot(xy[i].first - xy[j].first, xy[i].second - xy[j].second) * 2 / n;
        }
    }
    cout << setprecision(10) << res << endl;
    return 0;
}

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

using namespace std;

int main() {
    int r = 0, g = 0, b = 0, sum = 0;
    cin >> r >> g >> b;

    sum = 100 * r + 10 * g + b;

    if (sum % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;int l(string a,string b){int m=a.size(),n=b.size(),i=0,j,s=0,c[1001][1001]={};for(a=' '+a,b=' '+b;++i<=m;)for(j=0;++j<=n;s=s<c[i][j]?c[i][j]:s)c[i][j]=a[i]==b[j]?c[i-1][j-1]+1:c[i-1][j]>c[i][j-1]?c[i-1][j]:c[i][j-1];return s;}main(){string a,b;int n;for(cin>>n;n--;cin>>a>>b,cout<<l(a,b)<<endl);}

Measured memory_bytes: 7128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int t = sc.nextInt();

		int a = sc.nextInt();

		int b = sc.nextInt();

		int priceA = a * t;

		int priceB = b;

		if (priceA < priceB) {
			System.out.println(priceA);
		} else {
			System.out.println(priceB);
		}

	}

}


Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

int main() {
  //
  string s;
  ll k;
  cin >> s;
  cin >> k;
  vl gpcnt;
  char curch = s[0];
  ll curcnt = 1;
  REP(i, 1, s.size()) {
    if (curch == s[i]) {
      curcnt++;
    } else {
      gpcnt.emplace_back(curcnt);
      // cerr << "+" << curcnt << endl;
      curch = s[i];
      curcnt = 1;
    }
  }
  // cerr << "+" << curcnt << endl;
  gpcnt.emplace_back(curcnt);
  ll ans = 0;
  if (s[0] == s[s.size() - 1]) {
    if (gpcnt.size() == 1) {
      ans += gpcnt[0] * k / 2;
    } else {
      REP(i, 1, gpcnt.size() - 1) {
        // cerr << gpcnt[i] / 2 << endl;
        ans += (gpcnt[i] / 2) * k;
      }
      ans += gpcnt[0] / 2;
      ans += (gpcnt[0] + gpcnt[gpcnt.size() - 1]) / 2 * (k - 1);
      ans += gpcnt[gpcnt.size() - 1] / 2;
    }
  } else {
    for (auto& c : gpcnt) {
      ans += (c / 2) * k;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const int inf = 1001001001;

int main()
{
  int n, m; cin >> n >> m;
  vector<int> a(m);
  vector<int> c(m);
  rep(i, m) {
    int b; cin >> a[i] >> b;
    rep(j, b) {
      int t; cin >> t; t--;
      c[i] |= (1<<t);
    }
  }

  vector<int> dp(1<<n, inf);
  dp[0] = 0;
  for (int i=0; i<m; i++) {
    for (int bits=0; bits<(1<<n); bits++) {
      dp[bits|c[i]] = min(dp[bits|c[i]], dp[bits]+a[i]);
    }
  }

  if (dp[(1<<n)-1] == inf) cout << -1 << endl;
  else cout << dp[(1<<n)-1] << endl;

  return 0;
}


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

void solve(ll W, ll H, ll x, ll y){
    double ans1 = 0;
    ll ans2 = 0;
    ans1 = double(W) * double(H) / 2;
    ans2 = (x + x == W) && (y + y == H);
    cout << fixed << setprecision(6);
    cout << ans1 << " ";
    cout << fixed << setprecision(0);
    cout << ans2 << endl;
}

int main(){
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    solve(W, H, x, y);
    return 0;
}


Measured memory_bytes: 256
s = list(input())
s1 = []
s2 = []
for i in range(len(s)):
    if i % 2 == 0:
        s1.append('0')
        s2.append('1')
    else:
        s1.append('1')
        s2.append('0')
min_1 = 0
#for i in range(2):
for i in range(len(s)):
    if s[i] != s1[i]:
        min_1 += 1
        
min_2 = 0
for i in range(len(s)):
    if s[i] != s2[i]:
        min_2 += 1
print(min(min_1, min_2))

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

using namespace std;

int main(){
  int n,k,i,j,l,c=1;
  vector <int> v;
  
  cin>>n>>k;
  for(i=0;i<n;i++){
    j=c+k;l=c*2;
    if(j>l)
      c=l;
    else
      c=j;
  }
  cout<<c<<endl;
  return 0;
  
}

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

enum{TURN,QUEST};
struct Event{
    int type;
    int t,a;
};
int x;

struct State{
    int lh,lp;
    int rh,rp;
    int pre;
    bool upperA;
    void go(int t){
        int diff=t-pre;
        if(upperA){
            if(rh-diff<0){
                lh=rh=0;
                lp=rp=0;
            }
            else{
                if(lh-diff<0){
                    lp+=-(lh-diff);
                    lh=0;
                    rh-=diff;
                }
                else{
                    lh-=diff;
                    rh-=diff;
                }
            }
        }
        else{
            if(lh+diff>x){
                lh=rh=x;
                lp=rp=0;
            }
            else{
                if(rh+diff>x){                    
                    rp-=rh+diff-x;
                    rh=x;
                    lh+=diff;
                }
                else{
                    lh+=diff;
                    rh+=diff;
                }
            }
        }
        pre=t;
        //cout<<"#"<<t<<" "<<endl;
        //cout<<lp<<" "<<lh<<" "<<rp<<" "<<rh<<endl;
    }
    void flip(){
        upperA=!upperA;
    }

    int getHeight(int a){
        if(a<lp){
            return lh;
        }
        if(a>rp){
            return rh;
        }
        return lh+a-lp;
    }
};


int main(){
    cin>>x;
    int k;
    cin>>k;
    vector<int> r(k);
    for(auto &e:r) cin>>e;
    int q;
    cin>>q;
    vector<int> t(q),a(q);
    for(int i=0;i<q;i++){
        cin>>t[i]>>a[i];
    }

    vector<Event> events;
    for(int i=0;i<k;i++){
        events.push_back(Event{TURN,r[i],-1});
    }
    for(int i=0;i<q;i++){
        events.push_back(Event{QUEST,t[i],a[i]});
    }

    auto comp=[](const Event& lhs,const Event& rhs){
        return lhs.t<rhs.t;
    };
    sort(events.begin(),events.end(),comp);
    State st=State{0,0,x,x,0,true};

    for(int i=0;i<events.size();i++){
        if(events[i].type==TURN){
            st.go(events[i].t);
            st.flip();
        }
        else{
            st.go(events[i].t);
            cout<<st.getHeight(events[i].a)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1<<29;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)

int main(){
    int D, G, p[11], c[11]; cin >> D >> G;
    rep(i, D) cin  >> p[i] >> c[i];

    int ans = INF;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        rep(i, D){
            if(mask & (1<<i)){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            } else  {
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            String str = scan.nextLine();
            str = str.replaceAll("apple","------");
            str = str.replaceAll("peach","apple");
            str = str.replaceAll("------","peach");
            System.out.println(str);
        }
    }
}

Measured memory_bytes: 17136
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class WeightedUnionFind {
    int[] parent;
    long[] weightDiff;
    int count;

    public WeightedUnionFind(int size) {
        var b = new int[size];
        for (int i = 0; i < b.Length; i++) {
            b[i] = -1;
        }
        parent = b;
        weightDiff = new long[size];
        count = size;
    }

    int Find(int x) {
        if (parent[x] < 0) {
            return x;
        }
        else {
            var r = Find(parent[x]);
            weightDiff[x] += weightDiff[parent[x]];
            return parent[x] = r;
        }
    }

    long Weight(int x) {
        Find(x);
        return weightDiff[x];
    }

    public long Diff(int x, int y) => Weight(y) - Weight(x);

    public bool Same(int x, int y) => Find(x) == Find(y);

    public void Unite(int x, int y, long w) {
        w += weightDiff[x] - weightDiff[y];
        x = Find(x);
        y = Find(y);
        if (x == y) return;
        count--;
        if (parent[x] > parent[y]) {
            parent[y] += parent[x];
            parent[x] = y;
            weightDiff[x] = -w;
        }
        else {
            parent[x] += parent[y];
            parent[y] = x;
            weightDiff[y] = w;
        }
    }

    public int Size(int x) => -parent[Find(x)];

    public int Count() => count;
}
class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        int N = cin.Int();
        int M = cin.Int();

        var uf = new WeightedUnionFind(N);
        for (int i = 0; i < M; i++) {
            int L = cin.Int() - 1;
            int R = cin.Int() - 1;
            long D = cin.Long();
            if(uf.Same(L, R)) {
                if(uf.Diff(L, R) != D) {
                    Console.WriteLine("No");
                    return;
                }
            }
            else {
                uf.Unite(L, R, D);
            }
        }

        Console.WriteLine("Yes");
        Console.ReadLine();
    }
}

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

int bitCount(int i) {
  i = i - ((i >> 1) & 0x55555555);
  i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
  i = (i + (i >> 4)) & 0x0f0f0f0f;
  i = i + (i >> 8);
  i = i + (i >> 16);
  return i & 0x3f;
}

int main(void){
   int N,M;
   cin >> N >> M;
   
   int swt[M];
   for(int i=0;i<M;i++){
       swt[i] = 0;
   }
   
   
   int k,s;
   for(int i=0;i<M;i++){
       cin >> k;
       for(int j=0;j<k;j++){
           cin >> s;
           swt[i] += 1 << (s-1);
       }
   }
   
   int p[M];
   for(int i=0;i<M;i++){
       cin >> p[i];
   }
   
   int dam,ans = 0;
   for(int state = 0;state<pow(2,N);state++){
       bool allon = true;
       //各電球がついているか否か
       for(int i=0;i<M;i++){
           dam = state & swt[i];
           if(bitCount(dam)%2 != p[i]){
               allon = false;
               break;
           }
       }
       
       if(allon) ans++;
   }
   
   
   cout << ans << endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, x) = (v[0] as usize, v[1]);
    let l = read_vec::<i64>();
    let mut d = vec![0; n + 1];
    for i in 0..n {
        d[i + 1] = d[i] + l[i];
    }
    debug!(d);
    let ans = d.iter().filter(|&&i| i <= x).count();
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2132
function main(e){const r=parseInt(e),n=Math.sqrt(r);if(r<10)return"Yes";if(n>=10)return"No";if(Number.isInteger(n))return"Yes";const t=[];for(let e=2;e<r&&e<10;e++){r%e||t.push(e)}return t.some(e=>t.some(n=>{if(e*n===r)return!0}))?"Yes":"No"}console.log(main(require("fs").readFileSync("/dev/stdin","utf8")));

Measured memory_bytes: 9420