akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Prac
{
    class Prog
    {
        public static void Main()
        {
            var inputs = new List<String>();
            var results = new List<int>();
            String temp = "";

            while (true)
            {
                temp = Console.ReadLine();
                if (temp == "0")
                    break;
                inputs.Add(temp);
            }
            foreach (var i in inputs)
            {

                results.Add(sum(i.ToCharArray()));
            }
            foreach(var i in results)
            {
                Console.WriteLine(i);
                }
        }

        private static int sum(char[] ps)
        {
            var temp = 0;
            foreach (var p in ps)
            {
                temp += (p - 48);
            }
            return temp;
        }
    }
}

Measured memory_bytes: 19980
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long k, a, b;
  cin >> k >> a >> b;
  long long x = 1;
  long long t = k;
  long long ma = k + 1;
  if (a + 1 >= b)
  {
    cout << t + 1 << endl;
    return 0;
  }
  k -= (a - 1);
  if (k <= 0)
  {
    cout << t + 1 << endl;
    return 0;
  }
  x += (a - 1);
  k -= 2;
  if (k >= 0)
    x = b;
  if (k < 0)
  {
    cout << t + 1 << endl;
    return 0;
  }
  while (k > 0)
  {
    if (k >= 2)
    {
      k--;
      x -= a;
    }
    else
    {
      cout << x + k << endl;
      return 0;
    }
    k--;
    x += b;
  }
  ma = max(x, ma);
  cout << ma << endl;
}


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

typedef pair<int,int> P;
const int INF = 1000000000;

int main(){
    ll x,y;
    cin >> x >> y;
    int ans = 0;
    while(y >= x){
        y /= 2;
        ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();

int main() {
  int h, n;
  scanf("%d", &h);
  scanf("%d", &n);

  vector<int> arr(n);
  int sum = 0;

  REP(i, n) {
    scanf("%d", &arr[i]);
    sum += arr[i];
  }

  const char *str = (sum >= h ? "Yes" : "No");

  printf("%s\n", str);

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vll = vector<vl>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define RES(a, n) (a).resize(n)
ll n, q;
vl a, b, p, x;
vl cost;
vll G;
vector<bool> seen;
void dfs(ll v){
	seen[v] = true;
	for(auto nv : G[v]){
		if(seen[nv]) continue;
		cost[nv] += cost[v];
		dfs(nv);
	}
}
int main() {
	cin >> n >> q;
	RES(a, n-1);
	RES(seen, n);
	RES(G, n);
	RES(b, n-1);
	RES(cost, n);
	RES(p, q);
	RES(x, q);
	REP(i, n-1){
		cin >> a[i] >> b[i];
		G[a[i]-1].push_back(b[i]-1);
		G[b[i]-1].push_back(a[i]-1);
	}
	REP(i, q){
		cin >> p[i] >> x[i];
		cost[p[i]-1] += x[i];
	}
	dfs(0);
	REP(i, n){
		cout << cost[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 31404
n,*t=open(0).read().split()
n=int(n)
a=0
b=0
c=0

ans=0
for i in t:
    if i[0]=="B"and i[-1]=="A":
        a+=1
    elif i[0]=="B":
        b+=1
    elif i[-1]=="A":
        c+=1
    ans+=i.count("AB")
if a>0 and b>0 and c>0:
    ans+=a+1
    a=0
    b-=1
    c-=1
if a>0 and b>0:
    ans+=a
    a=0
    b-=1
if a>0 and c>0:
    ans+=a
    a=0
    c-=1
if a>0:
    ans+=a-1
    a=0
if b>0 and c>0:
    ans+=min(b,c)
print(ans)


Measured memory_bytes: 3828
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


typedef long long ll;

using namespace std;

int main() 
{ 

	ll h;
	cin >> h;

	ll i = 1;

	while (h){
		h /= 2;
		i *= 2;
	}

	cout << i - 1 << endl;

	return 0; 
} 


Measured memory_bytes: 256
a,b,c=map(int,input().split())
if a%2==1 or b%2==1 or c%2==1:
  print(0)
elif a==b==c:
  print(-1)
else:
  ans=0
  while a%2==0 and b%2==0 and c%2==0:
    ans+=1
    a1=(b+c)//2
    b1=(c+a)//2
    c1=(a+b)//2
    a=a1
    b=b1
    c=c1
  print(ans)

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	var l, r, sum int
	for i := 0; i < n; i++ {
		fmt.Scan(&l, &r)
		sum += r - (l - 1)
	}
  
	fmt.Println(sum)
}


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

int main(){

	int x,y,t;

	while(1){

		cin >> x >> y;

		if( x == y && x == 0 )break;

		if( x > y ){
		 t=y;
		 y=x;
		 x=t;

		}

		cout << x << " " << y << endl;
	}

	return 0;
}

Measured memory_bytes: 3028
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define eb emplace_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<30)
#define LLINF (1LL<<60)
#define MOD 998244353
typedef long long ll;
using namespace std;

int main(){
    int k;
    string s;
    cin>>k>>s;
    if(s.length()<=k)cout<<s;
    else{
        rep(i,k)cout<<s[i];
        cout<<"...";
    }
    return 0;
}


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

typedef long long ll;
#define PB push_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n, k, q; cin >> n >> k >> q;
	int freq[n] = {0};
	for (int i = 0; i < q; ++i) {
		int a; cin >> a;
		freq[a - 1]++;
	}
	for (int i = 0; i < n; ++i) {
		if (q - freq[i] < k) cout << "Yes" << "\n";
		else cout << "No" << "\n";
	}
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
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; }
const ll INF=1LL<<60;

int n,x,t;
ll ans;

int main(){
    cin>>n>>x>>t;
    if(n<=x) ans=t;
    else{
        ans=n/x*t;
        //n-=n/x;
        if(n%x!=0) ans+=t;
    }
    cout<<ans<<"\n";
    return 0;
}


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

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{int to;};
using graph = vector<vector<edge>>;

const int MOD = 998244353;
auto add(ll a, ll b){return (a + b) % MOD;}

struct ST {
  int s;
  vector<ll> v;
  ST(int n) : s{n}, v(2 * n) {}
  void update(int p, int val) {
    p += s;
    v[p] = add(v[p], val);
    for (p >>= 1; p; p >>= 1)
      v[p] = add(v[2 * p], v[2 * p + 1]);
  }
  ll query(int l, int r) {
    ll res = 0;
    for (l += s, r += s; l <= r; (++l) >>= 1, (--r) >>= 1) {
      if (l & 1) res = add(res, v[l]);
      if (~r & 1) res = add(res, v[r]);
    }
    return res;
  }
};

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

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

  vector<pii> jumps(k);
  trav(j, jumps) cin >> j.first >> j.second;

  ST st(n);
  vector<ll> dp(n);
  st.update(0, 1);
  dp[0] = 1;

  rep(i, 1, n) {
    for (auto [l, r]: jumps) {
      r = min(i, r);
      if (r < l) continue;
      auto delta = st.query(i - r, i - l);
      dp[i] = add(dp[i], delta);
    }
    st.update(i, dp[i]);
  }
  cout << dp[n - 1] << '\n';
}


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

int main(){
	int n;
  	int a,b;
  	cin >> n;
  	int count=0;
	for(int i = 0; i<n;i++) {
      	cin >> a >> b;
      	count += b-a+1;
    }
	cout << count << endl;
	
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(input())

# def LIST(): return list(map(str, input().split()))
# def LIST(): return list(input())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C = MAP()

if A == B:
    print(C)
elif A == C:
    print(B)
else:
    print(A)

Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
using edge = struct { int s, t; };
using edges = vector<edge>;

struct UnionFind {
  vector<int> data;
  UnionFind(int n) : data(n, -1) {}
  int root(int x) {
    return (data[x] < 0) ? x : data[x] = root(data[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int rank(int x) {
    -data[root(x)];
  }
};

main() {
  int N, M; cin >> N >> M;
  edges es;
  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    es.push_back({ a, b });
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    UnionFind uf(N);
    for (int j = 0; j < M; j++) {
      if (j == i) continue;
      uf.unite(es[j].s, es[j].t);
    }
    for (int j = 1; j < N; j++) {
      if (!uf.same(0, j)) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
  int H, W, checker;//定義, 入力
  cin >> H >> W;
  vector<vector<char>> result(H, vector<char>(W));
  vector<int> hight(H);
  vector<int> width(W);
  for (int i = 0; i < H; i++)
  for (int j = 0; j < W; j++)
  cin >> result.at(i).at(j);

  for (int i = 0; i < H; i++){//行列探し
    checker = 1;
    for (int j = 0; j < W; j++){
      if (result.at(i).at(j) == '#')
      checker = 0;
    }
    hight.at(i) = checker;
  }

  for (int i = 0; i < W; i++){
    checker = 1;
    for (int j = 0; j < H; j++){
      if (result.at(j).at(i) == '#')
      checker = 0;
    }
    width.at(i) = checker;
  }

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (hight.at(i) == 0 && width.at(j) == 0)
      cout << result.at(i).at(j);
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
template <class _T> static _T tp_gcd(_T first, _T second)
{
	_T num1 = first, num2 = second;
	_T remainder = 0, common = 0;

	if (!num1) return num2;
	if (!num2) return num1;

	while (!common) {
		remainder = num1 % num2;

		if (remainder == 0) {
			common = num2;
		}
		else {
			num1 = num2;
			num2 = remainder;
		}
	}
	return(common);
}
template <class _T> static _T tp_lcm(_T first, _T second) {
	_T num1 = first;
	_T num2 = second;

	if ((!num1) || (!num2)) return 0;
	while (num1 != num2) {
		if (num1 < num2) {
			num1 += first;
		}
		else if (num1 > num2) {
			num2 += second;
		}
	}

	return num1;
}
static void C_task();

int main()
{
	C_task();

	fflush(stdout);
	return 0;
}

static void C_task()
{
	LLONG A, B, C, D;
	get3int<LLONG>(A, B, C); get1int<LLONG>(D);

	LLONG lcm = tp_lcm<LLONG>(C, D);

	LLONG cCount = (B / C) - (A / C) + ((A % C) == 0 ? 1 : 0);
	LLONG dCount = (B / D) - (A / D) + ((A % D) == 0 ? 1 : 0);
	LLONG cdCount = (B / lcm) - (A / lcm) + ((A % lcm) == 0 ? 1 : 0);
	
	printf("%lld\n", (B - A + 1) - (cCount + dCount - cdCount));
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!{
        a: u64,
        bs: String,
    }

    let mut bs10x = bs.clone();
    bs10x.retain(|c| c != '.');

    let b10x: u64 = bs10x.parse().unwrap();
    println!("{}", a * b10x / 100);
}


Measured memory_bytes: 2152
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

ll gcd(ll x,ll y){
  if(x>y)swap(x,y);
  if(y%x==0)return x;
  return gcd(y-x*(y/x),x);
}

int main(){
  string s;
  cin >> s;
  int n=s.size();
  stack<char> ans;
  rep(i,n){
    if(s[i]=='S')ans.push('S');
    if(s[i]=='T'){
      if(i==0||ans.empty()){ans.push('T');continue;}
      char k=ans.top();
      if(k=='S')ans.pop();
      if(k=='T')ans.push('T');
    }
  }
  cout << ans.size() << endl;
}

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

int main() {
    int n,m,sou=0;
    cin >> n >> m;
    vector<int> hyou(n);
    rep(i,n){
        cin >> hyou[i];
        sou+= hyou[i];
    }
    sort(hyou.begin(),hyou.end());
    reverse(hyou.begin(),hyou.end());
    if(hyou[m-1] >= (sou-1)/(4*m)+1){
        cout << "Yes" << endl;
    }else{
        cout << "No" <<endl;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define dd double
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ll long long
#define ull unsigned long long
#define ld long double
#define mx 200005
#define mod 1000000007
#define fr first
#define cti(a) (a-48)
#define itc(a) char(a+48)
#define se second
#define End cout<<"\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define memo(Array,val) memset(Array, val, sizeof Array)
#define PI acos(-1)
bool check(ll n, ll pos){ return (n&(1<<pos)); }
bool Set(ll n, ll pos) {  return (n | (1<<pos)); }
ld LOG(ld b, ld e){ return log(b)/log(e); }




void solve()
{
    int a[mx+10];
    int n,k;

    unordered_map<int,ll>mp;
    unordered_map<int,ll>ans;
    set<int>s;

    cin >> n;
    for(int i=0;i<n;i++)cin >> a[i],s.insert(a[i]),mp[a[i]]++;
    ll tem=0;
    for(auto it:s)
    {
        int val=it;
        if(mp[val]>=2)tem+=(mp[val]*(mp[val]-1))/2;
    }

    for(int i=0;i<n;i++)
    {
        ll re=tem;
        if(mp[a[i]]>=2)
        {
            re-=(mp[a[i]]*(mp[a[i]]-1))/2;

        }
        if(mp[a[i]]>2)
        {
            re+=((mp[a[i]]-1)*(mp[a[i]]-2))/2;

        }
        cout << re << "\n";
    }

}

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


Measured memory_bytes: 14280
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> K;
    vi x(N);
    REP(i, K) {
        cin >> D;
        vi a(D);
        cin >> a;
        REP(j, D) {
            x[a[j] - 1]++;
        }
    }
    REP(i, N) {
        if (x[i] == 0) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <stdio.h>

#define INF 999999999

int H, W;
int a[64][64];
int b[64][64];

int h, w;
int c[64][64];

int main(void) {
	int i, j;
	int answer = -INF;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (scanf("%d", &a[i][j]) != 1) return 1;
		}
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (scanf("%d", &b[i][j]) != 1) return 1;
		}
	}
	if (scanf("%d%d", &h, &w) != 2) return 1;
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (scanf("%d", &c[i][j]) != 1) return 1;
		}
	}
	for (i = 0; i <= H - h; i++) {
		for (j = 0; j <= W - w; j++) {
			int ok = 1;
			int k, l;
			int score = 0;
			for (k = 0; k < h; k++) {
				for (l = 0; l < w; l++) {
					score += a[i + k][j + l];
					if (b[i + k][j + l] != c[k][l]) ok = 0;
				}
			}
			if (ok && score > answer) answer = score;
		}
	}
	if (answer == -INF) puts("NA"); else printf("%d\n", answer);
	return 0;
}



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

int main()
{
  int x,y,i,b;


  scanf("%d%d",&x,&y);
  

  if(x>=y)
    {
      
       while(1)
      {
        b=x%y;
	if(b==0) break;
	x=y%b;
	if(x==0) break;
	y=b%x;
	if(y==0) break;
      }
       if(b==0) printf("%d\n",y);
       else if(x==0) printf("%d\n",b);
       else printf("%d\n",x);
    }

  else
    {
      
       while(1)
      {
        b=y%x;
	if(b==0) break;
	y=x%b;
	if(y==0) break;
	x=b%y;
	if(x==0) break;
      }
       if(b==0) printf("%d\n",x);
       else if(y==0) printf("%d\n",b);
       else printf("%d\n",y);
    }
     
      
    
      
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define MAX_V 2005
#define INF (1e9)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//????????¨????§???????(???????????????????????????????????????)
struct edge{int to, cap,cost,rev;};

int V;                         //????????°
vector<edge> G[MAX_V];         //??°???????????£??\???????????¨???
ll dist[MAX_V];               //???????????¢
int prevv[MAX_V],preve[MAX_V]; //??´??????????????¨???

// from??????to??????????????????cap????????????cost???????????°????????????????????????
void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,G[to].size()});
  G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}

//s??????t????????????f???????°??????¨???????±???????
//??????????????´???-1?????????
ll min_cost_flow(int s,int t,int f){
  ll res=0;
  while(f>0){
    //????????????????????????????????????,s-t????????????????±???????
    fill(dist,dist+V,INF);
    dist[s]=0;
    bool update = true;
    while(update){
      update = false;
      for(int v=0; v<V ;v++){
	if(dist[v]==INF) continue;
	for(int i=0; i<G[v].size(); i++){
	  edge &e = G[v][i];
	  if(e.cap > 0 && dist[e.to] > dist[v]+e.cost) {
	    dist[e.to] = dist[v] + e.cost;
	    prevv[e.to] = v;
	    preve[e.to] = i;
	    update = true;
	  }
	}
      }
    }
    if(dist[t]==INF) return -1; //????????\??????????????????
    
    //s???t?????????????????£??????????????????
    int d = f;
    for(int v=t; v!=s; v=prevv[v])d=min(d,G[prevv[v]][preve[v]].cap);
    f -= d;
    res += d*dist[t];
    for(int v=t; v!=s; v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int a[MAX_V],b[MAX_V],w[MAX_V];
vector<P> v;

int main(){
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    
    for(int i=0;i<n;i++){
      cin>>a[i]>>b[i]>>w[i];
      v.push_back(P(a[i],i));
    }
    sort(v.begin(),v.end());

    int s=n*2,g=s+1;
    
    for(int i=0;i<n;i++){
      add_edge(s,i*2,1,0);
      add_edge(i*2,i*2+1,1,-w[i]);
      add_edge(i*2+1,g,1,0);

      for(int j=0;j<v.size();j++){
	if(i==v[j].second)continue;
	if(b[i]<v[j].first)
	  add_edge(i*2+1,v[j].second*2,1,0);
      }
    }

    V=g+1;

    cout<<-min_cost_flow(s,g,2)<<endl;
    
    for(int i=0;i<V;i++)G[i].clear();
    v.clear();
  }
  return 0;
}

Measured memory_bytes: 25848
#include<stdio.h>
#include<stdarg.h>
#include<stdint.h>
inline long _max(long a, long b){return a>b?a:b;}
long max(long a, ...){
	long res = INT64_MIN;
	va_list ap;
	va_start(ap, a);
	for(int i=0; i<a; i++){
		res = _max(res, va_arg(ap, long));
	}
	va_end(ap);
	return res;
}
int main(){
	long a, b, c, d;
	scanf("%ld%ld%ld%ld", &a, &b, &c, &d);
	printf("%ld\n", max(4, a*c, a*d, b*c, b*d));
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll a,b,c;
  cin >> a >> b >> c;

  int num = 0;
  ll na,nb,nc;
  for(int i = 0; i < 100; i++){
    if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
      break;
    } else { 
      num++;
      na = b/2 + c/2;
      nb = a/2 + c/2;
      nc = a/2 + b/2;
      a = na;
      b = nb;
      c = nc;
    }
  }

  cout << (num==100 ? -1 : num) << endl;
}



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

const int MAXN = 4001;

int r[MAXN], g[MAXN], b[MAXN];

int64_t solve(int n, const std::string& s) {
  r[n] = g[MAXN] = b[MAXN] = 0;
  for (int i = n - 1; i >= 0; --i) {
    r[i] = r[i + 1];
    g[i] = g[i + 1];
    b[i] = b[i + 1];
    if (s[i] == 'R') ++r[i];
    else if (s[i] == 'G') ++g[i];
    else ++b[i];
  }

  int64_t ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (s[i] == s[j]) continue;
      int *p;
      char ch = 'R';
      if (s[i] != 'R' && s[j] != 'R') p = r, ch = 'R';
      else if (s[i] != 'G' && s[j] != 'G') p = g, ch = 'G';
      else p = b, ch = 'B';
      ans += p[j + 1];
      if (j + j - i < n && s[j + j - i] == ch) --ans;
    }
  }
  return ans;
}

int main() {
  int n;
  std::string s;
  std::cin >> n >> s;
  std::cout << solve(n, s) << std::endl;
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

class mint{
	static const int MOD=998244353;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<int> x(m),y(m),c(m);
	map<pair<int,int>,int> C;
	rep(i,m){
		scanf("%d%d%d",&y[i],&x[i],&c[i]); y[i]--; x[i]--;
		if(C.count({y[i],x[i]})>0){
			if(C[{y[i],x[i]}]!=c[i]) return puts("0"),0;
		}
		else{
			C[{y[i],x[i]}]=c[i];
			if(abs(x[i]-y[i])>2) C[{x[i],y[i]}]=c[i];
		}
	}

	lint cnt=(n-3LL)*(n-2);
	for(auto p:C){
		int y,x; tie(y,x)=p.first;
		if(abs(x-y)>2) cnt--;
	}
	cnt/=2;

	// dp[i][c] = 対角線から距離 2 以内のマスについて, 対角線上のマスの色を左上から右下にかけて決めていくとき,
	//            マス (i, i) まで決めて, その色が c であるような場合の数
	mint dp[100001][2];
	if(C.count({0,0})>0) dp[0][C[{0,0}]]=1;
	else                 dp[0][0]=dp[0][1]=1;
	for(int i=1;i<n;i++){
		int c0=-1,c1=-1,c2=-1,c3=-1,c4=-1;
		if(C.count({i,i})>0)   c0=C[{i,i}];
		if(C.count({i-1,i})>0) c1=C[{i-1,i}];
		if(C.count({i,i-1})>0) c2=C[{i,i-1}];
		if(i==1) c3=0;
		else if(C.count({i-2,i})>0) c3=C[{i-2,i}];
		if(i==1) c4=0;
		else if(C.count({i,i-2})>0) c4=C[{i,i-2}];

		rep(j0,2) if(c0==-1 || c0==j0) {
			rep(j1,2) if(c1==-1 || c1==j1) {
				rep(j2,2) if(c2==-1 || c2==j2) {
					rep(j3,2) if(c3==-1 || c3==j3) {
						int j4=((j0+j1+j2)%2==0?j3:1-j3);
						if(i==1 || c4==-1 || c4==j4){
							dp[i][j0]+=dp[i-1][(j0+j1+j2)%2];
						}
					}
				}
			}
		}
	}
	cout<<(dp[n-1][0]+dp[n-1][1])*pow(mint(2),cnt)<<'\n';

	return 0;
}


Measured memory_bytes: 7808
s = input()
t = input()
min_num = len(t)
tbd = 0
for i in range(0,len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i:i+len(t)][j] != t[j]:
            tbd += 1
    if tbd <= min_num:
        min_num = tbd
    tbd = 0

print(min_num)


Measured memory_bytes: 9104
#include<iostream>
using namespace std;
int main(){
  int m,f,r;
  cin >> m >> f >> r;
  while(m!=-1||f!=-1||r!=-1){
    if(m==-1||f==-1) cout << "F" << endl;
    else if(m+f>=80) cout << "A" << endl;
    else if(m+f>=65) cout << "B" << endl;
    else if(m+f>=50) cout << "C" << endl;
    else if(m+f>=30)
      if(r>=50) cout << "C" << endl;
      else cout << "D" << endl;
    else cout << "F" << endl;

    cin >> m >> f >> r;
  }
  return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 10000000000
#define MAX 500008

int main(){
  int H,W,M;
  cin>>H>>W>>M;
  vector<int> h(M),w(M);
  for(int i=0;i<M;i++){
    cin>>h[i]>>w[i];
    h[i]--;
    w[i]--;
  }

  set<pair<int,int>> s;

  vector<pair<int,int>> row(H,make_pair(0,0)),col(W,make_pair(0,0));
  for(int i=0;i<M;i++){
    row[h[i]].first++;
    col[w[i]].first++;
    s.insert(make_pair(h[i],w[i]));
  }
  for(int i=0;i<H;i++){
    row[i].second=i;
  }
  for(int j=0;j<W;j++){
    col[j].second=j;
  }

  int ans=0;
  for(int i=0;i<M;i++){
    ans=max(ans,row[h[i]].first+col[w[i]].first-1);
  }

  sort(row.begin(),row.end());
  sort(col.begin(),col.end());
  int k=lower_bound(row.begin(),row.end(),make_pair(row[H-1].first,0))-row.begin();
  int l=lower_bound(col.begin(),col.end(),make_pair(col[W-1].first,0))-col.begin();
  if(((ll)H-(ll)k)*((ll)W-(ll)l)>(ll)M){
    ans=max(ans,row[H-1].first+col[W-1].first);
  }else{
    for(int i=k;i<H;i++){
      for(int j=l;j<W;j++){
        if(s.count(make_pair(row[i].second,col[j].second))==1){
          ans=max(ans,row[i].first+col[j].first-1);
        }else{
          ans=max(ans,row[i].first+col[j].first);
        }
      }
    }
  }

  cout<<ans<<endl;

}


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

int main(){
	int N,K;
	string S;
	cin >> N >> K >> S;
	if(S[K-1]>=97 && S[K-1]<=122){
	        S[K-1] -= 32;
	}else{
		S[K-1]+=32;
	}
	cout << S << "\n";
}


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

using namespace std;
#define ll long long
#define ld long double
const int N=2e5 + 5;
const ll mod = 1e9 + 7;
 
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    ll n, k;
    cin >> n >> k;
    ll res = 0LL;
    for(ll i=k;i<=n+1;i++) {
        ll mn = i*(i-1)/2;
        ll mx = n*i - i*(i-1)/2;
        res += mx - mn + 1;
        res %= mod;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3680
#include<stdio.h>
int main(void){
	int a[10]={0},i,j,b=0;
	for(i=0;i<10;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<10;i++){
		for(j=0;j<i;j++){
			if(a[j]<=a[i]){
				b=a[i];
				a[i]=a[j];
				a[j]=b;
			}
		}
	}
	for(i=0;i<3;i++){
		printf("%d\n",a[i]);
	}
	return 0;
}


Measured memory_bytes: 2024
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>

using namespace std;

typedef long long LL;

LL gcd(LL a, LL b)
{
    return b ? gcd(b, a % b) : a;
}

int main()
{
    LL a, b;
    cin >> a >> b;
    
    LL d = gcd(a, b);
    
    int cnt = 1;
    for(int i = 2; i <= d / i; i ++)
        if(d % i == 0)
        {
            cnt ++;
            while(d % i == 0)  d /= i;
        }
    if(d > 1)  cnt ++;
    printf("%d", cnt);
	return 0;
}

Measured memory_bytes: 888
n, k = map(int, input().split())
r,s,p = map(int, input().split())
t=input()

def zyanken(x):
    if x=="r":
        return p
    elif x=="s":
        return r
    elif x=="p":
        return s

str_list = []
for i in range(k):
    str_list.append(t[i::k])

ans = 0

for g in str_list:
    hand = ""
    for l in range(len(g)):
        if l==0:
            hand+=g[0]
            ans+=zyanken(g[0])
        elif hand[l-1]==g[l]:
            hand+="n"
            ans+=0
        else:
            hand+=g[l]
            ans+=zyanken(g[l])

print(ans)

Measured memory_bytes: 8828
def main():
    N = int(input())
    lst = []
    for i in range(1, N+1):
        inp = input().split()
        inp[1] = int(inp[1]) * -1
        inp.append(i)
        lst.append(inp)
    newLst = sorted(lst)
    for j in range(N):
        print(newLst[j][2])
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include  <stdio.h>


int main()
{

  int i, j, n;
  int C[100000];
  
  scanf("%d",&n);
  int A[n+1], B[n+1];
  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
  }

  for(i=0;i<=10000;i++){
    C[i] = 0;
  }
	    
  for(i=0;i<n;i++){
    C[A[i+1]]++;
  }

  for(i=1;i<=10000;i++){
    C[i] = C[i] + C[i-1];
  }

  for(j=1;j<=n;j++){ 
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i > 1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;

}



Measured memory_bytes: 17368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, n;
  string s;
  in(s);
  n = s.size();
  a = n * (n - 1) / 2;
  vector<ll> c(26, 0);
  char f = 'a';
  rep(i, 26){
    rep(j, n){
      if(f == s[j])
        c[i]++;
    }
    f++;
  }
  rep(i, 26){
    a -= c[i] * (c[i] - 1) / 2;
  }
  out(a + 1);
  memi;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
import bisect
from logging import getLogger, StreamHandler, DEBUG, WARNING
logger = getLogger(__name__)
handler = StreamHandler()
handler.setLevel(DEBUG)
logger.setLevel(DEBUG)
# handler.setLevel(WARNING)
# logger.setLevel(WARNING)
logger.addHandler(handler)



# class SegTree():
#     def __init__(self, n):
#         self.value = [0 for i in range(n*2)]

# MOD = 10 ** 9 + 7

# def getinvmod(n):
#     return [pow(i, MOD-2, MOD) for i in range(n+1)]

def main():
    ans = 0
    a,b,c,x,y = getList()


    if x > y:
        ans1 = (c * 2 * y + a * (x - y))
    else:
        ans1 = (c * 2 * x + b * (y - x))

    ans2 = (a * x + b * y)

    ans3 = c * 2 * max(x, y)

    print(min(ans1, ans2, ans3))
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 43628
#include<cstdio>

#define ran 1011

struct modular_arithmetic{
	int mod;

	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	int add(int x,int y){return (x+=y)<mod?x:x-mod;}
	int sub(int x,int y){return (x-=y)>=0?x:x+mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
};
modular_arithmetic ma;

int n, m;
int r_ma[ran], c_ma[ran];
bool r[ran*ran], c[ran*ran];

int main() {
	scanf("%d%d", &n, &m);
	for(int i=1;i<=n;i++) {
		scanf("%d", &r_ma[i]);
		r[r_ma[i]] = true;
	}
	for(int i=1;i<=m;i++) {
		scanf("%d", &c_ma[i]);
		c[c_ma[i]] = true;
	}
	
	int ans = 1;
	int got_r = 0, got_c = 0;
	for(int i = n*m; i>0 && ans>0; i--) {
		if (r[i] && c[i]) {
			got_r ++; got_c ++;
		} else
		if (r[i]) {
			ans = ma.mul(ans, got_c);
			got_r ++;
		} else
		if (c[i]) {
			ans = ma.mul(ans, got_r);
			got_c ++;
		} else {
			ans = ma.mul(ans, got_r * got_c - (n*m-i));
		}
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

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

void main() {
    while (true) {
        long n, m;
        scanf("%lld %lld\n", &n, &m);
        writeln(gcd(n, m), " ", lcm(n, m));
        if (stdin.eof) break;
    }
}

Measured memory_bytes: 1044
const main = (input) => {
	const args = input.trim().split(" ");
	const x = args[0];
	const y = args[1];

 const z = y % 2;
 if(z !== 0){
	 console.log('No');
	 return;
 }

	const a = (2 * x) - (y / 2);
	const b = (-1 * x) + (y / 2);
	if(a < 0 || b < 0){
		console.log('No');
		return;
	}
	console.log('Yes');
}

main(require("fs").readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29628
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;

signed main(){
	int n,q,p[100010],tmp = 0;
	set<int> st;
	cin >> n >> q;
	st.insert(0);
	for(int i = 0;i < n;i++) p[i] = i;
	for(int i = 0;i < q;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		if(tmp >= 1) st.insert(p[tmp - 1]);
		if(tmp < n - 1) st.insert(p[tmp + 1]);
		if(tmp == a) tmp = b;
		else if(tmp == b) tmp = a;
		swap(p[a],p[b]);
	}
	if(tmp >= 1) st.insert(p[tmp - 1]);
	if(tmp < n - 1) st.insert(p[tmp + 1]);
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007;
#define INF 1000000000000000001;
#define ll long long
vector<vector<int>>g;
vector<pair<int,int>>wg[12345];

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  double s=0.0,a;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>a;
    s+=(1/a);
  }
  cout<<(1/s)<<endl;


  return 0;
}


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

using namespace std;

int main(void) {
  int N; cin >> N;
  vector<pair<int, long long>> V[N+1];

  for (int i = 0; i < N; i++) {
    int u, v; long long w;
    cin >> u >> v >> w;
    V[u].push_back(make_pair(v, w));
    V[v].push_back(make_pair(u, w));
  }

  long long dist[N+1];
  memset(dist, 0xff, sizeof(dist));
  dist[1] = 0;
  vector<int> prev, next;
  next.push_back(1);

  while (!next.empty()) {
    prev = next;
    next.clear();

    for (auto it = prev.begin(); it != prev.end(); ++it) {
      for (auto jt = V[*it].begin(); jt != V[*it].end(); ++jt) {
        if (dist[jt->first] == -1) {
          next.push_back(jt->first);
          dist[jt->first] = dist[*it] + jt->second;
        }
      }
    }
  }

  for (int i = 1; i <= N; i++) cout << (dist[i] & 1) << endl;

  return 0;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll k;cin>>k;
    ll a;cin>>a;
    ll b;cin>>b;
    bool flag=false;
    for(int i=a;i<=b;i++){
        if(i%k==0) flag=true;
    }
    cout<<(flag?"OK":"NG")<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e6 +1)
#define INFL LLONG_MAX
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

ll binpow(ll a, ll b) {
	ll x = 1;
	while (b) {
		if (b & 1) x = x * a;
		a = a * a;
		b >>= 1;
	}
	return x;
}

ll mult(ll a, ll b) {
	ll x = 0;
	while (b) {
		if (b & 1) x = (x + a);
		a = (a + a);
		b >>= 1;
	}
	return x;
}

ll gcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll d = gcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * (a / b);
	return d;
}



int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;

	// Write your code here

	int t = 1;
	//cin >> t;
	while (t--) {
		ll x, n;
		cin >> x >> n;
		vb v(102, false);
		for (int i = 0; i < n; i++) {
			ll a;
			cin >> a;
			v[a] = true;
		}
		if (n == 0) {
			cout << x << "\n";
			return 0;
		}
		ll ans1 = x;
		while (v[ans1]) {
			ans1--;
		}
		ll ans2 = x;
		while (v[ans2]) {
			ans2++;
		}
		if (abs(ans2 - x) < abs(x - ans1)) {
			cout << ans2 << "\n";
		} else {
			cout << ans1 << "\n";
		}
	}


	return 0;
}

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

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

	bool f = false;
	while (n)
	{
		f |= (n % 10 == 7);
		n /= 10;
	}

	cout << (f ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<stdbool.h>
#define SWAP(type,a,b) { type temp = a; a = b; b = temp; }

int bubbleSort(int A[], int N){
  int sw = 0;
  int i, j;
  bool flag = 1;
  for( i = 0; flag ; i++){
    flag = 0;
    for( j = N -1; j >= i + 1 ; j--){
      if( A[j] < A[j-1] ){
        SWAP(int,A[j], A[j-1] );
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main(){
  int A[100], N, sw, end1, i;
  scanf("%d",&N);
  for( int i = 0; i < N; i++) scanf("%d", &A[i]);

  sw = bubbleSort( A, N);
  for(i = 0; i < N ; i++){
    if(i) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d", sw);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2064
#include <string.h>
#include <stdio.h>

int main(void)
{
    char s[101] = {'\0'};
    scanf("%s", s);
    char ss[202] = {'\0'};
    char p[101] = {'\0'};
    scanf("%s", p);
    snprintf(ss, 202,"%s%s", s, s);
    if (strstr(ss, p) != NULL) printf("Yes\n");
    else printf("No\n");
  
    return 0;
}


Measured memory_bytes: 2148
//#include "stdafx.h"
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
/*int gcd(int n,int m)
{
	if(m==0)
		return n;

	return gcd(m, n % m);
}*/
bool comp (int x,int y){
	return x>y;
}
int n,a[101],A,B;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	set<char>st;

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

	sort(a,a+n,comp);

	for(int i=0;i<n;i++){
		if(i%2==0)A+=a[i];
		else
			B+=a[i];
	}
	cout<<A-B<<"\n";


	return 0;
}

Measured memory_bytes: 3640
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

const MX: usize = 1010101;
#[fastout]
fn main() {
    input! {
        n:i64,k:i64,
    }
    let mut ans = 0;
    let mut cnts = vec![0; MX];
    for gcds in (1..=k).rev() {
        let mut l = k / gcds;

        let mut al = mod_pow(l, n, MOD);
        for mul in 2..=l {
            al -= cnts[(mul * gcds) as usize];
            al = (al + MOD) % MOD;
        }
        cnts[gcds as usize] = al;
        ans += al * gcds;
        ans %= MOD;
    }
    println!("{}", ans);
}
const MOD: i64 = 1000000007;
/// x ^ n % m
pub fn mod_pow(x: i64, n: i64, m: i64) -> i64 {
    let mut res = 1;
    let mut x = x % m;
    let mut n = n;
    while n > 0 {
        if n & 1 == 1 {
            res = (res * x) % m;
        }
        x = (x * x) % m;
        n >>= 1;
    }
    res
}


Measured memory_bytes: 2800
main :: IO ()
main = do
  s <- getLine
  putStrLn $ ans s

ans :: String -> String
ans s
  | elem h2 month && elem l2 month = "AMBIGUOUS"
  | elem h2 month && elem l2 year = "MMYY"
  | elem h2 year && elem l2 month = "YYMM"
  | otherwise = "NA"
  where
    h2 = take 2 s
    l2 = drop 2 s
    month = ["01","02","03","04","05","06","07","08","09","10","11","12"]
    year = "00" : month ++ (map show [13..99])

Measured memory_bytes: 508
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi can(10100);
	can[0] = 1;
	rep(i, n){
		int s; cin >> s;
		for(int j = 10000; j >= 0; j--) if(can[j]) can[j + s] = 1;
	}
	int ans = 0;
	rep(i, 10001) if(i % 10 && can[i]) ans = max(ans, i);
	cout << ans << endl;
	return 0;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    ll q, h, s, d;
    cin >> q >> h >> s >> d;
    ll n;
    cin >> n;

    vector<ll> val2(4);
    val2[0] = q * 8;
    val2[1] = h * 4;
    val2[2] = s * 2;
    val2[3] = d;
    sort(val2.begin(), val2.end());

    ll ans = (n / 2) * val2[0];
    if (n % 2) {
        vector<ll> val1(3);
        val1[0] = q * 4;
        val1[1] = h * 2;
        val1[2] = s;
        sort(val1.begin(), val1.end());
        ans += val1[0];
    }

    cout << ans << '\n';
    return 0;
}


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

if N==0:
    print(X)
else:
    p = list(map(int, input().split()))
    for i in range(100): #多分100もいらない
        if X-i not in p:
            print(X-i)
            break
        if X+i not in p:
            print(X+i)
            break


Measured memory_bytes: 61848
n = int(input())
cs = []
ss = []
fs = []
for i in range(n - 1):
    c, s, f = input().split()
    c = int(c)
    s = int(s)
    f = int(f)
    cs.append(c)
    ss.append(s)
    fs.append(f)
for i in range(n):
    t = 0
    for j in range(i, n - 1):
        c, s, f = cs[j], ss[j], fs[j]
        if t < s:
            t = s + c
        elif t % f == 0:
            t += c
        else:
            t += f - t % f + c
    print(t)

Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

string s, t;
int n, m, nm, nxt[500009], cnt, ans;
vector<int> vec[500009];
int ind[500009], ld[500009];

void fun()
{
	nxt[0] = -1;
	for (int i = 1, j  = 0; i < m; i++, j++) {
		while (t[i] != t[j]) {
			j--;
			if (j < 0) break;
			j = nxt[j] + 1;
		}
		nxt[i] = j;
	}
}

void gun(int cur, int v)
{
	cnt++;
	ld[cur] = max(ld[cur], v);
	ans = max(ans, ld[cur]);
	if (ind[cur] == 0) {
		for (int i = 0; i < (int)vec[cur].size(); i++) {
			ind[vec[cur][i]]--;
			gun(vec[cur][i], ld[cur] + 1);
		}
	}
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s >> t;
	n = s.length();
	m = t.length();
	nm = n + m;
	fun();
	for (int i = 0, j = 0; i < nm; i++, j++) {
		if (j == m) {
			vec[(i - m) % n].pb(i%n);
			ind[i%n]++;
			j = nxt[j - 1] + 1;
		}
		while (s[i%n] != t[j]) {
			j--;
			if (j < 0) break;
			j = nxt[j] + 1;
		}
	}
	for (int i = 0; i < n; i++) {
		if (ind[i] == 0)
			gun(i, 0);
	}
	if (cnt < n)
		cout << -1 << E;
	else {
		cout << ans << E;
	}
	//system("pause");
	return 0;
}

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

int main(){
  string str;
  cin >> str;
  for(int i = 0;i < 3;i++){
    if(str.at(i) == '7'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main(){
  int n;
  int a[110];
  cin >> n;
  int x;
  int sum = 0;
  for(int i=0;i<n;i++){
    cin >> x;
    a[i] = x;
    sum += x;
  }
  int before = sum;
  for(int i=0;i<110;i++){
    sum = before - a[i]*2;
    if(sum < 0){
      if(-sum < before){
        cout << -sum << flush;
      }else{
        cout << before << flush;
      }
      break;
    }
    before = sum;
  }
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int d;
  cin>>d;
  cout<<"Christmas";
  while(d<25){
    cout<<" Eve";
    d++;
  }
  return(0);
}



Measured memory_bytes: 256
n,p = map(int,input().split())
a = list(map(int,input().split()))
ans = o = e = 0
for i in a:
    if i%2==0:e+=1
    else:o+=1

from math import factorial
ec = 0
for i in range(e+1):
    ec += factorial(e)//(factorial(e-i)*factorial(i))
oc = 0
if p==0:
    for i in range(o+1):
        if i%2==0:
            oc += factorial(o)//(factorial(o-i)*factorial(i))
else:
    for i in range(o+1):
        if i%2==1:
            oc += factorial(o)//(factorial(o-i)*factorial(i))
print(oc*ec)

Measured memory_bytes: 3064