akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <vector>
#include<algorithm>

int ta[200000];
std::vector<int> ti[200000];
std::vector<int> tb[200000];

void f(int x, int idx)
{
  ta[idx] += x;
  for (auto &&i : ti[idx])
  {
    auto removeIt = std::remove_if(tb[i].begin(), tb[i].end(), [&](int value) {
      return value == idx;
    });
    tb[i].erase(removeIt, tb[i].end());
    f(ta[idx], i);
  }
  for (auto &&i : tb[idx])
  {
    auto removeIt = std::remove_if(ti[i].begin(), ti[i].end(), [&](int value) {
      return value == idx;
    });
    ti[i].erase(removeIt, ti[i].end());
    f(ta[idx], i);
  }
}

int main(int argc, char const *argv[])
{
  int N;
  int Q;

  scanf("%d %d", &N, &Q);

  for (size_t i = 0; i < N; i++)
  {
    ta[i] = 0;
  }


  int a, b;
  for (size_t i = 0; i < N - 1; i++)
  {
    scanf("%d %d", &a, &b);
    ti[a - 1].push_back(b - 1);
    tb[b - 1].push_back(a - 1);
  }

  int p, x;
  for (size_t i = 0; i < Q; i++)
  {
    scanf("%d %d", &p, &x);
    ta[p - 1] += x;
  }

  f(0, 0);

  for (size_t i = 0; i < N; i++)
  {
    printf("%d ", ta[i]);
  }

  return 0;
}


Measured memory_bytes: 34432
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    if(a % 2 == 0 || b % 2 == 0) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}

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

using namespace std;

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    
    for(int i = -200; i <= 200; ++i)
    {
        ll a = 1LL;
        
        for(int k = 0; k < 5; ++k)
        {
            a *= (ll)i;   
        }
        
        for(int j = -200; j <= 200; ++j)
        {
               ll b = 1LL;
               
               for(int k = 0; k < 5; ++k)
               {
                    b *= (ll)j;
               }
               
               if(a - b == n)
               {
                    cout << i << ' ' << j << '\n';
                    return 0;
               }
        }
    }
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_H = (int)(8e1 + 5);
const int MAX_W = (int)(8e1 + 5);
const int MAX_DIFF = (int)(8e1 + 5);
// const int BASE = MAX_H * MAX_W * MAX_DIFF;
const int BASE = 15000;
const int SIZE = 2 * BASE;

int h, w;
int a[MAX_H][MAX_W];
int b[MAX_H][MAX_W];

bitset<30101> dp[MAX_H][MAX_W];

int main(void) {
  // Here your code !
  scanf("%d %d", &h, &w);

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      scanf("%d", &(a[i][j]));
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      scanf("%d", &(b[i][j]));
    }
  }

  int init = abs(a[0][0] - b[0][0]);

  dp[0][0].set(BASE + init);
  dp[0][0].set(BASE - init);

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int diff = abs(a[i][j] - b[i][j]);

      if (i - 1 >= 0) {
        dp[i][j] |= (dp[i - 1][j] << diff);
        dp[i][j] |= (dp[i - 1][j] >> diff);
      }

      if (j - 1 >= 0) {
        dp[i][j] |= (dp[i][j - 1] << diff);
        dp[i][j] |= (dp[i][j - 1] >> diff);
      }
    }
  }

  int ans = SIZE;

  for (int i = 0; i < 30101; ++i) {
    if (dp[h - 1][w - 1][i]) {
      ans = min(ans, abs(i - BASE));
    }
  }

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

  return 0;
}


Measured memory_bytes: 26752
N = int(input())
A = [int(n) for n in input().split()]
A = [0] + A + [0]
L = []
LL = []

for i, a in enumerate(A):
    if i < len(A) - 1:
        L.append(abs(A[i] - A[i+1]))
    if i < len(A) - 2:
        LL.append(abs(A[i] - A[i+2]))

s = sum(L)

for i in range(N):
    ans = s - L[i] - L[i+1] + LL[i]
    print(ans)


Measured memory_bytes: 18080
#include    <stdio.h>

int main() {
    int n, l = 0;
    char c, d;
    scanf("%d", &n);
    c = getchar();
    c = getchar();
    while(n > 1) {
        d = getchar();
        n--;
        if(c != d) {
            l++;
            n--;
            c = getchar();
        } else {
            c = d;
        }
    }
    printf("%d\n", l);
    return 0;
}




Measured memory_bytes: 2104
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val A = mutableListOf<Long>()
    val B = mutableListOf<Long>()
    repeat(N) {
        val (a, b) = nextLongList()
        A.add(a)
        B.add(b)
    }
    A.sort()
    B.sort()
    if (N % 2 == 1) {
        val l = A[N / 2]
        val r = B[N / 2]
        println(r - l + 1)
    } else {
        val ll = A[N / 2] + A[N / 2 - 1]
        val rr = B[N / 2] + B[N / 2 - 1]
        println(rr - ll + 1)
    }
}

Measured memory_bytes: 73772
def additional_time(t: int):
    return (10 - (t % 10)) % 10


A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

base_time = sum((A, B, C, D, E))
additional_times = list(map(additional_time, (A, B, C, D, E)))

print(base_time + sum(additional_times) - max(additional_times))


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
  int n,a[200000],i,t;
  scanf("%d",&n);
  t=n-1;
  for (i=0;i<n;i++) scanf("%d",&a[i]);
  printf("%d",a[t]);
  for (i=t-2;i>=0;i-=2) printf(" %d",a[i]);
  for (i=n%2;i<n;i+=2) printf(" %d",a[i]);
  printf("\n");
  return 0;
}

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

int main() {
  int x;
  cin >> x;
  int numOf500 = x / 500;
  x = x % 500;
  int numOf5 = x / 5;
  int ans = numOf500 * 1000 + numOf5 * 5;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int cntA,cntB,cntAB;
char s[15];
signed main(){
	long long ans=0,n,m,L,R;
	cin>>n;
	for(int i=1;1ll*i*i<=n;++i)
		if(n%i==0){
			long long m=i-1;
			if(m && (n/m)*(m+1)==n) ans+=m;
			if(1ll*i*i!=n){
				m=(n/i)-1;
				if(m && (n/m)*(m+1)==n) ans+=m;
			}
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long s;
	int a[12]={0};
	cin>>s;
	int n=0;
	for(int i=0;;i++)
	{
		a[i]=s%10;
		n++;
		s/=10;
		if(s==0)break;
	}
	int m=1e4;
	for(int i=n-1;i>1;i--)
	{
		m=min(m,abs(a[i]*100+a[i-1]*10+a[i-2]-753));
	}
	cout<<"                                  "<<m<<endl;
	return 0;
}

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

int main() {
	int  m,n,c,b[100],a,sum=0,count=0;
	cin>>n>>m>>c;
	for(int i=0;i<m;i++){
	    cin>>b[i];
	}
	for(int i=0;i<n;i++){
            sum=0;
	    for(int j=0;j<m;j++){
	        cin>>a;
	        sum+=b[j]*a;
	    }
	    if(sum+c>0){
	        count++;
	    }
	}
	cout<<count<<'\n';
	return 0;
}


Measured memory_bytes: 256
S = input()
K = int(input())

ord_a = ord('a')
ord_z = ord('z')

k = K
Ans = list(S)
for i, s in enumerate(S[:-1]):
    ord_s = ord(s)
    dif = ord_z - ord_s + 1
#    print(i, k, dif)
    if s == 'a':
        Ans[i] = 'a'
    elif dif <= k:
        Ans[i] = 'a'
        k -= dif
    else:
        pass
Ans[-1] = chr(ord_a + (ord(Ans[-1]) + k - ord_a)%26)
print(''.join(Ans))

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

int main() {
	


	string s;
	cin >> s;
	int freq[2] = {0};
	for (int i = 0; i < s.length(); ++i) {
		if(s[i] == 'A') {
			freq[0]++;
		} else {
			freq[1]++;
		}
	}
	if(freq[0]&&freq[1]) 
		cout<<"Yes";
	else
		cout<<"No";
	return 0;

}

Measured memory_bytes: 256
import sys
from collections import defaultdict, deque
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    n = getN()
    nums = getList()
    stock = defaultdict(int)
    for num in nums:
        stock[num] += 1

    # print(stock)
    ans = 0
    for i in range(32, -1, -1):
        tgt = 2 ** i
        # print(tgt)
        d = defaultdict(int)
        for num in nums:
            d[tgt - num] += 1
        # print(d)
        for dk in d.keys():
            if dk * 2 == tgt:
                a = stock[dk] // 2
                ans += a
                stock[dk] -= 2 * a
            else:
                # print(dk)
                if dk in stock:
                    # print("--")
                    # print(stock, dk, tgt)
                    a = min(stock[tgt - dk], stock[dk])
                    ans += a
                    stock[dk] -= a
                    stock[tgt - dk] -= a


    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()


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

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

int main()
{
	int X, N;
	int p[100];
	int flag = 0;
	int min = 100;
	int n_closest = 100;

	cin >> X >> N;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}

	for (int n = 101; n >= 0; n--) {
		for (int i = 0; i < N; i++) {
			if (n == p[i])
				flag = 1;
		}
		if (flag == 0) {
			if (min >= abs(X - n)) {
				min = abs(X - n);
				n_closest = n;
			}
		}
		flag = 0;
	}

	cout << n_closest << endl;

	return 0;
}

Measured memory_bytes: 3624
/*
05:55 - 06:20 first leg
06:20 - 6:50  finished
 */
#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
#include<climits>
#include<unordered_map>
#include<unordered_set>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 501
using namespace std;

typedef pair<int,int> ii;

int n,u,v,m,card;
int G[MAX][MAX][2];
bool used[MAX][MAX][2];
bool row[MAX][2],column[MAX][2],diag[2][2];
int dx[] = {+1,0,+1,-1};
int dy[] = {0,+1,+1,+1};

bool check(int type,int player,int p){
  int x,y;
  if(type == 0)x = 0, y = p; // テ・ツ渉ウ
  else if(type == 1)x = p, y = 0; // テ、ツクツ?
  else if(type == 2)x = y = 0; //テ、ツコツ暗ヲツδウテ」ツ?ョテ」ツ?ッテ」ツつ凝」ツ?凝ヲツ鳴愿」ツつ?」ツつ津」ツ?づ」ツ?づ」ツ??
  else if(type == 3)x = n-1, y = 0;

  rep(i,n){
    assert( 0 <= x && x < n && 0 <= y && y < n );
    if(!used[y][x][player])return false;
    x = x + dx[type];
    y = y + dy[type];
  }
  return true;
}

inline void increment(int& a,int& b,int player){
  if(player == 0)a++;
  else b++;
}

int main(){

  unordered_map<int,ii> place[2];
  cin >> n >> u >> v >> m;
  rep(i,2)rep(y,n)rep(x,n){
    cin >> G[y][x][i];
    place[i][G[y][x][i]] = ii(x,y);
  }

  int limit_USAGI = u, limit_NEKO = v;
  int score_USAGI = 0,score_NEKO = 0;
  string win = "$";
  rep(i,m){
    cin >> card;
    if(win[0] != '$')continue;

    rep(player,2){
      if(place[player].find(card) != place[player].end()){
	ii p = place[player][card];
	used[p.second][p.first][player] = true;

	if(!row[p.second][player]){
	  if(check(0,player,p.second)){
	    row[p.second][player] = true;
	    increment(score_USAGI,score_NEKO,player);
	  }
	}

	if(!column[p.first][player]){
	  if(check(1,player,p.first)){
	    column[p.first][player] = true;
	    increment(score_USAGI,score_NEKO,player);
	  }
	}


	if(p.first == p.second && !diag[0][player]){
	  if(check(2,player,0)){
	    diag[0][player] = true;
	    increment(score_USAGI,score_NEKO,player);
	  }
	}

	if(p.second == n-p.first-1 && !diag[1][player]){
	  if(check(3,player,0)){
	    diag[1][player] = true;
	    increment(score_USAGI,score_NEKO,player);
	  }
	}
      }
    }

    if(n == 1)score_USAGI = min(score_USAGI,1),
		score_NEKO = min(score_NEKO,1);

    if(score_USAGI >= limit_USAGI && score_NEKO >= limit_NEKO){
      win = "DRAW";
      //limit_USAGI++, limit_NEKO++;
    } else if( score_USAGI >= limit_USAGI ){
      win = "USAGI";
    } else if( score_NEKO >= limit_NEKO ){
      win = "NEKO";
    }
  }

  if(win[0] == '$')cout << "DRAW" << endl;
  else             cout << win    << endl;

  return 0;
}

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

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

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

	int n, d, x;
	cin >> n >> d >> x;

	vector<vector<int>> p(d, vector<int>(n));
	for(auto &row : p) {
		for(auto &e : row) {
			cin >> e;
		}
	}

	int ans = x;
	for(int day = 0; day < d - 1; ++day) {
		vector<int> dp(ans + 1, 0);

		for(int i = 0; i < n; ++i) {
			if(p[day + 1][i] <= p[day][i]) continue;

			for(int j = ans; j >= p[day][i]; --j) {
				chmax(dp[j - p[day][i]], dp[j] + p[day + 1][i]);
			}
		}

		for(int i = 0; i < dp.size(); ++i) {
			chmax(ans, dp[i] + i);
		}
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

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

int n;
vector<int> l;

bool isok(int a,int b, int c){
  if(l[a]+l[b]>l[c])return true;
  else return false;
}

    
int nibutan(int a, int b){
  int ok=b,ng=n;
  while(ng-ok>1){
    int naka=(ng+ok)/2;
    if(isok(a,b,naka))ok=naka;
    else{
      ng=naka;
    }
  }
    return ok-b;
}
   
 int main(){
  cin>>n;
   l.resize(n);
  rep(i,n){
    cin>>l[i];
  }
   ll ans=0;
  sort(l.begin(),l.end());
  for(int a=0;a<n;a++){
    for(int b=a+1;b<n;b++){
      ans+=nibutan(a,b);
    }
  }
  cout<<ans<<endl;
 }



Measured memory_bytes: 3640
//Giorgi Kldiashvili

#include <bits/stdc++.h>

#define ll long long
#define M 1000000007LL

using namespace std;

int n, x;
int a[300020];
bool F[300020];

int main()
{
  cin >> n >> x;
  if(2 * n - 1 == x || 1 == x)
    return printf("No\n"), 0;
  printf("Yes\n");

  a[n] = x;
  a[n - 1] = 1;
  a[n + 1] = 2 * n - 1;
  F[x] = F[1] = F[2 * n - 1] = true;
  int now = 1;
  for(int i = 1; i < n - 1; ++ i)
  {
    while(F[now] == true) now ++;
    a[i] = now;
    now ++;
  }
  for(int i = n + 2; i < 2 * n; ++ i)
  {
    while(F[now] == true) now ++;
    a[i] = now;
    now ++;
  }
  for(int i = 1; i <= 2 * n - 1; ++ i)
    printf("%d\n", a[i]);
}


Measured memory_bytes: 2304
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#include<iostream> 
#define mp make_pair
#define MIN(a,b) (a>b?b:a)
//#define MAX(a,b) (a>b?a:b)
typedef long long ll;
typedef unsigned long long ull;
const int MAX=2e5+5;
const int INF=1e8+5;
using namespace std;
//const int MOD=1e9+7;
typedef pair<ll,int> pii;
const double eps=0.00000001;
int n,m;
queue<int> que[305];
int tem;
bool vi[305];
int num[305];
int cnt,an,who;
int main()
{
	int i,j,k;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            scanf("%d",&tem);
            que[i].push(tem);
        }
    }
    for(i=1;i<=m;i++)
    {
        memset(num,0,sizeof(num));
        cnt=0;
        who=que[1].front();
        for(j=1;j<=n;j++)
        {
            int pre=que[j].front();
            while(vi[pre])
            {
                que[j].pop();
                pre=que[j].front();
            }
            ++num[pre];
            if(num[pre]>cnt)
            {
                 cnt=num[pre];
                 who=pre;
            }
        }
        vi[who]=true;
        if(i!=1)
            an=min(an,cnt);
        else
            an=cnt;
    }
    printf("%d\n",an);
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define l first
#define r second
#define INF (1e9)
using namespace std;
typedef pair <int,int> P;
int ans=1,m,n,used[101],memo[101][101];
P cmd[101][101];

int check(int a,int b){
  if(memo[a][b]!=-1) return memo[a][b];
  for(int i=0;i<n;i++)
    if(cmd[a][i].l>cmd[b][i].r) return memo[a][b]=0;
  return memo[a][b]=1;
}

int solve(){
  memset(memo,-1,sizeof(memo));
  int cnt=0;
  for(int i=0;i<m;i++){
    int j=0;
    while(!used[i]&&j<m&&(used[j]||check(i,j)))j++;
    if(j==m) used[i]=1,cnt++,i=-1;
  }
  return cnt/m;
}

int main(){
  for(int i=0;i<101;i++)
    for(int j=0;j<101;j++)cmd[i][j]=P(-INF,INF);

  cin>>m>>n;
  for(int i=0,k;i<m;i++){
    cin>>k;
    while(k--){
      string cond;
      int s,t;
      cin>>s>>cond>>t;
      s--;
      if(cond=="<=")cmd[i][s].r=min(cmd[i][s].r,t);
      if(cond==">=")cmd[i][s].l=max(cmd[i][s].l,t);
      if(cmd[i][s].l>cmd[i][s].r)ans=0;
    }
  }

  cout << (ans*solve()? "Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 1336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++)
#define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

ll n, h[200005];

void reset()
{
}

void input()
{
	cin>>n;
	UU(i,1,n) cin>>h[i];
}

void solve()
{
	ll total = 0, mx = h[1];
	UU(i,2,n)
	{
		mx = max(h[i], mx);
		if(mx > h[i])
		{
			total += mx - h[i];
		}
	}
	cout<<total<<endl;
}

void LetsRock()
{
	solve();	
}

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

		input();
		reset();
		LetsRock();
	
	return 0;
}


Measured memory_bytes: 5212
#include <cstdio>
#include <queue>
#include <utility>

using namespace std;

typedef pair<int, int> P;

const int MAX_N = 400;

const int di[] = { 1, 0, -1, 0 };
const int dj[] = { 0, 1, 0, -1 };

bool color[MAX_N][MAX_N];
int H, W;

char ch[MAX_N + 1];

void input()
{
    scanf("%d%d", &H, &W);
    for (int i = 0; i < H; ++i) {
        scanf("%s", ch);
        for (int j = 0; j < W; ++j) {
            color[i][j] = (ch[j] == '#');
        }
    }
}

bool isin_(int i, int j)
{
    return i >= 0 && i < H && j >= 0 && j < W;
}

bool check_(int i, int j, int d)
{
    int ni = i + di[d];
    int nj = j + dj[d];
    if (!isin_(ni, nj))
        return false;
    if (color[i][j] == color[ni][nj])
        return false;
    return true;
}

bool used[MAX_N][MAX_N];

long long solve()
{
    long long ans = 0;
    long long b = 0, w = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (used[i][j])
                continue;
            b = 0;
            w = 0;
            queue<P> que;
            used[i][j] = true;
            que.push(P(i, j));
            while (!que.empty()) {
                P p = que.front();
                que.pop();
                int ci = p.first, cj = p.second;
                if (color[ci][cj])
                    b++;
                else
                    w++;
                for (int d = 0; d < 4; ++d) {
                    if (!check_(ci, cj, d))
                        continue;
                    int ni = ci + di[d], nj = cj + dj[d];
                    if (used[ni][nj])
                        continue;
                    used[ni][nj] = true;
                    que.push(P(ni, nj));
                }
            }
            ans += b * w;
        }
    }
    return ans;
}

int main()
{
    input();
    long long ans = solve();
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 512
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let t: i32 = read();

    let ans = (t / a) * b;

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#N = int(input())

#t, x, y = [0]*(N+1), [0]*(N+1), [0]*(N+1)#N+1個の空のリストを作成(原点を入れて##るから一つ増える)
#delta_t=0
#delta_x=0
#delta_y=0
#l=0
#t[0],x[0],y[0]=[0, 0, 0]
#とりあえず入力までは完成した．
#for i in range(N):
# t[i+1], x[i+1], y[i+1] = map(int, input().split())
a_b =  list(map(int, input().split()))

if a_b[0] <= 0 and a_b[1] >= 0:
    print("Zero")
    sys.exit()
    
if a_b[0] >=1 :
    print("Positive")
    sys.exit()
if (a_b[1]-a_b[0]+1)%2 ==0:
    print("Positive")
    sys.exit()
else:
    print("Negative")
    sys.exit()


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#define B 1
#define W 2
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

short d[] = {0,1,-1};
int n,m,p;
short G[7*7*7+1][8][8];

bool check(int x,int y,int z)
{
  for(int i=0;i<3;i++)
    {
      for(int j=0;j<3;j++)
	{
	  for(int k=0;k<3;k++)
	    {
	      if(i+j+k == 0)
		continue;

	      short dx = d[k],dy = d[j],dz = d[i];
	      short c = G[z][y][x];
	      short cnt = 0;
	      short nx,ny,nz;
	      nx = ny = nz = 0;

	      while((0 <= x+nx && x+nx < n) && (0 <= y+ny && y+ny < n) && (0 <= z+nz && z+nz < n) && G[z+nz][y+ny][x+nx] == c)
		nz-=dz,ny-=dy,nx-=dx;
	      nz+=dz,ny+=dy,nx+=dx;

	      while((0 <= x+nx && x+nx < n) && (0 <= y+ny && y+ny < n) && (0 <= z+nz && z+nz < n) && G[z+nz][y+ny][x+nx] == c)
		cnt++,nz+=dz,ny+=dy,nx+=dx;
		
	      if(cnt >= m)
		return true;
	    }
	}
    }
  return false;
}

int main()
{
  while(cin >> n >> m >> p,n|m|p)
    {
      rep(i,p+1)
	rep(j,n+1)
	  rep(k,n+1)
            G[i][j][k] = 0;
      int found = -1;
      rep(i,p)
	{
	  int x,y,z = 0;
	  cin >> x >> y;
	  x--,y--;
	  while(G[z][y][x]!=0)
	    z++;
	  G[z][y][x] = i%2?W:B;
	  if(found == -1)
	    if(check(x,y,z))
	      found = i;    
	}
      if(found == -1)
	cout << "Draw" << endl;
      else 
	found%2?cout << "White " << found+1 << endl:cout << "Black " << found+1 << endl; 


    }
  return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define ll long long
#define N 3005
#define mod 1000000007
using namespace std;
inline int read(){
	int x=0; bool f=1; char c=getchar();
	for(;!isdigit(c); c=getchar()) if(c=='-') f=0;
	for(; isdigit(c); c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
	if(f) return x;
	return 0-x;
}
int n,m; char s[N];
int R[N],sum[N],f[N][N];
int main(){
    n=read(), m=read(); scanf("%s",s+1);
    for(int i=1; i<=n; ++i) sum[i]=s[i]-'0';
    for(int i=1; i<=n+1; ++i) sum[i]+=sum[i-1];
    for(int i=1; i<=n+1; ++i) R[i]=i;
    int l,r;
    for(int i=1; i<=m; ++i){
        l=read(), r=read();
        R[l]=max(R[l],r);
    }
    for(int i=1; i<=n; ++i) R[i]=max(R[i],R[i-1]);
    f[1][sum[R[1]]]=1;
    int flag0,flag1;
    for(int i=1; i<=n; ++i)
        for(int j=0; j<=n; ++j)
            if(f[i][j]){
                l=R[i]+1, r=R[i+1];
                flag1=j, flag0=R[i]-(i-1)-flag1;
                if(flag0) (f[i+1][j+sum[r]-sum[l-1]]+=f[i][j])%=mod;
                if(flag1) (f[i+1][j-1+sum[r]-sum[l-1]]+=f[i][j])%=mod;
            }
    printf("%d\n",f[n+1][0]);
    return 0;
}

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int x;
    cin >> x;

    cout << (x >= 30 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
    using namespace std;
     
    int main()
    {
      int n,a,b;
      cin >> n >> a >> b;
      int i,sum;
      int total = 0;
      for(i = 1; i <= n; i++)
      {
        sum = i % 10 + (i % 100 - i % 10) / 10 + (i % 1000 - i % 100) / 100 + (i % 10000 - i % 1000) / 1000 + i / 10000;
        if (sum >= a && sum <= b)
        {
          total += i;
        }
      }
      cout << total << endl;
      return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout << endl
#define sp(x) cout << setprecision(x);
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
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) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; }
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }

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

	int N, W; cin >> N >> W;
	vl w(N), v(N);
	rep(i, N)cin >> w[i] >> v[i];
	vvl dp(N + 1, vl(1e5 + 1, 1e12));

	dp[0][0] = 0;
	rep(i, N)rep(j, 1e5 + 1)
	{
		if (j < v[i])dp[i + 1][j] = dp[i][j];
		else dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
	}
	int ans = 0;
	rep(j, 1e5 + 1)if (dp[N][j] <= W)chmax(ans, j);
	co(ans);
	return 0;
}


Measured memory_bytes: 80256
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
k = 0
f = 0
for i in range(n):
  k += a[i]
  if k >= s//2:
    f = i
    break
k = max(k, s - k)
k2 = k - a[f]
k2 = max(k2, s - k2)
print(min(2*k - s, 2*k2 - s))

Measured memory_bytes: 26060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i > 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

int main()
{
  ll N, M; cin >> N >> M;
  vector<int> a(M), c(M);
  REP(i, M)
  {
    ll b, cij;
    cin >> a[i] >> b;
    REP(j, b)
    {
      cin >> cij;
      c[i] |= (1 << (cij - 1));
    }
  }
  
  vector<int> dp((1 << N), INF);
  dp[0] = 0;
  REP(i, M) REP(j, (1 << N)) chmin(dp[j | c[i]], dp[j] + a[i]);
  if(dp[(1 << N) - 1] == INF) dp[(1 << N) - 1] = -1;
  cout << dp[(1 << N) - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100001

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


int main(){
  int N,n,i,j,k,l;
	LL dp[120][4][4][4],ans=0;
	scanf("%d",&N);
	FOR(i,0,4)FOR(j,0,4)FOR(k,0,4)dp[3][i][j][k]=1;
	dp[3][0][1][2]=dp[3][0][2][1]=dp[3][1][0][2]=0;
	FOR(n,4,N+1)FOR(i,0,4)FOR(j,0,4)FOR(k,0,4)FOR(l,0,4)
	if(!(j==0&&k==1&&l==2||j==0&&k==2&&l==1||j==1&&k==0&&l==2||i==0&&j==1&&l==2||i==0&&k==1&&l==2))
	dp[n][j][k][l]=(dp[n][j][k][l]+dp[n-1][i][j][k])%MOD;
	if(N==1)ans=4;else if(N==2)ans=16;
	else FOR(i,0,4)FOR(j,0,4)FOR(k,0,4)ans=(ans+dp[N][i][j][k])%MOD;

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


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cctype>
#include<queue>
#include<vector>
inline int read() {
	int x = 0, f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) f ^= c == '-';
	for (; isdigit(c); c = getchar())  x = x * 10 + c - '0';
	return f ? x : -x;
}
using namespace std;
const int yuzu = 1e5;
int d[yuzu | 10],k;

void bfs(int u, int dep) {
	memset(d, 0x3f, sizeof d);
	queue<int> q;
	q.push(1), d[1] = 1;
	for (; !q.empty();) {
		int u = q.front();q.pop();
		int net = u * 10 % k;
		if (d[net] > d[u]) {
			q.push(net);
			d[net] = d[u];
		}
		net = (u + 1) % k;
		if (d[net] > d[u] + 1) {
			q.push(net);
			d[net] = d[u] + 1;
		}
	}
}

int main() {
	k = read();
	bfs(1, 1);
	cout << d[0]<<endl;
}

Measured memory_bytes: 768
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(int argc, const char * argv[]) {
    std::cout << std::fixed << std::setprecision(15);
    int N; cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    
    bool ans = false;
    int cnt = 0;
    rep(i, N){
      if(A[i] % 2 == 1) cnt++;
    }

    if(cnt > 0){
      cout << "first" << endl;
    }
    else
    {
      cout << "second" << endl;
    }
    
}  


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,d,i,count=0;
	cin>>n>>d;
	long long int a[n],b[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	for(i=0;i<n;i++)
	{
		if(sqrt(a[i]*a[i] + b[i]*b[i])<=d) count++;
	}
	cout<<count<<endl;
}


Measured memory_bytes: 6772
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    set<int> colors;
    for (int i = 0; i < 3; ++i)
    {
        int color;
        cin >> color;
        colors.insert(color);
    }
    cout << colors.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int count,num,sub;
  while(1){
    count=0;
    scanf("%d",&num);
    if(num==0){
      break;
    }else{
      while(num!=1){
	if(num%2==0){
	  num/=2;
	}else{
	  sub=3*num+1;
	  num=sub;
	}
	//printf("%d\n",num);
	count++;
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  ll a[2], b[2];
  rep(i,0,2) cin>>a[i];
  rep(i,0,2) cin>>b[i];
  ll ans=-INF;
  rep(i,0,2)rep(j,0,2){
    chmax(ans, a[i]*b[j]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3620
n = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(len(l)):
    for j in range(i+1,len(l)):
        for k in range(j+1,len(l)):
            if l[i]+l[j]>l[k] and len({l[i],l[j],l[k]})==3:
                count+=1
print(count)

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

using namespace std;
#define lli long long int
#define numberofdigits(x) floor(log10(x)) + 1

int main()
{
    lli n,i,a[85],mn,mx,yen,stocks;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    mn=0,mx=0;
    yen=1000;
    stocks=0;
    if(a[1]<=a[2])
    {
        mn=a[1];
        // stocks = yen/mn;
        // yen = yen%mn;
    }
    for(i=2;i<n;i++)
    {
        if(a[i]>=a[i-1] && a[i]>=a[i+1])
        {
            if(mn)
            {
                stocks = yen/mn;
                yen = yen%mn;
                yen += stocks*a[i];
                stocks=0;
                mn=0;
            }
        }
        else if(a[i]<=a[i-1] && a[i]<=a[i+1])
        {
            mn=a[i];
        }
    }
    if(a[n]>=a[n-1])
    {
        if(mn)
        {
            stocks = yen/mn;
            yen = yen%mn;
            yen += stocks*a[i];
            stocks=0;
            mn=0;
        }
    }
    cout<<yen<<"\n";
    return 0;
}

Measured memory_bytes: 3616
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
  n = ni()
  s = ns()
  ans = ""
  for ss in s:
    x = ord(ss) + n
    if x > 90:
      x -= 26
    ans += chr(x)
  print(ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000

int main(){

	int N,M;
	cin>>N>>M;
	
	map<int,int> mp;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		mp[a]++;
	}
	
	vector<int> num(M,0),Pnum(M,0);
	
	for(auto a:mp){
		Pnum[a.first%M] += a.second/2;
		num[a.first%M] += a.second;
	}
	
	int ans = 0;
	
	for(int i=0;i<=M/2;i++){
		if(i+i==M||i==0){
			ans += num[i]/2;
		}
		else{
			int x = min(num[i],num[M-i]);
			ans += x;
			num[i] -= x;
			num[M-i] -= x;
			
			ans += min(num[i]/2,Pnum[i]);
			ans += min(num[M-i]/2,Pnum[M-i]);
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    bool flag = true;
    cin>>a>>b;
    string str;
    cin>>str;
    for(int i=0;i<a+b+1;i++)
    {
        if((i == a && str[i] != '-') || (i!= a && ( str[i] <48 || str[i]>57)))
        {
          
            flag = false;
            break;
        }
    }
    if(flag)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll L, R, d, i, sum=0;

    cin >> L >> R >> d;

    for(i=L; i<=R; i++){
        if(i%d==0) sum++;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3476
from collections import Counter

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

A = list(map(int,input().split()))
S = [A[0]%M]

for i in range(N-1):
    S.append((S[i]+A[i+1])%M)

ans = 0

counter = Counter(S)

for k in counter.keys():
    c = counter[k]
    if k==0:
        ans+=c
    ans+=(c*(c-1))//2

print(ans)


Measured memory_bytes: 63256
/*#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int par[100005],ran[100005];
void init(){ for(int i=0;i<100005;i++) par[i] = i; }
int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
void unite(int x,int y){
	x = find(x); y = find(y); if(x==y) return;
	if(ran[x] < ran[y]) par[x] = y;
	else{
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x,int y){ return find(x)==find(y); }
int n,q;
ll m;
vector<P>vec;
int main(){
	cin >> n >> m >> q;
	int cur = n; init();
	rep(i,q){
		int a,b,c; cin >> a >> b >> c;
		if(c == 0) {if(!same(a,b)) { unite(a,b) ; cur--; } }
		else vec.pb(mp(a,b));
	}
	rep(i,vec.size()){
		if(same(vec[i].fi,vec[i].sc)){
			puts("No"); return 0;
		}
	}
	if(cur == 1){
		puts(m==n-1?"Yes":"No");
		return 0;
	}
	else if(cur == 2){
		if(vec.empty()){
			puts(m==n-1?"Yes":"No");
		}
		else{
			puts("No");
		}
	}
	else{
		ll mn, mx;
		if(vec.empty()) mn = n-1; else mn = n;
		mx = n-cur + 1LL*cur*(cur-1)/2;
		puts((mn<=m&&m<=mx)?"Yes":"No");
	}
}

Measured memory_bytes: 1912
def mapt(fn, *args):
    return list(map(fn, *args))


def Atom(segment):
    try:
        return int(segment)
    except ValueError:
        try:
            float(segment)
        except ValueError:
            return segment


def Input():
    return mapt(int, input().split(" "))


def main():
    n = int(input())
    data = [mapt(Atom, input().split(" ")) for _ in range(n)]
    for i in range(n):
        data[i].append(i)
    data = sorted(data, key=lambda x:x[1], reverse=True)
    data = sorted(data, key = lambda x:x[0])
    for row in data:
        print(row[2]+1)

main()

Measured memory_bytes: 9008
#include<bits/stdc++.h>
#define MAX 100000
#define INF 1000
using namespace std;
int n,m,Q,v[MAX+5],d[MAX+5],c[MAX+5],rec[MAX+5];
int vis[MAX+5],way[MAX+5],MinDis[MAX+5];
vector<int>edge[MAX+5];
void run()
{
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++) rec[i]=-1,MinDis[i]=-1;
	for(int i=1; i<=m; i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	scanf("%d",&Q);
	for(int i=1; i<=Q; i++)
    scanf("%d%d%d",&v[i],&d[i],&c[i]);
}
void dfs(int from,int dis,int col)
{
	if(MinDis[from]>=dis) return; 
	else MinDis[from]=dis;
	vis[from]=1;
	way[from]=1;
	for(int i=0; i<edge[from].size(); i++)
	{
		int to=edge[from][i];
		if(way[to]) continue;
		if(dis>=1) 
		{
		rec[to]=(!vis[to])?col:rec[to];
		dfs(to,dis-1,col);
	    }
	}
	way[from]=0;
}
void solve()
{
	for(int i=Q; i>=1; i--)
	{
	if(!vis[v[i]]) rec[v[i]]=c[i];
	dfs(v[i],d[i],c[i]);
    }
}
void lprint()
{
	for(int i=1; i<=n; i++)
	{
		int check=(rec[i]==-1)?0:rec[i];
		printf("%d\n",check);
	}
}
int main()
{
	run();
	solve();
	lprint();
	return 0;
}

Measured memory_bytes: 9208
N,M = map(int,input().split())
A = tuple(map(int,input().split()))

actions = [tuple(map(int,input().split())) for _ in range(M)] + [(1,a) for a in A]

actions = sorted((c,b) for b,c in actions)

def it():
    cards = N
    for c,b in reversed(actions):
        if cards == 0:
            return
        b = min(cards, b)
        yield c*b
        cards -= b

print(sum(it()))

Measured memory_bytes: 43080
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        String result = solve(s);

        // 出力
        System.out.println(result);
    }

    private static String solve(String s) {
        if ("zyxwvutsrqponmlkjihgfedcba".equals(s)) {
            return "-1";
        }

        char[] alphabets = "abcdefghijklmnopqrstuvwxyz".toCharArray();
        boolean[] isUsed = new boolean[26];

        if (s.length() < 26) {
            for (char c : s.toCharArray()) {
                isUsed[(int) c - 97] = true;
            }
            for (int i = 0; i < isUsed.length; i++) {
                if (!isUsed[i]) {
                    s += alphabets[i];
                    break;
                }
            }
            return s;

        } else {
            char[] c = s.toCharArray();
            for (int i = 25; 0 < i; i--) {
                char right = c[i];
                char left = c[i - 1];
                isUsed[(int) right - 97] = true;
                c[i] = '*';
                if (left < right) {
                    for (int j = (int) left - 97; j < 26; j++) {
                        if (isUsed[j]) {
                            c[i - 1] = alphabets[j];
                            break;
                        }
                    }
                    break;
                }
            }
            return new String(c).replace("*", "");
        }
    }
}


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

int main() {
	char v;
	cin >> v;
	if (v == 'S') cout << "Cloudy" << endl;
	else {
		if (v == 'C') cout << "Rainy" << endl;
		else cout << "Sunny" << endl;
		}
	}

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

using namespace std;

int n, t;
int a[3100], b[3100];
int dp[3100][2];

int main(){
    cin >> n >> t;
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    for(int j = 0; j < n; j++){
        for(int i = t - 1; i >= 0; i--){
            if(i + a[j] < t){
                dp[i + a[j]][0] = max(dp[i + a[j]][0], dp[i][0] + b[j]);
                dp[i + a[j]][1] = max(dp[i + a[j]][1], dp[i][1] + b[j]);
            }
            dp[i][1] = max(dp[i][1], dp[i][0] + b[j]);
        }
    }
    cout << dp[t - 1][1] << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

string s;
void solve(){
    int n = s.length();
    if(s[n - 1] == 's')
        s += "es";
    else
        s += "s";
    cout << s;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--) {
        cin >> s;
        solve();
    }
    return 0;
}

Measured memory_bytes: 3644
mod = 1000000007

N = int(input())

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

S = [0]*N

for i in range(N):
    j = N-1 - i

    if i == 0:
        S[j] = 0
    else:
        S[j] = S[j+1] + A[j+1]

ans = 0

for i in range(N):
    ans += A[i]*S[i]
    ans = ans % mod

print(ans)

Measured memory_bytes: 31676
n = int(input())
r = [0]*n
for i in range(n):
    r[i] = int(input())

r_min = r[0]
ans = -2000000000
for i in range(1, n):
    ans = max(ans, r[i] - r_min)
    r_min = min(r[i], r_min) 
    
print(ans)



Measured memory_bytes: 13372
/**
 * ????????????????????°

1 ?????? n ?????§?????°?????????????????????????????§???????????°?????????????????????????¨???? x
??¨??????????????????????????°????±???????????????°?????????????????????????????????

????????°???1 ?????? 5 ?????§?????°???????????????????????§????????????????¨???? 9 ??¨???????????????????????????

1 + 3 + 5 = 9
2 + 3 + 4 = 9
??????????????????????????????

Input
?????°??????????????????????????\?????¨??????????????????????????????????????????????????§??????????????§???????????????
n???x ??? 1 ???????????????????????????

n???x ?????¨?????? 0 ?????¨?????\?????????????????¨????????????

n ??? 3 ??\??? 100?????\?????¨????????????

Output
????????????????????????????????????????????????????????°????????????????????????????????????

Sample Input
5 9
0 0
Sample Output
2
 */

#include <iostream>
#include <sstream>
#include <vector>

int main(int argc, char const *argv[]) {
  unsigned short n, x;
  n = 5;
  x = 9;
  while (true) {
    while (true) {
      std::string Param;

      getline(std::cin, Param);
      std::istringstream iss(Param);
      iss >> n >> x;

      if (n == 1 || n == 2 || n > 100) {
        std::cout << "Error: 3 <= n <= 100" << std::endl;
      } else {
        break;
      }
    }
    if (n == 0 && x == 0) {
      break;
    } else {
      unsigned short MatchCount = 0;

      for (size_t i = 1; i < n + 1; i++) {
        for (size_t j = 1; j < n + 1; j++) {
          for (size_t k = 1; k < n + 1; k++) {
            if (i > j && j > k) {
              if ((i + j + k) == x) {
                MatchCount++;
              }
            }
          }
        }
      }
      std::cout << MatchCount << std::endl;
    }
  }
  return 0;
}

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

int main() {
  char c;
  cin >> c;
  
    if (c == 'a' || c == 'i' || 
        c == 'u' || c == 'e' || c == 'o') {
       cout << "vowel" << endl;
    }
  else
    cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int m[55][55];
int qx[1000000],qy[1000000];
int s,e,x,y,ans;

void push(int bx,int by){
  e++;
  qx[e]=bx;
  qy[e]=by;
}
void pop(){
  x=qx[s];
  y=qy[s];
  s++;
}
void bfs(int bx,int by){
  s=0; e=-1;
  push(bx,by);
  m[by][bx]=0;
  while(s<=e){
    pop();
    for(int i=y-1;i<y+2;++i){
      for(int j=x-1;j<x+2;++j){
	if(m[i][j]){
	  push(j,i);
	  m[i][j]=0;
	}
      }
    }
  }
}
int main(){
  int w,h;
  while(cin>>w>>h,w){
    //init
    rep(i,55) rep(j,55) m[i][j]=0;
    ans=0;
    
    rep(i,h){
      rep(j,w){
	int a; cin>>a;
	m[i][j]=a;
      }
    }
    rep(i,h) rep(j,w)
      if(m[i][j]){
	bfs(j,i);
	ans++;
      }    
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3028