akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

signed main(){
  int a, b;cin>>a>>b;
  cout << (a*b%2 == 0 ? "Even" : "Odd") << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main (void) {
    int N;

    cin >> N;
    int C[N - 1];
    int S[N - 1];
    int F[N - 1];
    for (int i = 0; i < N - 1; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }

    for (int i = 0; i < N - 1; i++) {
        int ans = S[i] + C[i];
        for (int j = i + 1; j < N - 1; j++) {
            if (ans <= S[j]) {
                ans = S[j];
            } else {
                int tmp = S[j];
                while (tmp < ans) {
                    tmp += F[j];
                }
                ans = tmp;
            }
            ans += C[j];
        }
        cout << ans << endl;
    }
    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
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()
}

fn digit_sum(n: u32) -> u32 {
    let mut res = n;
    let mut ret = 0;
    while res > 0 {
        ret += res % 10;
        res /= 10;
    }
    ret
}

fn main() {
    let n: u32 = read();
    let ds = digit_sum(n);
    if n % ds == 0 {
        println!("Yes");
    } else {
        println!("No");
    }

}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;

    vector<int> l(n);

    for(int i = 0; i < n; i++){
        cin >> l.at(i);
    }

    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());

    long long ans = 0;

    for(int i = 0; i < n-2; i++){
        for(int j = i+1; j < n-1; j++){
            if(l[i] > 2*l[j]){
                break;
            }
            for(int k = j+1; k < n; k++){
                if(l[i] < l[j] + l[k]){
                    ans++;
                }else{
                    break;
                }
            }
        }
    }

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

Measured memory_bytes: 384
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
//using
using namespace std;
/*using vi = vector <int>;
using vs = vector <string>;
using vc = vector <char>;*/
//vector<vector<char> > hyou(N, vector<char>(N));
//define
#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
//グローバル変数宣言
int a=0,b=0,c=0,d=0,n;

signed main(){
    cin>>n;
    vector<int>A(n);
    rep(i,n)cin>>A[i];
    sort(A.rbegin(),A.rend());
    rep(i,n){
        if(i%2==0){
            a+=A[i];
        }else b+=A[i];
    }
    cout<<a-b<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

int main() {
  int n,h[110000], ma[110000];
  cin >> n;
  
  for(int i = 0; i < n; i++) {
    cin >> h[i];
    ma[0] = h[0];
    if(i > 0) ma[i] = max(ma[i-1], h[i]);
    
    if(h[i] < ma[i] - 1) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 4432
a,b,c = map(int,input().split())
# if a**2+b**2+c**2 - 2*c*(a+b) - 6*a*b > 0:
#     print('Yes')
# else:
#     print('No')
if a+b >= c:
    print('No')
    exit()
if 4*a*b < (c-a-b)**2:
    print('Yes')
else:
    print('No')


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

int main()
{
  int n; cin >> n;
  vector<int> t(n);
  REP(i, n) cin >> t.at(i);

  int m; cin >> m;
  vector<int> p(m);
  vector<int> x(m);
  REP(i, m) cin >> p.at(i) >> x.at(i);

  REP(i, m) {
    int sum = 0;
    vector<int> t_(n);
    t_ = t;
    t_.at(p.at(i) - 1) = x.at(i);
    sum = accumulate(t_.begin(), t_.end(), 0);
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n,p1=0,p2=0;
    string str1,str2;
     
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> str1 >> str2;
        if(str1 > str2)p1 += 3;
        if(str2 > str1)p2 += 3;
        if(str2 == str1){p1 += 1; p2 += 1;}
    }
    cout << p1 << " " << p2 << endl;
}


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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
long long a , b ;

long long LCM(long long x , long long y)
{
	return (x / __gcd(x , y) * y) ;
}

long long calc(long long x)
{
	return (b / x - (a-1ll) / x) ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	long long x , y ;
	cin>>a>>b>>x>>y ;
	return cout<<(b-a+1ll) - calc(x) - calc(y) + calc(LCM(x , y))<<"\n" , 0 ;
}		

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

using namespace std;

using ll = long long;

int main(){
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = a * x + b * y;
    ll ans1 = max(x, y) * 2 * c;
    ll ans2;
    if (x < y){
        ans2 = x * 2 * c + (y - x) * b;
    }
    else{
        ans2 = y * 2 * c + (x - y) * a;
    }

    cout << min(min(ans, ans1), ans2) << endl;
}


Measured memory_bytes: 256
# UnionFind、0-indexであることに注意
#############################################################


class UnionFind:

    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, v):  # vが属する集合の根を返す
        if self.parents[v] < 0:
            return v
        else:
            self.parents[v] = self.find(self.parents[v])
            return self.parents[v]

    def unite(self, u, v):  # 「uが属する集合」と「vが属する集合」を併合（根同士を結ぶ）
        u = self.find(u)
        v = self.find(v)
        if u == v:
            return
        if self.parents[u] > self.parents[v]:  # u < v に統一する
            u, v = v, u
        self.parents[u] += self.parents[v]
        self.parents[v] = u

    def size(self, v):  # vが属する集合の要素数
        return -self.parents[self.find(v)]

    def same(self, u, v):  # uとvが同じ集合に属するか否か
        return self.find(u) == self.find(v)
#############################################################


N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)

ans = 1
for i in range(N):
    s = uf.size(i)
    ans = max(ans, s)

print(ans)


Measured memory_bytes: 79984
#include <iostream>
using namespace std;
int main(){
	string str,cmd,p;
	int cmd_num,a,b;
	cin>>str>>cmd_num;
	for(int i=0;i<cmd_num;i++){
		cin>>cmd>>a>>b;
		if(cmd=="print"){
			cout<<str.substr(a,b-a+1)<<endl;
		}else if(cmd=="reverse"){
			while(a<b){
				char tmp;
				tmp=str[a];
				str[a]=str[b];
				str[b]=tmp;
				a++;b--;
			}
		}else if(cmd=="replace"){
			cin>>p;
			str.replace(a,b-a+1,p);
		}
	}
	return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>

int main(){
  int n;
  long a, max=-1000000, min=1000000, sum=0, i;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%ld",&a);
    sum+=a;
    if(a>max) max=a;
    if(a<min) min=a;
  }

  printf("%ld %ld %ld\n",min,max,sum);
  return 0;
}



Measured memory_bytes: 2148
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxW = sc.nextInt();
		
		int[] w = new int[n + 1];
		int[] v = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
		}
		
		long[][] dp = new long[n + 1][maxW + 1];
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= maxW; j++) {
				dp[i][j] = dp[i - 1][j];
				if (j - w[i] >= 0)
					dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
			}
		}
		
		System.out.println(dp[n][maxW]);
//		for (int i = 0; i <= n; i++)
//			System.out.println(Arrays.toString(dp[i]));
				
		sc.close();
	}
}



Measured memory_bytes: 131760
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		StringBuilder s = new StringBuilder();
		int i = 0;
		for (char ch : sc.next().toCharArray()) {
			if (i==0) s.append(ch);
			i+=(i==1) ? -1 : 1;
		}
		System.out.println(s);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 39032
n = int(input())
p = list(map(int,input().split()))
a = 0
b = 0
for i in range(n):
    a += p[i]
    b += p[i] ** 2

a = a ** 2
k = (a-b) // 2 % (10 ** 9 + 7)

print(k)

Measured memory_bytes: 31556
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

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

	for (int i = 0;i < s.length();i++) {
		printf("x");
	}

	return 0;
}

//AAAAAAAAAAAA
//int main() {
//	string s, t, u;
//	int a, b;
//	cin >> s >> t >> a >> b >> u;
//
//	if (s == u)a--;
//	else b--;
//
//	cout << a << " " << b << endl;
//	return 0;
//}

Measured memory_bytes: 3592
import Debug.Trace

main :: IO ()
main = do
  ss <- getLine 
  let ans = solve $ zip [0..] ss
  print $ sum ans
  putStrLn $ unwords $ map show $ length ans : (reverse ans)


solve :: [(Int, Char)] -> [Int]
solve input = go [] [] input
  where
    go :: [(Int, Char)] -> [(Int, Int)]
      -> [(Int, Char)] -> [Int]
    go _ ns [] = map snd ns
    go [] ns (x:xs)
      | snd x == '\\' = go [x] ns xs
      | snd x == '/' = go [] ns xs
      | otherwise = go [] ns xs
    go stack@(s:ss) ns (x:xs)
      | snd x == '\\' = go (x:stack) ns xs
      | snd x == '/' = go ss next xs
      | otherwise = go stack ns xs
      where
        (hd, tl) = span (\(loc, _) -> loc >= fst s) ns
        miz = (fst s, sum (map snd hd) + (fst x - fst s))
        next = miz : tl

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

int n;
int buf = -1;
int c = 0;

int main(){
    cin >> n;
    for(int i = 0; i < 4; i++){
        if(buf == n % 10){
            c++;
            if(c == 2){
                cout << "Yes" << endl;
                return 0;
            }
        }else{
            c = 0;
            buf = n % 10;
        }
        n = n/10;
    }
    cout << "No" << endl;
    return 0;
}

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

int main(){
    int N;
    char c;
    char alpha[10]={'.','.','a','d','g','j','m','p','t','w'};
    char alpha1[5]={' ','.',',','!','?'};
    cin>>N;
    getchar();
    while(N--){
        int cnt=0,before,now=0;
        while(c=getchar(),c!='\n'){
            before = now;
            now = c-'0';
            //printf("before=%d , now=%d\n",before,now);
            if(now!=0)cnt++;
            else if(before==1){
                printf("%c",alpha1[cnt%5]);
                cnt=0;
            }else if(before!=0){
                printf("%c",alpha[before]+(cnt-1)%(before==7||before==9 ? 4 : 3));
                cnt=0;
            }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <vector>
using namespace std;
static const int MAXN = 100000 + 10;

struct TreeNode{
    vector<int> sons;
} trees[MAXN];

int dfs(int root, int fa) {
    int val = 0;
    for (int son : trees[root].sons) {
        if (son == fa) continue;
        val ^= (dfs(son, root) + 1);
    }
    return val;

}

int main() {
//    freopen("test.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    int x, y;
    for (int i = 1; i < n; i++) {
        scanf("%d%d", &x, &y);
        trees[x].sons.push_back(y);
        trees[y].sons.push_back(x);
    }
    int val = dfs(1, 0);
    if (val != 0) {
        cout << "Alice" << endl;
    }
    else cout << "Bob" << endl;



    return 0;
}

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

using namespace std;

int main() {
    vector<int> a(9);
    for (int i = 0; i < 9; ++i) {
        cin >> a[i];
    }

    int N;
    cin >> N;
    vector<int> b(9);
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        for (int j = 0; j < 9; ++j) {
            if (a[j] == x) b[j] = 1;
        }
    }

    if (b[0] + b[1] + b[2] == 3 or
        b[3] + b[4] + b[5] == 3 or
        b[6] + b[7] + b[8] == 3 or
        b[0] + b[3] + b[6] == 3 or
        b[1] + b[4] + b[7] == 3 or
        b[2] + b[5] + b[8] == 3 or
        b[0] + b[4] + b[8] == 3 or
        b[2] + b[4] + b[6] == 3) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int i=0,n=0,x,a,b,d=0;
  scanf("%d %d %d",&x,&a,&b);
  x=x-a;
  do{
     x=x-b;
  }while(x>=b);
  printf("%d",x);
  return 0; 
}

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

int main()
{
    int n; cin >> n;
    vector<int> v(2*n);
    for(int i=0; i<2*n; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int niku = 0;
    for(int i=0; i<2*n; i+=2){
        niku+=v[i];
    }
    cout << niku << endl;
    return 0;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n;
string s[1000006];
vii neg,pos;
vi tr;
void solve(){
	cin>>n;
	string w;
	rep(i,0,n){
		cin>>s[i];
		int cur=0,res=hell;
		for(auto j:s[i]){
			if(j=='(') cur++;
			else cur--;
			res=min(res,cur);
		}
		if(res<0){
			if(cur>0) pos.pb({res,i});
			else if(cur<0) neg.pb({res-cur,i});
			else    tr.pb(i);
		}
		else w+=s[i];
	}
	sort(all(pos));
	reverse(all(pos));
	sort(all(neg));
	for(auto i:pos) w+=s[i.y];
	for(auto i:tr) w+=s[i];
	for(auto i:neg) w+=s[i.y];
	int cur=0;
	for(auto i:w){
		if(i=='(') cur++;
		else cur--;
		if(cur<0){
			cout<<"No"<<endl;
			return;
		}
	}
	if(cur) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 41216
#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 N;
  cin >> N;
  vector<ll> A(N);
  for_each(begin(A), end(A), [](auto& x) { cin >> x; });

  ll num = 1;
  ll count = 0;
  bool breaking = false;
  for (ll i = 0; i < N; i++) {
    if (A[i] == num) {
      count++;
      num++;
      breaking = true;
    }
  }
  if (!breaking) {
    cout << -1 << endl;
  } else {
    cout << N - count << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>


int main()
{
	int n,m,a,verline,num;
	int hline[1000][3],HLINE[1000][3];
	
	while(1)
	{
		scanf("%d %d %d",&n,&m,&a);
		verline=a;
		num=0;
		if(n!=0 && m!= 0 && a!=0)
		{
			for(int i=0;i<m;i++)
			{
				scanf("%d %d %d",&hline[i][0],&hline[i][1],&hline[i][2]);
			}
			for(int i=1000;i>=0;i--)
			{
				for(int t=0;t<m;t++)
				{
					if(hline[t][0]==i)
					{
						HLINE[num][0]=hline[t][0];
						HLINE[num][1]=hline[t][1];
						HLINE[num][2]=hline[t][2];
						num++;
					}
				}
			}
			for(int i=0;i<m;i++)
			{
				if(HLINE[i][1]==verline) verline=HLINE[i][2];
				else if(HLINE[i][2]==verline) verline=HLINE[i][1];
			}
			printf("%d\n",verline);
		}
		else break;
	}
	
	return 0;
}


Measured memory_bytes: 2628
K, A, B = map(int, input().split())
if B - A < 2:
    print(K + 1)
elif K < A - 1:
    print(K + 1)
else:
    K -= (A - 1)
    if (K % 2 == 0):
        ans = (B - A) * (K // 2) + A
    else:
        ans = (B - A) * (K // 2) + A + 1
    print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1.0), EPS = 1e-9;
const int MX=2*1e5 + 10;
int N, Q, M, k;
int arr[MX];
int main()
{
    ll a, b, c;
    cin>>a>>b>>c;
    cout<<min(a*b, c);
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];

    }

    int sum = 0;
    int m = 0;
    for(int i = 0; i < n - 1; ++i) {
        sum += abs(a[i] - a[i + 1]);
        m = max(m, abs(a[i] - a[i + 1]));

    }
    sum += k - a[n - 1];
    sum += a[0];
    m = max(m, k - a[n - 1] + a[0]);
    cout << sum - m << endl;
    return 0;
}



Measured memory_bytes: 1024
def prime(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for j in range(4, n+1, 2):
        is_prime[j] = False
    
    for i in range(3, int(n**0.5) + 1, 2):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(n+1):
        if i % 5 != 1:
            is_prime[i] = False
    return [i for i in range(n + 1) if is_prime[i]]

n = int(input())
k = prime(1500)
for i in range(n):
    print(k[i], end=" ")

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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, l, t;
	cin >> n >> l >> t;
	vector<int> x(n), w(n), pos(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> w[i];
		if (w[i] == 1) {
			pos[i] = (x[i] + t % l) % l;
		} else {
			pos[i] = (x[i] - t % l + l) % l;
		}
	}

	int sum = 0;
	for (int i = 1; i < n; i++) {
		if (w[i] == w[0]) continue;
		sum += 2 * t / l;
		if (w[0] == 1) {
			sum += ((x[i] + l - x[0]) % l < 2 * t % l);
		} else {
			sum += ((x[0] + l - x[i]) % l < 2 * t % l);
		}
	}

	int tar = pos[0];
	int idx;
	if (w[0] == 1) {
		idx = sum % n;
	} else {
		idx = (n - sum % n) % n;
	}

	sort(pos.begin(), pos.end());

	int sidx;
	for (int i = 0; i < n; i++) {
		if (pos[i] == tar) {
			sidx = i;
			if (i + 1 < n && pos[i + 1] == tar && w[0] == 2) sidx = i + 1;
			break;
		}
	}

	vector<int> ans(n);
	for (int i = 0; i < n; i++) {
		ans[(idx + i) % n] = pos[(sidx + i) % n];
	}

	for (int x : ans) cout << x << endl;

	return 0;
}

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

long long dp[100010][2];
long long INF = -100000000000000;

long long max(long long a, long long b) {
  return a > b ? a : b;
}

int main() {
  int N;
  cin >> N;
  vector<long long> a(N);
  
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  dp[0][0] = 0;
  dp[0][1] = INF;
  
  for (int i = 0; i < N; i++) {
    dp[i+1][0] = max(dp[i][0]+a[i], dp[i][1]-a[i]);
    dp[i+1][1] = max(dp[i][0]-a[i], dp[i][1]+a[i]);
  }

  cout << dp[N][0] << endl;

  return 0;
}

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

int main() {
	int N, M;
	static int T[100000] = {}, Par[100000] = {};
	static vector<int> V[100000];
	queue<int> Q;
	cin >> N >> M;
	for (int i = 0; i < N + M - 1; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		T[B]++;
		V[A].push_back(B);
	}
	for (int i = 0; i < N; i++) {
		if (T[i] == 0) Q.push(i);
	}
	while (!Q.empty()) {
		int P = Q.front();
		Q.pop();
		for (int NP : V[P]) {
			T[NP]--;
			if (T[NP] == 0) Q.push(NP), Par[NP] = P + 1;
		}
	}
	for (int i = 0; i < N; i++) {
		cout << Par[i] << endl;
	}
}

Measured memory_bytes: 7040
from heapq import heapify,heappop,heappush
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[-a[i] for i in range(n)]
heapify(b)
for i in range(m):
    a=heappop(b)
    heappush(b, -((-a)//2))
print(-sum(b))

Measured memory_bytes: 14180
#include<stdio.h>

int main(void)
{
	int i,x[3000],y[3000];
	
	for(i=0;i<=2999;i++){
		scanf("%d %d",&x[i],&y[i]);
		if(x[i]==0 && y[i]==0){
			break;
		}
	}
	for(i=0;i<=2999;i++){
		if(x[i]!=0 || y[i]!=0){
			if(x[i]<y[i]){
			printf("%d %d\n",x[i],y[i]);
			}else{
				printf("%d %d\n",y[i],x[i]);
			}	
		}else{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();


    set<string> st;
    for (int l = 1; l <= min(5, n); l++) {
        rep(i, n - l + 1) {
            string t = s.substr(i, l);
            st.insert(t);
        }
    }

    auto it = st.begin();
    rep(i, k - 1) it++;
    cout << *it << endl;

}


Measured memory_bytes: 4808
#include <stdio.h>

int main(void) {
    int n, x;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        x = i * 1.08;
        if (x == n) {
            printf("%d\n", i);
            return 0;
        }
    }
    printf(":(\n");
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] t = new int[n];
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++) {
			t[i] = sc.nextInt();
			a[i] = sc.nextInt();
		}
		
		sc.close();
		
		long t_now = t[0], a_now = a[0], t_next1 = 0, a_next1 = 0, t_next2 = 0, a_next2 = 0;
		
		for(int i = 1; i < n; i++) {
				if(t_now % t[i] == 0) {
					t_next1 = t_now;
					a_next1 = (t_next1/t[i])*a[i];
				} else {
					t_next1 = t_now + t[i] - t_now % t[i];
					a_next1 = (t_next1/t[i])*a[i];	
				}
				
				if(a_now % a[i] == 0) {
					a_next2 = a_now;
					t_next2 = (a_next2/a[i])*t[i];
				} else {
					a_next2 = a_now + a[i] - a_now % a[i];
					t_next2 = (a_next2/a[i])*t[i];	
				}
				
				if(t_now + a_now > t_next1 + a_next1 || t_now > t_next1 || a_now > a_next1) {
					t_now = t_next2;
					a_now = a_next2;
				} else if(t_now + a_now > t_next2 + a_next2 || t_now > t_next2 || a_now > a_next2) {
					t_now = t_next1;
					a_now = a_next1;
				} else if(t_next1 + a_next1 > t_next2 + a_next2) {
					t_now = t_next2;
					a_now = a_next2;
				} else {
					t_now = t_next1;
					a_now = a_next1;
				}
		}
		
		System.out.println(t_now + a_now);
		
		return;
	}
	
}

Measured memory_bytes: 13400
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int n, m;
string s, t;


ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	else return gcd(b, a%b);

}

ll lcm(ll a, ll b)
{
	return (a*b) / gcd(a, b);
}


int main()
{
	cin >> n >> m;
	cin >> s;
	cin >> t;

	ll l = lcm(n, m);
	/*
	if (n%m != 0 && m%n != 0) {
		if (s[0] == t[0]) cout << l << endl;
		else cout << -1 << endl;
		return 0;
	}
	else {
		if (n == m) {
			if (s == t)cout << n << endl;
			else cout << -1 << endl;
			return 0;
		}
		if (n < m) {
			int k = m / n;
			int ope = 0;
			for (int i = 0; i < n; i++) {
				if (s[i] != t[k*i])ope++;
			}
			if (ope == 0)cout << m << endl;
			else cout << -1 << endl;
			return 0;
		}
		if (n > m) {
			int k = n/m;
			int ope = 0;
			for (int i = 0; i < m; i++) {
				if (t[i] != s[k*i])ope++;
			}
			if (ope == 0)cout << n << endl;
			else cout << -1 << endl;
			return 0;
		}
	}
	*/

	ll a = l / n;
	ll b = l / m;
	ll c = lcm(a, b);
	//cout << a << " " << b << " " << c << endl;

	int ope = 0;
	for (ll i = 0; i <l; i+=c) {
		//cout << i << " " << i / a << " " << i / b << endl;
		if (s[i/a] != t[i/b])ope++;
	}
	if (ope == 0)cout << l << endl;
	else cout << -1 << endl;





	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main(){
    int n;cin >> n;
    vector<int> v(n);
    vector<int> c(n);
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    for(int i=0;i<n;i++){
        cin >> c[i];
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(v[i] > c[i]){
            ans += v[i] - c[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

    int a,b,N,K;

    cin >> N;
    cin >> K;

    b = N%2;
    if(b==1){
        a = N/2;
        a = a+1;
        if(K <= a){
            cout << "YES" << endl;
        }else{
            cout << "NO" <<endl;
        }
    }else{
        a = N/2;
        if(K <= a){
            cout << "YES" << endl;
        }else{
            cout << "NO" <<endl;
        }
    }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i =0; i < n; i++){
    cin >> d[i];
  }
  int ans = 0;
  for (int i = 0;i < n; i++){
    for (int j = i+1; j<n; j++){
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
}

  

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

int main(){

	long long a, n, m, R_ans, L_sum;
	int ans = 0, i = 1;

	cin >> a >> n >> m;

	R_ans = powl(i + a, n);

	while(R_ans <= m) {
		int  num = R_ans;
		L_sum = 0;

		//  各桁数の合計値を求める
		while(num > 0){
			L_sum += num % 10;
			num /=10;
		}

		//  左辺と右辺の式を比較
		if(R_ans == powl(L_sum+a,n)) ans++; 
		i++;
		R_ans = powl(i + a, n);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;

void solve() {
	char c;
	cin >> c;
	if (c - 'a' < 0) cout << 'A' << '\n';
	else cout << 'a' << '\n';
}

signed main() {
	int t = 1;
	while (t--) 
		solve();
}

Measured memory_bytes: 3640
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int inva[200'000];

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        int j;
        cin >> j;
        inva[j - 1] = i + 1;
    }

    int64_t result = 0;
    set<int> s;
    s.insert(0);
    s.insert(n + 1);

    rrep(i, n)
    {
        int64_t pnum = 0;
        auto ub = s.upper_bound(inva[i]);
        auto r0 = ub;
        ub--;
        auto l0 = ub;
        if (*r0 != n + 1) {
            auto rtmp = r0;
            rtmp++;
            auto r1 = rtmp;

            pnum += (inva[i] - *l0) * (*r1 - *r0);
        }
        if (*l0 != 0) {
            auto ltmp = l0;
            ltmp--;
            auto l1 = ltmp;

            pnum += (*r0 - inva[i]) * (*l0 - *l1);
        }

        result += pnum * (i + 1);

        s.insert(inva[i]);
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 5376
def main():
    n, c = map(int, input().split())
    xv = [list(map(int, input().split())) for _ in range(n)]
    v, left_max, right_max = 0, 0, 0
    gl = [None]*n
    gr = [None]*n
    _2oas = [None]*(n+1)
    _2obs = [None]*(n+1)
    _2oas[0], _2obs[0] = 0, 0
    ans = 0
    for i, (xi, vi) in enumerate(xv, 1):
        v += vi
        left = v - xi
        if left_max < left:
            left_max = left
        gl[n-i] = left_max
        _2oas[i] = v - 2*xi
    v = 0
    for i, (xi, vi) in enumerate(xv[::-1], 1):
        v += vi
        right = v - c + xi
        if right_max < right:
            right_max = right
        gr[n-i] = right_max
        _2obs[i] = v - 2*(c - xi)
    for oa, _2ob, ob, _2oa in zip(gl, _2obs[:n], gr, _2oas[:n]):
        ans = max(ans, _2oa+ob, _2ob+oa)
    print(ans)
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 73176
// ~maqsat~

#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)
#define ever ;;

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T>
inline void cmin (T &a, T b) {a = min(a, b);}
template<class T>
inline void cmax (T &a, T b) {a = max(a, b);}

const int oo = 0x3f3f3f3f;
const ll N = 1e2 + 123;
const ll MOD = 1e9 + 7;
const ll INF = 1e15 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

bool dp[N][10000];
main () {
#ifdef ZVER
    cerr << "Ready\n";
#endif
    fre("");
    ACCELERATE;

    int n;
    cin >> n;

    int a[N];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        dp[i][a[i]] = true;
        sum += a[i];
    }

    dp[0][0] = true;
    for (int i = 1; i < n; i++) {
        for (int s = 0; s <= sum; s++) {
            if (s >= a[i]) dp[i][s] |= (dp[i - 1][s - a[i]] | dp[i - 1][s]);
            else dp[i][s] |= dp[i - 1][s];
        }
    }

    for (int i = sum; i >= 0; i--) {
        if (i % 10 == 0) continue;
        if (dp[n - 1][i]) {
            cout << i << '\n';
            return 0;
        }
    }

    cout << "0\n";
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(string S) {
  string YAKI = "YAKI";
  bool pred = equal(ALL(YAKI),S.begin());
  cout << (pred ? YES : NO) << endl;
}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ll x; cin >> x;
    ll i = 1;
    vector<ll> s;
    s.push_back(0);
    while (1) {
        ll p = pow(i, 5);
        s.push_back(p);
        int lb = 0;
        int ub = (int)s.size();
        while (ub - lb > 1) {
            int mid = (lb + ub) / 2;
            if (s[mid] <= p - x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        if (s[lb] == p - x) {
            cout << i << ' ' << lb;
            return 0;
        }
        lb = 0;
        ub = (int)s.size();
        while (ub - lb > 1) {
            int mid = (lb + ub) / 2;
            if (s[mid] <= x - p) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        if (s[lb] == x - p) {
            cout << i << ' ' << -lb;
            return 0;
        }
        i++;
    }
    return 0;
}


Measured memory_bytes: 4048
// I make this just for fun because i'm done
// Aimi Haraguni >> Konomi Suzuki >> Yui >>  Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi.   .. dude? 
// problems that involves any kind of persistent data structures are the best of the best, are not them?
 
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
 
#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
 
#define N 31000000
// #define M 19
 
// #define mod  11092019
#define mod1 1000000007
#define mod2 1000000009
#define bas 987625403
#define sqr(x) (x)*(x)  
#define INF 2000000000000
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> S_t;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}

inline ll mul(ll a, ll b, ll mod) { return (long long) a*b%mod;}
inline ll add(ll a, ll b, ll mod) { return a+b < mod? a+b: a+b-mod;}
inline void Mul(ll &a, ll b, ll mod) { a = (long long) a*b%mod;}
inline ll bp(ll a, ll p, ll mod){
	ll ret;
	for(ret = 1; p; p>>=1, Mul(a, a, mod)) (p & 1) && (Mul(ret, a, mod), 1);
	return ret;
}

static inline ll get_num() {
    ll num = 0;
    char c = getchar_unlocked();
    while(!((c>='0') & (c<='9')))  c=getchar_unlocked();
    while(c>='0' && c<='9'){
        num = (num<<1)+(num<<3)+c-'0';
        c=getchar_unlocked();
    }
    return num;
}

static inline void read(ll &x) { x = get_num();}

ll cnt[1<<19];

int main(){
	ll n; read(n);
	ll top = sqrt(n);
	FER(i, 1, top+1) {
		FER(j, 1, top+1){
			FER(k, 1, top+1){
				ll ans = sqr(i) + sqr(j) + sqr(k) + i*(j+k) + j*k;
				cnt[ans]++;
			}
		}
	}
	FER(i, 1, n+1) cout<<cnt[i]<<"\n";
	return 0;
}

Measured memory_bytes: 4116
#include<bits/stdc++.h>
#include<vector>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,N) for(int i=0;i<N;i++)

using namespace std;

int main(void){
    int M,F,B;
    cin>>M>>F>>B;
    if(M+F<B){
        cout<<"NA"<<endl;
        return 0;
    }
    cout<<max(0,B-M)<<endl;

}




Measured memory_bytes: 3112
import Control.Monad
import Data.List

main = readLn >>= main'
    where
        main' n = getLine >>= print . solve' n . fmap read . words
        solve' n xs = minimum [solve b n xs | b <- [True, False]]

solve :: Bool -> Int -> [Int] -> Int
solve b c = fst' . foldl' ff (0, 0, b)
    where
        ff (acc, s, e) n
            | (next > 0 && e) || (next < 0 && not e) = (acc, next, not e)
            | next /= 0 = (acc + abs next + 1, negate next `div` abs next, not e)
            | e = (acc + 1, 1, not e)
            | otherwise = (acc + 1, -1, not e)
            where
                next = s + n

        fst' (a, _, _) = a
        


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    bool f = is_sorted(p.begin(), p.end());
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            auto tmp = p;
            bool check = true;
            swap(tmp[i], tmp[j]);
            for (int k = 1; k < n; k++)
                if (tmp[k - 1] > tmp[k])
                    check = false;
            if (check)
                f = true;
        }
    }
    cout << (f ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define m 1000000000000000000
#define sze 100000

using namespace std;
int main()
{

    long long  n,a[sze],flag=0;
    long double mul=1;


    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
}
sort(a,a+n);
     for(int i=0;i<n;i++)
    {
        mul=mul*a[i];
        if(mul>m)
        {
            flag=1;
            break;
        }


    }

    if(flag==1)
        cout<<"-1"<<endl;
    else
        cout<<((long long)mul)<<endl;

    return 0;

}


Measured memory_bytes: 4360
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: str):
    s = 0
    for i in N:
        s += int(i)


    if s %9 ==0 :
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)  # type: str
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 81532
N,K=map(int,input().split())
A=list(map(int,input().split()))
mod=10**9+7

micro=0
for i in range(N):
    for j in range(i):
        if A[i]<A[j]:
            micro+=1
A.sort()
macro=[0]
for i in range(1,N):
    if A[i-1]==A[i]:
        macro.append(macro[-1])
    else:
        macro.append(i)

ans=(micro*K+sum(macro)*K*(K-1)//2)%mod
print(ans)

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

namespace ITP1_2_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int temp;

            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);

            while (true)
            {
                if (a > b)
                {
                    temp = a;
                    a = b;
                    b = temp;
                }

                if (b > c)
                {
                    temp = b;
                    b = c;
                    c = temp;
                }

                if (a <= b && b <= c) break;
            }

            Console.WriteLine("{0} {1} {2}", a, b, c);
        }
    }
}



Measured memory_bytes: 17984
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs             v.size()
#define ss             s.size()
#define sot(v)       sort(v.begin(),v.end())
#define rev(v)       reverse(v.begin(),v.end())
#define pii             pair<int,int>
#define ll               long long
#define ull             unsigned long long
#define pb             push_back
#define mpp          make_pair
#define Okay         0

const int m = 10+10e7;
static ll int inf = 1e18;
using namespace std;


void  solve(){
      ll int k;
      int a,b,c;
      cin>>a>>b>>c;
      cin>>k;
      for(int i=0;i<k;i++){
        if(a>=b){
            b *= 2;
            continue;
        }
        if(b>=c){
            c*=2;
            continue;
        }
      }
      if(a<b && b<c)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;


}


int main() {
    Fast;

           solve();

    return Okay ;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=2;i<n;i++)
 
int main(void) {
  long long int a,b;
  cin >> a >> b;
  
  vector<int> mina;
  vector<int> minb;
  long long int minas = 0,minbs = 0;
  rep(i,a){
    if(a%i == 0){
      mina.push_back(i);
      minas++;
    }
  }
  rep(i,b){
    if(b%i == 0){
      minb.push_back(i);
      minbs++;
    }
  }

  long long int min = 0;
  for(int i=0;i<minas;i++){
    for(int j=0;j<minbs;j++){
      if(mina[i] == minb[j]){min = mina[i];}
    }
  }
  
  
  if(min == 0){cout << a*b << endl;}
  else if(a%b == 0){cout << a << endl;}
  else if(b%a == 0){cout << b << endl;}
  else{cout << a/min*b << endl;}
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;

int main() {
    ll n; cin >> n;
    ll ans = 0;

    if (n % 2 == 1) puts("0");
    else {
        ll cnt = 10;
        while (cnt <= n) {
            ans += n / cnt;
            cnt *= 5;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[5], b[5], i;
	
	a[4] = b[4] = 0;
	for (i = 0; i < 4; i++){
		scanf("%d", &a[i]);
		a[4] += a[i];
	}
	for (i = 0; i < 4; i++){
		scanf("%d", &b[i]);
		b[4] += b[i];
	}
	
	if (a[4] > b[4]){
		printf("%d\n", a[4]);
	}
	else {
		printf("%d\n", b[4]);
	}
	
	return 0;
}

Measured memory_bytes: 592
import sys


def solve():
    readline = sys.stdin.readline
    N, W = map(int, readline().split())
    WV = (map(int, readline().split()) for _ in range(N))
    INF = 10 ** 15
    MAX_V = 100 * 10**3 + 1
    dp = [INF] * MAX_V
    dp[0] = 0
    for w, v in WV:
        for i in range(MAX_V-1, v-1, -1):
            tmp_dp = dp[i-v] + w
            if dp[i] > tmp_dp:
                dp[i] = tmp_dp
    for v, w in enumerate(dp):
        if w <= W:
            ans = v
    return ans


if __name__ == "__main__":
    answer = solve()
    print(answer)


Measured memory_bytes: 7340
from sys import stdin

def solve(K, xs):
  return sum([2 * min(x, K - x) for x in xs])

def splitToInt(line):
  words = line.strip().split()
  return [int(w) for w in words]

N = int(stdin.readline())
K = int(stdin.readline())
xs = splitToInt(stdin.readline())
if len(xs) != N: raise
print(solve(K, xs))

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

int main(){
	int w, a, b;
	cin >> w >> a >> b;

	if(a<b){
		if(b-a < w){ cout << '0' << endl; return 0;}
		cout << b-a-w << endl;
	}
	else {
		if(a-b < w){ cout << '0' << endl; return 0; }
		cout << a-b-w << endl;
	}

	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    string s; cin >> s;

    rep(i, s.size()){
        if( s[i] == s[i+1] && i+1 < s.size() ){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }else if(s[i] == s[i+2] && i+2 < s.size()){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }

    cout << "-1 -1" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#define llint long long

using namespace std;

llint n, p;
string s;
llint S[200005];

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

	cin >> n >> p;
	cin >> s;
	
	llint ans = 0;
	if(p == 2){ 
		for(int i = 0; i < n; i++){
			if((s[i] - '0')%2 == 0){
				ans += i+1;
			}
		}
		cout << ans << endl;
		return 0;
	}
	if(p == 5){ 
		for(int i = 0; i < n; i++){
			if(s[i] - '0' == 5 || s[i] - '0' == 0){
				ans += i+1;
			}
		}
		cout << ans << endl;
		return 0;
	}
	
	reverse(s.begin(), s.end());
	
	llint mul = 1, sum = 0;
	for(int i = 0; i < n; i++){
		sum += mul * (s[i]-'0') % p, sum %= p;
		mul *= 10, mul %= p;
		S[i+1] = sum;
	}
	sort(S, S+n+1);
	
	//for(int i = 0; i <= n; i++)  cout << S[i] << " "; cout << endl;
	
	llint cnt = 0, pre = -1;
	for(int i = 0; i <= n; i++){
		if(S[i] == pre) cnt++;
		else{
			ans += cnt*(cnt-1)/2;
			cnt = 1;
		}
		pre = S[i];
	}
	ans += cnt * (cnt-1)/2;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2196