akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

long long fac[51000], finv[51000], inv[51000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 51000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/

int main(){
    ll H,W;
    cin >> H >> W;
    vector<vector<char>> maze(H,vector<char>(W));
    queue<P> que;
    vector<vector<ll>> d(H,vector<ll>(W,INF));
    rep(i,H){
        rep(j,W){
            cin >> maze[i][j];
            if(maze[i][j] == '#'){
                que.push(P(i,j));
                d[i][j] = 0;
            }
        }
    }
    const ll dx[] = {1,0,0,-1};
    const ll dy[] = {0,1,-1,0};
    while(que.size()){
        P p = que.front();que.pop();
        rep(i,4){
            ll hx = dx[i] + p.first;
            ll hy = dy[i] + p.second;
            if(hx >= 0 && hy >= 0 && hx < H && hy < W && d[hx][hy] == INF){
                que.push(P(hx,hy));
                d[hx][hy] = d[p.first][p.second] + 1;
            }
        }
        //cout << p.first << " " << p.second << endl;
    }
    ll ans = 0;
    rep(i,H){
        rep(j,W){
            ans = max(d[i][j],ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 28248
#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprv(i, n) for (int i = n - 1; i >= 0; i--)
#define ll long long
using namespace std;

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

    bool in_boxes[n + 1];
    bool out_boxes[n + 1];

    rep(i, n){
      int x;
      cin >> x;
      in_boxes[i + 1] = (x != 0);
    }

    int total = 0;
    for (int i = n ; i > 0 ; i--) {
        bool is_odd = false;
        int modifier = 2;
        while (modifier * i <= n) {
            if (out_boxes[modifier * i]) {
                is_odd = !is_odd;
            }
            modifier++;
        }

        if (is_odd != in_boxes[i]) {
            out_boxes[i] = true;
            total++;
        }
    }

    cout << total << endl;

    if (total > 0) {
        rep(i, n + 1) {
            if (out_boxes[i]){
                cout << i << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
n = int(input())
lst = list(map(int,input().split()))
num = [i+1 for i in range(n)]

opp = []
for i in range(n):
    if num[i] == lst[i]:
        opp.append(num[i])

cnt = len(opp)
for i in range(len(opp)-1):
    if opp[i+1] == opp[i] + 1:
        cnt -= 1
        tmp = opp[i+1]
        opp[i+1] = opp[i]
        opp[i] = tmp
        
print(cnt)

Measured memory_bytes: 13880
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef short int sh;

const int inf=0x3f3f3f3f;
const int MAX=2e5+10;
const int mod=1e9+7;

int n,k;
ll a[MAX];

bool cmp(ll x,ll y)
{
    return x>y;
}

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n,cmp);
        ll ans=a[0],i;
        for(i=0;i<n-1>>1;i++)
            ans+=a[i+1]<<1;
        if(n&1)
        {
            ans-=a[i];
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
  ll n,m;
  cin >> n >> m;
  ll a[1000000];
  FOR(i,n){
    cin >> a[i];
  }
  ll ans=0;
  sort(a,a+n);


  ll b[1000000],c[1000000];
  vector<ll> v;
  vector<pair<ll,ll>> vv;
  bool un=0;
  FOR(i,m){
    cin >> b[i] >> c[i];
    vv.push_back(make_pair(c[i],b[i]));
  }
  sort(vv.begin(),vv.end());
  reverse(vv.begin(),vv.end());

  FOR(i,vv.size()){
    FOR(j,vv[i].second){
      v.push_back(vv[i].first);
    }
    if(v.size()>n)break;
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());

  
  ll cnt=0,x=1000000;

  FOR(i,n){
    if(v.size()==i)break;
      if(a[i]<v[i]){
        a[i]=v[i];
      
      }
  }

  FOR(i,n){
    ans+=a[i];

  }

  cout << ans << endl;








  

  
  
  
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int x = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    x ^= A[i];
  }
  for (const auto& a : A) {
    cout << (x ^ a) << (a == A.back() ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
int ord(char C){
  int ans;
  ans = -(int)'a' + (int)C;
  return ans;
}

int main() {
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<set<int> > m(26, set<int>());
  for (int i = 0 ; i < n; i++){
    m.at(ord(s[i])).insert(i);
  }
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      char c;
      cin >> i >> c;
      i--; 
      if (s[i] != c){
        m.at(ord(s[i])).erase(i);
        m.at(ord(c)).insert(i);
        s.at(i) = c;
      }
    } 
    else {
      int l, r;
      cin >> l >> r;
      l--; 
      r--;  
      int ans = 0;
      for(int j = 0; j < 26; j++){
        if (m.at(j).end() != m.at(j).lower_bound(l)){
          int ite = *m.at(j).lower_bound(l);
          if (ite <= r){
            ans++;
          }
        }
      }
      cout << ans << '\n';
    }
  }
}

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

ll dp[100005];

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    for (int i = 1; i < n; ++i) {
        ll minStep = 1001001001001;
        for (int j = 1; j <= k && j <= i; ++j) {
            ll step = dp[i-j] + abs(h[i]-h[i-j]);
            minStep = min(minStep, step);
        }
        dp[i] = minStep;
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
vector<vector<int> > G;
void input(){
    fast_io();
    cin >> N >> M;
    G.resize(N);
    for (size_t i = 0; i < M; i++)
    {
        int a,b; cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
}

vector<int> bfs(int s=0){
    vector<int> dp(N,0);
    vector<bool> visited(N,false);
    queue<int> q;
    q.push(s);
    while(!q.empty()){
        int cur = q.front();
        q.pop();
        visited[cur] = true;
        for(int next:G[cur]){
            if(visited[next]) continue;
            visited[next] = true;
            dp[next] = cur;
            q.push(next);
        }
    }
    return dp;
}

int solve(){
    auto dp = bfs();
    cout << "Yes" << endl;
    for (size_t i = 1; i < N; i++) cout << (dp[i]+1) << endl;
    
    return 0;
}   

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

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

int solve(string s) {
	if (s.size() % 2 == 1) {
		s.erase(s.end()-1);
		solve(s);
	}
	while (s.size() != 0) {
		string t;
		t = "";
		for (int i = 0; i < s.size() / 2; i++) {
			t.push_back(s[i]);
		}
		bool f = true;
		for (int i = 0; i < t.size(); i++) {
			if (t[i] != s[i + t.size()])f = false;
		}
		if (f)return s.size();
		s.erase(s.end() - 1);
		s.erase(s.end() - 1);
	}
}

int main() {
	string a;
	cin >> a;
	a.erase(a.end() - 1);
	cout << solve(a) << endl;
	return 0;
}

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

namespace AtCoder_Cs
{
    public class Program
    {
        public static void Main()
        {
            var c500 = int.Parse(Console.ReadLine());
            var c100 = int.Parse(Console.ReadLine());
            var c50 = int.Parse(Console.ReadLine());
            var sum = int.Parse(Console.ReadLine());

            int sum500 = 0;
            int sum100 = 0;
            int sum50 = 0;

            int cnt = 0;

            for (int i = 0;i <= c500; i++)
            {
                sum500 = 500 * i;

                if (sum500 + sum100 + sum50 == sum)
                {
                    cnt++;
                    continue ;
                }

                sum100 = 0;
                for (int j = 0; j <= c100; j++)
                {
                    sum100 = 100 * j;

                    if (sum500 + sum100 + sum50 == sum)
                    {
                        cnt++;
                        continue;
                    }

                    sum50 = 0;
                    for (int k = 0; k <= c50; k++)
                    {
                        sum50 = 50 * k;

                        if (sum500 + sum100 + sum50 == sum)
                        {
                            cnt++;
                            continue;
                        }

                    }
                }
            }

            Console.WriteLine($"{cnt}");
        }
    }
}


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

int n, h[100004];
int dp[100004];

int main() {
	cin>>n;
	for(int i = 1; i<= n ; i++)	cin>>h[i];
	dp[1] = 0;
	dp[2] = abs(h[1]-h[2]);
	for(int i = 3;i<=n;i++)
		dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1024
import java.lang.Integer.min

//

fun main() {
    abc177b()
}

fun abc177b() {
    val s = readLine()!!
    val t = readLine()!!
    var count = 1000
    for (i in 0 .. s.length - t.length) {
        var c = 0
        for (j in t.indices) {
            if (s[i + j] != t[j]) c++
        }
        count = min(count, c)
    }
    println(count)
}


Measured memory_bytes: 35868
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
a=[]
x=[]
y=[]

for i in range(n):
    a0=ii()
    a.append(a0)
    xtemp=[]
    ytemp=[]
    for j in range(a0):
        x0,y0=mii()
        x0-=1
        xtemp.append(x0)
        ytemp.append(y0)
    x.append(xtemp)
    y.append(ytemp)

ans=0
for i in product([0,1], repeat=n):
    arr=list(deepcopy(i))


    #嘘つきは0 正直だと1 0だと反転 1だとそのまま
    temp=0
    for j in range(n):
        
        if i[j]==1:
            for k in range(a[j]):
                if i[x[j][k]]!=y[j][k]:
                    temp=1

    if temp==0:
        ans=max(ans,sum(arr))
    #ans=max(cnt,ans)
print(ans)


Measured memory_bytes: 77524
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	vector<tuple<ll, ll, ll>> v;
	REP(i, n)
	{
		int a, b; cin >> a >> b;
		v.emplace_back(a + b, a, b);
	}
	sort(v.rbegin(), v.rend());
	ll a = 0, b = 0;
	REP(i, n)
	{
		if (i % 2 == 0) a += get<1>(v[i]);
		else b += get<2>(v[i]);
	}
	cout << a - b << endl;
	return 0;
}

Measured memory_bytes: 4724
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;

	vector<int> s(m);
	vector<char> c(m);

	for (int i = 0; i < m; i++) {
		cin >> s[i] >> c[i];
		s[i]--;
	}

	int upper, lower;
	switch (n) {
		case 1:
			lower = 0;
			upper = 10;
			break;
		case 2:
			lower = 10;
			upper = 100;
			break;
		case 3:
			lower = 100;
			upper = 1000;
			break;
	}

	int ans = -1;
	for (int i = lower; i < upper; i++) {
		bool ok = true;
		string t = to_string(i);
		for (int j = 0; j < m; j++) {
			if (t[s[j]] != c[j]) {
				ok = false;
				break;
			}
		}
		if (ok) {
			ans = i;
			break;
		}
	}

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int N = 10;

int main(){
    int a[3][3];
    int n;
    int b[N];
    
    for(int i = 0; i < 3; i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(b[i] == a[j][k]) a[j][k] = 0;
            }
        }
    }
    
    bool flag = false;
    
    for(int i = 0; i < 3; i++){
        int j;
        for(j = 0; j < 3; j++){
            if(a[i][j] != 0) break;
        }
        if(j == 3) flag = true;
    }
    
    for(int j = 0; j < 3; j++){
        int i;
        for(i = 0; i < 3; i++){
            if(a[i][j] != 0) break;
        }
        if(i == 3) flag = true;
    }
    
    if(a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) flag = true;
    if(a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0) flag = true;
    
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int D, L;
	cin >> D >> L;

	if (D % L == 0) cout << D / L << endl;
	else
	{
		int t = D - L * (D / L);
		cout << (D / L) + t << endl;
	}

	return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mk(a, b) make_pair(a, b)
#define pb(a) push_back(a)

int N, bit[300030], M;
vector<pair<int, int> > V;
priority_queue<pair<int, int> > que[300030], q;

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> M;
        for(int j = 0; j < M; j++){
            int a;
            cin >> a;
            que[i].push(mk(a, i));
        }
    }
    int ans = 0;
    for(int i = N - 1; i >= 0; i--){
        q.push(mk(que[i].top().first ,i));
        que[i].pop();
        ans += q.top().first;
        //printf("%lld\n", ans);
        if(que[q.top().second].size()){
            q.push(mk(que[q.top().second].top().first, que[q.top().second].top().second));
            que[q.top().second].pop();
        }
        q.pop();
    }
    cout << ans << endl;


    return 0;
}
/*

3
3 8 10 1
4 7 1 2 15
3 11 8 19


*/



Measured memory_bytes: 23148
// -*- coding:utf-8-unix -*-

use proconio::input;
use rand::Rng;

pub fn get_time() -> f64 {
    static mut STIME: f64 = -1.0;
    let t = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .unwrap();
    let ms = t.as_secs() as f64 + t.subsec_nanos() as f64 * 1e-9;
    unsafe {
        if STIME < 0.0 {
            STIME = ms;
        }
        ms - STIME
    }
}

pub struct State {
    D: usize,
    sat: isize,
    out: Vec<usize>,
    last: Vec<usize>,
    c: Vec<isize>,
    s: Vec<Vec<isize>>,
}

impl State {
    fn calclate_score(&mut self) -> isize {
        self.sat = 0;
        self.last = vec![0; 26];
        let mut s: isize = 0;
        for i in 0..26 {
            s += self.c[i];
        }
        let mut temp_minus = 0;
        for d in 0..self.D {
            temp_minus += s;
            assert!(0 <= self.out[d] && self.out[d] <= 25);
            let j = self.out[d as usize] as usize;
            temp_minus -= self.c[j] * (d + 1 - self.last[j]) as isize;
            self.sat -= temp_minus;
            self.last[j] = d + 1;
            self.sat += self.s[d][j];
        }
        self.sat
    }
    fn initialize_output(&mut self) {
        for i in 0..self.D {
            let mut max = 0;
            for j in 0..26 {
                max = if self.s[i][max] < self.s[i][j] {
                    j
                } else {
                    max
                };
            }
            self.out[i] = max;
        }
    }
}

fn main() {
    input! {
        D: usize,
        c: [isize; 26],
        s: [[isize; 26]; D],
    }
    let mut plan = State {
        D: 365,
        sat: 0,
        out: vec![0; D],
        last: vec![0; 26],
        c: c,
        s: s,
    };
    plan.initialize_output();
    let mut rng = rand::thread_rng();
    let mut max_score = plan.calclate_score();
    let mut loop_cnt = 0;
    while get_time() < 1.9 {
        // eprintln!("{}", max_score);
        let d: usize = rng.gen_range(0, D);
        let q: usize = rng.gen_range(0, 26);
        let old = plan.out[d];
        plan.out[d] = q;
        let score = plan.calclate_score();
        if max_score < score {
            max_score = score;
        } else {
            plan.out[d] = old;
        }
        loop_cnt += 1;
    }
    for x in plan.out {
        println!("{}", x + 1);
    }
    eprintln!("score:{}, loop:{}", max_score, loop_cnt);
}


Measured memory_bytes: 2736
<?php
error_reporting(0);
//list($x,$t) = explode(" ",trim(fgets(STDIN)));
$N = trim(fgets(STDIN));
$ret=0;
for($i=0;$i<$N;$i++) {
  $l = explode(" ",trim(fgets(STDIN)));
  $ret += $l[1]-$l[0]+1;
}
printf("%d\n",$ret);


Measured memory_bytes: 3828
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        string s = Console.ReadLine();

        int i = 0;
        while (i < s.Length - 4)
        {
            string subs = s.Substring(i, 5);
            if (subs == "dream")
            {
                i += 5;
                if (i < s.Length - 1 && s.Substring(i, 2) == "er")
                {
                    if (!(i < s.Length - 2 && s.Substring(i, 3) == "era"))
                    {
                        i += 2;
                    }
                }
            }
            else if (subs == "erase")
            {
                i += 5;
                if (i < s.Length && s.Substring(i, 1) == "r") i++;
            }
            else
            {
                break;
            }
        }
        if (i == s.Length)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
        //Main();
    }
}

Measured memory_bytes: 11232
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T, typename S> T expo(T b, S e, const T &m){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b)%m, e>>1, m): (b*expo((b*b)%m, e>>1, m))%m;}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}

const int MAXN = 2e5 + 3;
LL arr[MAXN];
LL n;
LL sum = 0;

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  if(n == 1) {
    cout << "YES" << endl;
    return 0;
  }
  for(int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  bool ok = true;
  if((2ll * sum) % (n * (n + 1)) != 0) ok = false;
  LL R = (2ll * sum) / (n * (n + 1));
  LL crap = 0;
  for(int i = 1; i <= n; i++) {
    int a = i - 1, b = i % n;
    LL diff = arr[b] - arr[a];
    LL t = R - diff;
    if(t % n == 0 and R >= diff) {
      crap += t / n;
    } else {
      ok = false;
    }
  }
  if(ok) assert(crap == R);
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 1024
fun main() {
  val K = readInt()
  var d = 0
  for (i in 1..1000000) {
    d = (10 * d + 7) % K
    if (d == 0) {
      println(i)
      return
    }
  }
  println(-1)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 34548
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

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

int main (void) {

  int A, B, K; std::cin >> A >> B >> K;

  int G = gcd(A,B);

  std::set<int> L;
  for(int i=1; i<=sqrt(G); i++) {
    if ( G % i == 0 ) {
      L.insert(i);
      L.insert(G/i);
    }
  }

  auto itr = std::next(L.rbegin(), K-1);
  std::cout << *itr << std::endl;

  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
using namespace std;

const ll MAX =  1000 * 1000 ;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 301 ;
const int INF = INT_MAX ;
const int M = 200005;
bool cmp( pii x , pii y  ){
	return x.ff < y.ff ; 
	return x.ss < y.ss ;
}
int main ( ){

int n ;
cin >> n ; 
ll x , l  , pre , reach ;
vector<pii> v( n ); 
for ( int i = 0 ; i < n ; ++ i )
{
	cin >> v[i].ff >> v[i].ss ; 
} 
sort ( all ( v ) , cmp  ) ; 
int res = 0 ;
pre = v[0].ff , reach = v[0].ss ; 
for ( int i = 1 ; i < n ; ++ i ){
 x = v[i].ff , l = v[i].ss ; 
if (  x - l <  pre + reach  ){
	res ++ ;  
	if ( x + l < pre + reach )
	{
		pre = x ; 
		reach = l ; 
	}
}
else{
pre = x ; 
reach = l ; 
} 
// cout <<"i = " << i << " " << pre << " " << reach ; br  
}
cout << n - res ; 


return 0 ;

}


Measured memory_bytes: 1024
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = sorted(il())[::-1]
    print(sum(A[::2]) - sum(A[1::2]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
#define BOOST        std::ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define sp           <<" "<<
#define ll           long long
#define ld           long double
#define For(i,k,n)   for(ll i=k;i<n;i++)
#define Ford(i,n)    for(ll i=n-1;i>=0;i--)
#define AZI(i,x)     for(auto i=x.begin();i!=x.end();i++)
#define AZ(x)        x.begin(),x.end()
#define P(x,y)       pair < x,y >
#define V(x)         vector < x >
#define fi           first
#define se           second
#define pb           push_back
#define mp           make_pair
#define PI           3.14159265358979323846264338327950288419716939937510
 
const ll mod=1e9+7,N=1e6+5;

int h,w;
ll dp[1005][1005];
char grid[1005][1005]={};

ll no_of_paths(int r, int c)
{
    if(r>h || c>w)
        return 0;

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

    if(grid[r][c]=='#')    return dp[r][c] = 0;

    else return dp[r][c] = ( (no_of_paths(r+1,c)%mod + no_of_paths(r,c+1)%mod) )%mod;
}

int main() 
{ 
    BOOST

    cin>>h>>w;

    memset(dp,-1,sizeof(dp));

    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++)
            cin>>grid[i][j];

    dp[h][w] = 1;

    cout<<no_of_paths(1,1)<<"\n";
    
    return 0; 
} 

Measured memory_bytes: 9344
N = int(input())
A_list = list(map(int,input().split()))
ans = []
total_xor = 0
for i in A_list:
  total_xor = int(str(bin(total_xor^i)),2)
total_xor = int(str(bin(total_xor^0)),2)
for i in A_list:
  print(int(str(bin(total_xor^i)),2),end=" ")

Measured memory_bytes: 31496
def C():
    a,b,h,m = list(map(int, input().split()))
    import math
    h_r = 2*math.pi*(h+m/60)/12
    m_r = 2*math.pi*m/60
    r = abs(h_r-m_r)
    print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(r)))
C()

Measured memory_bytes: 9412
H,W=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(H)]

N=0
ans=[]
for i in range(H):
    for j in range(W):
        if a[i][j]%2==1:
            if j<W-1:
                a[i][j]-=1
                a[i][j+1]+=1
                N+=1
                ans.append([i+1,j+1,i+1,j+2])
            elif i<H-1:
                a[i][j]-=1
                a[i+1][j]+=1
                N+=1
                ans.append([i+1,j+1,i+2,j+1])
print(N)
for a in ans:
    for k in range(4):
        if k<3:
            print(a[k],end=" ")
        else:
            print(a[k])

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

void trace(int A[], int N) {
  int i;
  for (i = 0; i < N; i++) {
    if (i > 0) cout << " ";
    cout << A[i];
  }
  cout << endl;
}

void insertionSort(int A[], int N) {
  int j, i, v;
  for (i = 1; i < N; i++) {
    v = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A, N);
  }
}

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

  trace(A, N);
  insertionSort(A, N);
  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int D,N;cin>>D>>N;
  int ans;
  if(D==0){
    if(N==100)ans=101;
    else ans=N;
  }else if(D==1){
    ans=N*100;
    if(N==100)ans=10100;
  }else{
    ans=N*10000;
    if(N==100)ans=1010000;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n = input()
t = len(n)
ans = 0
for i in range(1,t+1):
    if i%2 == 1:
        str1 = ''
        if(t == i):
            ans += int(n) -  10**(i-1) +1
            continue
        else:
            ans += 9 * (10**(i-1))
print(ans)

Measured memory_bytes: 3060
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
#define mp make_pair
#define fr first
#define sc second
#define pb push_back
#define lc (x<<1)
#define rc ((x<<1)|1)
const int N=100005,M=200005;
const LL two=2ll;
int v[M*2],nxt[M*2],point[N],bs=0;
int vis[N],bh[N],num,ff;
LL A=0,B=0,C=0;
void addedge(int x,int y){
    bs++;v[bs]=y;nxt[bs]=point[x];point[x]=bs;
    bs++;v[bs]=x;nxt[bs]=point[y];point[y]=bs;
}
void dfs(int x,int fp){
    vis[x]=1;bh[x]=fp;num++;
    for (int p=point[x];p;p=nxt[p])
     if (!vis[v[p]]) dfs(v[p],fp^1);
      else if (bh[v[p]]==fp) ff=1;
}
int main(){
   // freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,n,m;
    scanf("%d%d",&n,&m);
    for (i=1;i<=m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        addedge(x,y);
    }
    for (i=1;i<=n;i++)
     if (!vis[i]) {num=ff=0;dfs(i,0);if (num==1) C++; else if (ff) A++; else B++;}
    printf("%lld\n",A*A+two*A*B+two*B*B+C*C+two*C*(((LL)n)-C));
  //  system("pause");
    return 0;
}


Measured memory_bytes: 6400
#include<iostream>
    using namespace std;
    int main(){
        int N;
        cin >> N;
        for(int i=N; i>=1; i--){
            int a = i;
            while(a % 2 == 0){
                a /= 2;
            }
            if(a == 1){
                cout << i <<endl;
                break;
            }
        }
        
    }

Measured memory_bytes: 256
S_a=str(input())
S_b=str(input())
S_c=str(input())
count_a=1
count_b=0
count_c=0
word=S_a[0]
while count_a<=len(S_a) and count_b<=len(S_b) and count_c<=len(S_c):
  if word=='a':
    if count_a==len(S_a):
      print('A')
      break
    else:
      word =S_a[count_a]
      count_a +=1
  elif word=='b':
    if count_b==len(S_b):
      print('B')
      break
    else:
      word =S_b[count_b]
      count_b +=1
  elif word=='c':
    if count_c==len(S_c):
      print('C')
      break
    else:
      word =S_c[count_c]
      count_c +=1


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
typedef struct
{
	char suit;
	char value;
} Card;
void bubbleSort(Card* a,int n)
{
	int i=0,j;
	Card temp;
	bool flag = true;
	while(flag)
	{
		flag = false;
		for(j=n-1; j>=i+1; j--)
		{
			if(a[j].value<a[j-1].value)
			{
				temp=a[j];
				a[j]=a[j-1];
				a[j-1]=temp;
				flag = true;
			}
		}
		i++;
	}
}
void selectionSort(Card* a,int n)
{
	int i,j;
	Card temp;
	int minj;
	for(i=0; i<n; i++)
	{
		minj=i;
		for(j=i; j<n; j++)
		{
			if(a[j].value<a[minj].value)
			{
				minj=j;
			}
		}
		temp=a[i];
		a[i]=a[minj];
		a[minj]=temp;
	}
}
bool isStable(Card* c1,Card* c2,int n)
{
	for(int i=0; i<n; i++)
	{
		if(c1[i].suit!=c2[i].suit)
		{
			return false;
		}
	}
	return true;
}
void printArr(Card* a,int n)
{
	for(int i=0;i<n;i++)
	{
		if(i>0) cout << " ";
		cout << a[i].suit << a[i].value;
	}
	cout << endl;
}
int main()
{
	int n;
	cin >> n;
	Card c1[n],c2[n];
	for(int i=0; i<n; i++)
	{
		cin >> c1[i].suit >> c1[i].value;
		c2[i]=c1[i];
	}
	bubbleSort(c1,n);
	selectionSort(c2,n);
	printArr(c1,n);
	cout << "Stable" << endl;
	printArr(c2,n);
	bool flag = isStable(c1,c2,n);
	if(flag)
	{
		cout << "Stable" <<endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
ar=$stdin.read.split("\n")
  (ar.size-1).times do |n|
    h,w=ar[n].split.map(&:to_i)
    h.times do |i|
      print (i==0 || i==h-1) ? "#"*w + "\n" : "#" + "."*(w-2) + "#\n"
    end
    print "\n"
  end


Measured memory_bytes: 6964
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
using gragh = vector<vector<int>>;

int main() {

    int M1,D1,M2,D2;
    cin>>M1>>D1;
    cin>>M2>>D2;
    if (M2-M1 == 1){
        cout<<1<<endl;
        return 0;
    }
    cout<<0<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    if(s.size()==3)cout << s[2] << s[1] << s[0] << endl;
    else cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 10050
#define H 10050
#define ll long long
#define x first
#define y second
#define all(v) v.begin(),v.end()
using namespace std;
ll h,n;
ll dp[H];
ll vis[H];
ll ar[N],co[N];
ll rec( ll a ){
    if(a<=0)return 0ll;
    if(vis[a])return dp[a];
    vis[a]=1;
    ll ans  = 1e18;

    for(int i=0;i<n;i++){
            ans = min( ans , co[i] + rec(a- ar[i]) );
    }
    dp[a] = ans;
    return dp[a];
}
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            cout.tie(NULL);
            cin>>h>>n;
            for(int i=0;i<n;i++)
                cin>>ar[i]>>co[i];
            cout<<rec(h);
            return 0;
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

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

    vector<vector<ll>> dp(n + 1, vector<ll>(2, 0));
    dp[0][0] = 1;
    REP(i, n) {
        dp[i + 1][1] = (dp[i + 1][1] + dp[i][1] * 3) % MOD;
        if (s[i] == '0') {
            dp[i + 1][0] = (dp[i + 1][0] + dp[i][0]) % MOD;
        } else {
            dp[i + 1][0] = (dp[i + 1][0] + dp[i][0] * 2) % MOD;
            dp[i + 1][1] = (dp[i + 1][1] + dp[i][0]) % MOD;
        }
    }
    cout << ((dp[n][0] + dp[n][1]) % MOD) << endl;
}


Measured memory_bytes: 5760
// abc173_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N;
    cin >> N;

    ll ans = 0;
    REP(i, N) {
        ans += (i + 1) * (N - i);
    }

    REP(i, N-1){
        ll u, v;
        cin >> u >> v; u--; v--;
        if (u > v) swap(u, v);
        ans -= (u+1) * (N-v);
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; i < (n); i++)
#define pb push_back
#define fi first
#define se second
#define ALL(a) (a.begin(), a.end())
using ll = long long;
template<typename T> void Out(T x) { cout << x << endl; }

const int maxn = 101;
int A[maxn];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N;
  double M;
  cin >> N >> M;
  double sum = 0;
  for(int i = 0;i<N;i++){
    cin >> A[i];
    sum += A[i];
  }
  int cnt = 0;
  for(int i = 0;i<N;i++){
    if (A[i] >= sum / 4 / M) {
      cnt ++;
    }
  }
  if (cnt >= M) Out("Yes");
  else Out("No");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int a[10][11][11]={0};
      for(int i=0;i<10;i++)for(int j=0;j<=10;j++)for(int k=0;k<=10;k++)a[i][j][k]=0;
      int n;
      cin>>n;
      string s;
      cin>>s;
      for(int i=0;i<n;i++){
            int d=s[i]-'0';
            for(int j=0;j<10;j++){
                  for(int k=0;k<10;k++){
                        a[j][k][d]|=a[j][k][10];
                  }
            }
            for(int j=0;j<10;j++){
                  a[j][d][10]|=a[j][10][10];
            }
            a[d][10][10]=1;
      }
      int cnt=0;
      for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                  for(int k=0;k<10;k++)cnt+=a[i][j][k];
            }
      }
      cout<<cnt;
}


Measured memory_bytes: 384
#include <vector>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
#include <iostream>
using namespace std;
int main(void)
{
    long N, X;
    cin >> N >> X;
    long here = 0;
    long cnt = 1;
    int flag = 0;
    for(int i =0; i < N; i++){
        long tmp;
        cin >> tmp;
        here += tmp;
        if(here > X){
            cout << cnt;
            flag = 1;
            break;
        }
        cnt += 1;
        
    }
    if(flag == 0) cout << cnt;
    
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h= new int[n];
		for(int i = 0; i < n; i++){
		    h[i] = sc.nextInt();
		}
		Arrays.sort(h);
		
		// 計算
		long result = 0;
		for(int i = 0; i < n - k; i++){
		    result += h[i];
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 89204
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    if(abs(a-c)<=d){
        cout<<"Yes"<<endl;
        return 0;
    }else if(abs(a-b)<=d && abs(b-c)<=d){
        
        cout<<"Yes"<<endl;
        return 0;
    }else{
        cout<<"No"<<endl;
    }
    
    return 0;
   
}






Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static size_t a[300000];

int main(void) {
    size_t N;

    scanf("%zu\n", &N);
    for (size_t i = 0; i < 3 * N; i++) {
        scanf("%zu", &(a[i]));
        if (i < 3 * N - 1) {
            scanf(" ");
        }
    }

    qsort(a, 3 * N, sizeof(size_t), compare_sz_desc);

    uint64_t sum = 0;
    for (size_t i = 0; i < N; i++) {
        sum += (uint64_t)(a[2 * i + 1]);
    }

    printf("%"PRIu64, sum);

    return 0;
}


Measured memory_bytes: 4860
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

const int M=20;

char s[M];
int ans,ls;

int getval(int x)
{
	return (s[x]-'0')*100+(s[x+1]-'0')*10+(s[x+2]-'0');
}

int main()
{
	int tmp;
	ans=1e9+7;
	scanf("%s",s);
	ls=strlen(s);
	for(int i=0;i+2<ls;i++)
	{
		tmp=getval(i);
		ans=min(ans,abs(tmp-753));
	}
	printf("%d\n",ans);
	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a,b,c,t;
    scanf("%d %d %d",&a,&b,&c);
    t=a;
    a=b;
    b=t;
    t=a;
    a=c;
    c=t;
    printf("%d %d %d",a,b,c);
    return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
  public static void main(String[] args) {
    try {
      BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
      String input = stdReader.readLine();
      StringBuilder output = new StringBuilder();
      
      for (int i = 0; i < input.length(); i++) {
        int c = (int)input.charAt(i);
        if     (c >= 65 && c <= 90)  output.append(lowerCase(input.charAt(i)));
        else if(c >= 97 && c <= 122) output.append(upperCase(input.charAt(i)));
        else                         output.append(input.charAt(i));
      }
      System.out.println(output.toString());
    } catch (Exception e) {
      System.out.println(e);
    }
  }
  
  public static char lowerCase(char c){
    return (char)(c + 32);
  }
  
  public static char upperCase(char c){
    return (char)(c - 32);
  }
}

Measured memory_bytes: 16872
#include<iostream>
#include<vector>
using namespace std;
long N,M,R,r,d[210][210]={},INF=9999999999999,ans=99999999999999,prime[10]={2,3,5,7,11,13,17,19,23,29};
vector<long> v;

void dfs(long i,long s,long sum,long jdg){
  if(i==R){
    if(sum<=ans){
      ans=sum;
      return;
    }
  }else{
    for(long j=0;j<R;++j){
      if(jdg%prime[j]!=0){
       dfs(i+1,j,sum+d[v[s]][v[j]],jdg*prime[j]);
      }
    }
  return;
  }
}

int main(){
  cin>>N>>M>>R;
  for(long i=0;i<R;i++){
    cin>>r;
    v.push_back(r-1);
  }

  for(long i=0;i<210;i++){
    for(long j=0;j<210;j++){
        d[i][j]=INF;
    }
  }
  for(long i=0;i<N;i++){
    d[i][i]=0;
  }
  long A,B,C;
  for(long i=0;i<M;i++){
    cin>>A>>B>>C;
    d[A-1][B-1]=C;
    d[B-1][A-1]=C;
  }

  for(long k=0;k<N;k++){
    for(long i=0;i<N;i++){
      for(long j=0;j<N;j++){
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      //  cout<<"d["<<i<<"]["<<j<<"]="<<d[i][j]<<endl;
      }
    }
  }
  for(long i=0;i<R;i++){
    dfs(1,i,0,prime[i]);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 768
h,w,k=map(int,input().split())
A=[]
p=1
Flag=True
ans=[]
trap=0
W=0
Q=0
for i in range(h):
  a=input()
  A.append(a)
for i in range(h):
  L=[]
  for j in range(w):
    if A[i][j]==".":
      L.append(p)
    else:
      W += 1
      if W == 0 or W==1:
        pass
      else:
        p+=1
      L.append(p)
      Flag=False
    if j==w-1:
      p+=1
  ans.append(L)
  W=0
  if Flag:
    if i!=0 and Q==0:
      ans[i]=ans[i-1]
    else:
      Q+=1
    p-=1
  else:
    if Q!=0:
      
      for q in range(Q):
        ans[q]=ans[i]
        Q=0
  Flag=True
for i in ans:
     print(' '.join(map(str, i)))

Measured memory_bytes: 7240
package main

import "fmt"

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var s string
	fmt.Scan(&s)

	ca, cb, cc := 0, 0, 0
	for _, r := range s {
		switch r {
		case 'a':
			ca++
		case 'b':
			cb++
		case 'c':
			cc++
		}
	}
	if abs(ca-cb) > 1 || abs(cb-cc) > 1 || abs(cc-ca) > 1 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}


Measured memory_bytes: 1280