akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val (N, W) = readLine()!!.split(" ").map { it.toInt() }

    // dp を 0 で初期化
    val dp = Array(N + 1) { LongArray(W + 1) { 0 } }

    for (i in 1 until N + 1) {
        // 各アイテムが与えられる毎に dp の行を更新
        val (w, v) = readLine()!!.split(" ").map { it.toInt() }

        // アイテム i を加えるかどうかをすべての重み上限の場合で考える
        for (j in 1 until W + 1) {
            // それまでのアイテム取得で重みは使い切っているが，価値が高い場合と，それまでに使い切らずに，今回足す場合を考える
            if (j - w >= 0) {
                // アイテムが加えられる可能性がある場合は，加える場合と加えない場合を考える
                dp[i][j] = Math.max(dp[i - 1][j - w] + v, dp[i - 1][j])
            } else {
                // アイテムが加えられる可能性が無い場合は，加えない場合で最大となる値を持ってくる
                // １つ前までのアイテムで同じ重さ
                dp[i][j] = dp[i - 1][j]
            }
        }
    }

    println(dp[N][W])
}


Measured memory_bytes: 156396
#include<iostream>
#include<string>
#include<vector>
 
using namespace std;
 
int main() {
 
	int N;
	long long C = 0;
 
	cin >> N;
	vector<int> A(N + 1);
	vector<int> B(N);
 
	for (int i = 0; i < N + 1; i++)
	{
		cin >> A[i];
	}
	for (int i = 0; i < N ; i++)
	{
		cin >> B[i];
	}
 
 
 
	for (int i = 0; i < N; i++)
	{
		if (A[i] - B[i] >= 0) {
			C += B[i];
		}
		else {
			B[i] -= A[i];
			C += A[i];
			A[i] = 0;
 
			if (A[i + 1] - B[i] >= 0) {
				A[i + 1] -= B[i];
				C += B[i];
			}
			else {
				C += A[i + 1];
				A[i + 1] = 0;
			}
		}
	}
	cout << C;
 
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
#define int long long
#define INT INT_MAX
#define LONG LLONG_MAX
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
typedef long long ll;
using namespace std;

ll GCD(ll a, ll b) {
	if (b == 0)return a;
	return GCD(b, a%b);
}

ll LCM(ll a, ll b) {
	return a / GCD(a, b)*b;
}

ll mypow(ll a, ll b, ll c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	else return mypow(a, b / 2, c)*mypow(a, b / 2, c) % c;
}

signed main() {
	string s;
	map<char, bool> m;
	cin >> s;
	f(i, s.size()) m[s[i]] = true;
	if ((m['N'] == m['S']) && (m['W'] == m['E'])) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

int main()
{
    int n, m;
    string pass[256];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> pass[i];
    }
    cin >> m;
    string input;
    bool isopen = false;
    for(int i = 0; i < m; i++){
        cin >> input;
        bool isfound = false;
        for(int j = 0; j < n; j++){
            if(pass[j] == input){
                isfound = true;
                break;
            }
        }
        if(isfound){
            if(!isopen) cout << "Opened by " << input << endl;
            else cout << "Closed by " << input << endl;
            isopen = !isopen;
        } else cout << "Unknown " << input << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから

void solve(){
  int a,b,t;
  cin>>a>>b>>t;
  cout<<t/a*b;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx")
#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 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())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 998244353;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int n, k, p[1005], ans;
int main(){
	cin>>n>>k;
	repn(i, n) cin >> p[i];
	sort(p+1, p+n+1);
	repn(i, k) ans+=p[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cmath>

using namespace std;

int main(void){
  long long a, b, ans;
  cin >> a >> b;
  if(a == b)
    cout << a << endl;
  else{
    if(a%2==0&&b%2!=0){
      ans = (b-a+1)/2;
      if(ans%2==0)
        cout << 0 << endl;
      else
        cout << 1 << endl;
    }
    else if(a%2!=0&&b%2==0){
      ans = (b-a)/2;
      if(ans%2==0){
        ans = a^b;
        ans = ans^0;
        cout << ans << endl;
      }
      else{
        ans = a^b;
        ans = ans^1;
        cout << ans << endl;
      }
    }
    else if(a%2==0&&b%2==0){
      ans= (b-a) / 2;
      if(ans%2==0){
        ans=b^0;
        cout << ans << endl;
      }
      else{
        ans=b^1;
        cout << ans << endl;
      }
    }
    else{
      ans=(b-a)/2;
      if(ans%2==0){
        ans = a^0;
        cout << ans << endl;
      }
      else{
        ans=a^1;
        cout << ans << endl;
      }
    }
  }
  return 0;
}


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

void solve(int sx,int sy,int tx,int ty,string&ans){
	int xd=tx-sx,yd=ty-sy;
	if(yd>0)while(yd--)ans+='U';
	else while(yd++)ans+='D';
	if(xd>0)while(xd--)ans+='R';
	else while(xd++)ans+='L';
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
	string ans;
	solve(sx,sy,tx,ty,ans);
	solve(tx,ty,sx,sy,ans);
	ans+='L';
	solve(sx-1,sy,tx,ty+1,ans);
	ans+="DR"s;
	solve(tx+1,ty,sx,sy-1,ans);
	ans+='U';
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator
const int MxN = 1e5;
ll ar[MxN];
int n;
ll solve() {    
    ll res = 0;
    ll sum = 0;
    for(int i=0;i<n;i++) {
        if (i % 2 == 0) {
            if (sum + ar[i] <= 0) {
                res += llabs(sum + ar[i] - 1);
                sum = 1;
            } else 
                sum += ar[i];
        } else {
            if (sum + ar[i] >= 0) {
                res += llabs(sum + ar[i] + 1);
                sum = -1;
            } else 
                sum += ar[i];
        }
    }
    return res;
}

int main() {
    cin>>n;
    for(int i=0;i<n;i++) cin>>ar[i];
    ll a =solve();
    for(int i=0;i<n;i++) ar[i] = -ar[i];
    ll b =solve();
    cout<<min(a, b)<<endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	static class Word implements Comparable<Word>{
		int id;
		String word;
		ArrayList<Integer> page = new ArrayList<Integer>();
		
		Word (int id, String word, int page) {
			this.id = id;
			this.word = word;
			this.page.add(page);
		}

		public int compareTo(Word x) {
			return this.word.compareTo(x.word);
		}
	}
	
	public static void main (String args[]) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Word> dict = new ArrayList<Word>();
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		int id;
		
		id = 0;
		while (sc.hasNext()) {
			String word = sc.next();
			int page = sc.nextInt();
			if (map.get(word) == null) {
				map.put(word, id++);
				dict.add(new Word(id, word, page));
			} else {
				Word w = dict.get(map.get(word));
				w.page.add(page);
			}
		}
		Collections.sort(dict);
		for (Word w: dict) {
			Collections.sort(w.page);
			System.out.println(w.word);
			String s = "";
			for (Integer i: w.page) {
				System.out.print(s + i);
				s = " ";
			}
			System.out.println();
		}
	}
}

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

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if (s == u){
    a--;
  }
  else{
    b--;
  }
  cout << a << ' ' << b << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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) { return a/gcd(a,b)*b;}
 
int dp[1000000];
string s;

int main () {
  cin >> s;
  dp[0] = 1;
  rep(i,s.size()) {
    if (dp[i] == 0) continue;
    if (i+5<=s.size() && s.substr(i,5) == "dream") dp[i+5] = 1;
    if (i+7<=s.size() && s.substr(i,7) == "dreamer") dp[i+7] = 1;
    if (i+5<=s.size() && s.substr(i,5) == "erase") dp[i+5] = 1;
    if (i+6<=s.size() && s.substr(i,6) == "eraser") dp[i+6] = 1;
  }

  puts(dp[s.size()]==1 ? "YES" : "NO");
}

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

int main()
{
  long long int N, M;
  cin >> N >> M;
  vector<long long int> a(M);
  for (int i = 0; i < M; i++)
  {
    cin >> a[i];
  }
  long long int MOD = 1000000007;
  vector<long long int> ans(N + 1);
  if (M > 0)
  {
    ans[0] = 1;
    int j;
    if (a[0] != 1)
    {
      ans[1] = 1;
      j = 0;
    }
    else
    {
      ans[1] = 0;
      j = 1;
    }
    long long int nowa = a[j];
    for (int i = 2; i <= N; i++)
    {
      if (i == nowa)
      {
        ans[i] = 0;
        j++;
        if (j <= M - 1)
          nowa = a[j];
      }
      else
        ans[i] = (ans[i - 1] + ans[i - 2]) % MOD;
    }
    long long int res = ans[N] % MOD;
    cout << res << endl;
  }
  else
  {
    ans[0] = 1, ans[1] = 1;
    for (int i = 2; i <= N; i++)
    {
      ans[i] = (ans[i - 1] + ans[i - 2]) % MOD;
    }
    long long int res = ans[N] % MOD;
    cout << res << endl;
  }
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for (int i = 0; i < N; ++i){
        cin >> A.at(i);
    }
    int votes = accumulate(A.begin(), A.end(), 0);
    int valid = count_if(A.begin(), A.end(), 
        [votes, M](int x)->bool{return(x * 4 * M >= votes);});
    if (valid >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
 
#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

ll gcd(ll x, ll y) {
    // if (x < y) swap(x, y);
    if (!y) return x;
    return gcd(y, x % y);
}

// int main() {
//     ll n, ans = 0;
//     cin >> n;
//     ll a[n];
//     rep(i,0,n) cin >> a[i];
//     ll hoge = 0;
//     rep(i,0,n) {
//         hoge = 0;
//         rep(j,0,n) {
//             if (i != j) {
//                 // cout << hoge << endl;
//                 hoge = gcd(a[j], hoge);
//             }
//         }
//         ans = max(ans, hoge);
//     }
//     cout << ans << endl;
//     return 0;
// }

int main() {
    ll n, ans = 0;
    cin >> n;
    ll a[n];
    rep(i,0,n) cin >> a[i];
    ll plus = 0;
    rep(i,0,n) {
        if (a[i] >= 0) {
            plus++;
        }else{
            a[i] = -a[i];
        }
    }
    sort(a, a+n);
    rep(i,0,n)ans += a[i];
    if ((n - plus) % 2 == 0) {
        cout << ans << endl;
    }else{
        cout << ans - 2*a[0] << endl;
    }
    return 0;
}

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

int main() {
	// your code goes here
	long long  a,b,n;
	cin>>a>>b>>n;
	long long  x = 0;
	if(n<b) x = n;
	else x = b-1;
	//else x = b-1;
	long long  val = (a*x)/b - a*(x/b);
	cout<<val<<endl;
	return 0; 
}


Measured memory_bytes: 3644
#include<stdio.h>

int main(void){
  int coordinates[10][10] = {0};
  int x,y,size;
  int max = 0;
  int blank = 0;
  int i,j;

  while(scanf("%d,%d,%d",&x,&y,&size) != EOF){
    coordinates[x][y]++;
    if(x>0) coordinates[x-1][y]++;
    if(x<9) coordinates[x+1][y]++;
    if(y>0) coordinates[x][y-1]++;
    if(y<9) coordinates[x][y+1]++;
    if(size == 1) continue;

    if(x > 0){
      if(y>0) coordinates[x-1][y-1]++;
      if(y<9) coordinates[x-1][y+1]++;
    }
    if(x < 9){
      if(y>0) coordinates[x+1][y-1]++;
      if(y<9) coordinates[x+1][y+1]++;
    }
    if(size == 2) continue;
    
    if(x > 1) coordinates[x-2][y]++;
    if(x < 8) coordinates[x+2][y]++;
    if(y > 1) coordinates[x][y-2]++;
    if(y < 8) coordinates[x][y+2]++;
  }

  for(i=0;i<10;i++){
    for(j=0;j<10;j++){
      if(coordinates[i][j] == 0)
	blank++;
      else if(coordinates[i][j] > max)
	max = coordinates[i][j];
    }
  }

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

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e5+5,LG=19,SM=600+5,inf=1e18+1;
ll mod=1e9+7;

ll n,a,b,c,m;
vll g[M];
ll mark[M];
bool ba2;

void dfs(ll x)
{
    for (ll y:g[x])
    {
        if (mark[y])
        {
            ba2|=(mark[x]==mark[y]);
            continue;
        }
        mark[y]=(mark[x]==1?2:1);
        dfs(y);
    }
}

int main()
{
	ios::sync_with_stdio(0);
    cin >> n >> m;
    For(i,0,m)
    {
        ll u,v;
        cin >> u >> v;
        u--;v--;
        g[u].PB(v);g[v].PB(u);
    }
    a=n;
    For(i,0,n)
    {
        if (SZ(g[i])==0)
        {
            a--;
            continue;
        }
        if (mark[i]) continue;
        ba2=0;
        mark[i]=1;
        dfs(i);
        b++;
        c+=1-ba2;
    }
    //ER(a);ER(b);ER(c);
    ll res=n*n;
    res-=a*a;
    res+=b*b;
    res+=c*c;
    RET(res);    
}    

Measured memory_bytes: 13824
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SC second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


int main()
{
  string s ;
  cin >> s ;
  int cnt0 = 0 ;
  int cnt1 = 0 ;
  int n = SZ(s) ;
  REP(i,n){
    if(s.at(i)=='0'){
      cnt0++ ;
    }
    else{
      cnt1++ ;
    }
  }
  
 cout << min(cnt0,cnt1)*2 <<endl ; 


  return 0 ;
}

Measured memory_bytes: 512
import sys
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            cnt += 1
        A[j + g] = v
def solve():
    n = int(input())
    A = list(map(int, sys.stdin))
    G = [int((2.25**i - 1) / 1.25)for i in range(17, 0, -1)]
    G = [v for v in G if v <= n]
    for g in G:
        insertionSort(A, n, g)
    print(len(G))
    print(*G)
    print(cnt)
    print('\n'.join(map(str, A)))
if __name__ == '__main__':
    cnt = 0
    solve()


Measured memory_bytes: 126044
def main():
    K, A, B = map(int, input().split())
    if A+2 >= B:
        print(K+1)
        return
    ans = A + (B-A)*((K-(A-1))//2) + (K-(A-1))%2
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>

#define ll long long

using namespace std;

int main(){

    int vn = 1;

    vector<int> v(vn,0);

    for(int i = 0; i < vn; i++){
        int tmp;
        cin >> tmp;

        v[i] = tmp;
    }

    int ans = (v[0] - 2) * 180;
    cout << ans << endl;
    
 
    return 0;
}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
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; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  ll n;cin>>n;
  reps(i,-1000,1001){
    ll a=i;rep(_,4)a*=i;
    reps(j,-1000,1001){
      ll b=j;rep(_,4)b*=j;
      if(a-b==n){
        cout<<i<<" "<<j;return 0;
      }
    }
  }
}

Measured memory_bytes: 3636
N = int(input())
W = list(map(int, input().split()))

ans = 100000

for i in range(0, N):
    s1 = s2 = 0
    for j in range(0, i):
        s1 += W[j]
    for j in range(i, N):
        s2 += W[j]
    ans = min(ans, abs(s1 - s2))

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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; }

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

const ll INF = 1LL << 60;

int main(){
  int n,a,b,c,d; cin >> n;
  a = n/1000; b = (n/100)%10; c = (n/10)%10; d = n%10;
  int v[4] = {a,b,c,d};

  for (int bit = 0; bit < (1<<3); bit++) {
    int sum = v[0];
    string ans = to_string(v[0]);
    for (int i = 0; i < 3; i++) {
      if(bit & (1<<i)){
        sum += v[i+1];
        ans += '+' + to_string(v[i+1]);
      }
      else{
        sum -= v[i+1];
        ans += '-' + to_string(v[i+1]);
      }
    }
    //std::cout << sum << '\n';
    if(sum == 7){
      std::cout << (ans + "=7") << '\n';
      return 0;
    }
  }
}


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


typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/


vector<vector<int>> G;
vector<int> score;
vector<bool> seen;

void dfs(int v,int point){
  if(!seen[v]){
    seen[v] = true;
    score[v] += point;

    for(int next_v:G[v]){
      dfs(next_v,score[v]);
    }
  }
}

int main(){
  //cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N,Q;
  cin >> N >> Q;
  
  G.resize(N);
  score.assign(N,0);
  seen.assign(N,false);
  
  rep(i,N-1){
    int a,b;
    cin >> a >> b;
    --a;--b;
    G[a].PB(b);
    G[b].PB(a);
  }
  
  rep(i,Q){
    int x,q;
    cin >> x >> q;
    --x;
    score[x] += q;
  }

  dfs(0,0);
  
  rep(i,N) cout << score[i] << ' ';
  cout << endl;
    
}

Measured memory_bytes: 20352
#include<iostream>
using namespace std;
int main(void)
{
  int a,b,c;
  cin>>a;
  cin>>b;
  cin>>c;
  if(a>b)
    {
      int tmp=a;
      a=b;
      b=tmp;
    }
if(b>c)
    {
      int tmp=b;
      b=c;
      c=tmp;
    }
if(a>b)
    {
      int tmp=a;
      a=b;
      b=tmp;
    }
 cout<<a<<" "<<b<<" "<<c<<endl;
 return 0;
}

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

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> table(H,vector<char>(W));
  vector<bool> row(H,false);
  vector<bool> col(W,false);
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
      cin>>table.at(i).at(j);
      if (table.at(i).at(j)=='#'){
        row.at(i)=true;
        col.at(j)=true;
      }
    }
  }
  for(int i=0;i<H;i++){
    if (row.at(i)){
      for (int j=0;j<W;j++){
        if (col.at(j)){
          cout<<table.at(i).at(j);
        }
        if (j==W-1){
          cout<<endl;
        }
      }
    }
  }
}

Measured memory_bytes: 256
from collections import deque
S = input()
S = deque(S)

Q = int(input())
flipped = False
for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        flipped = not flipped
    elif (q[1] == '1') == flipped:
        S.append(q[2])
    else:
        S.appendleft(q[2])

print(''.join(reversed(S)) if flipped else ''.join(S))

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

template <typename T>
class SegmentTree {
	using func_t = function<T(T, T)>;
	const int n;
	const T id;
	func_t merge;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
	T sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return data[node];
		return merge(sub(l, r, node * 2, lb, (lb + ub) / 2), sub(l, r, node * 2 + 1, (lb + ub) / 2, ub));
	}
public:
	SegmentTree(int n_, T id_, func_t merge_) :
		n(size(n_)), id(id_), merge(merge_), data(size(n_) * 2, id_) {}
	SegmentTree(vector<T> data_, T id_, func_t merge_) :
		n(size(data_.size())), id(id_), merge(merge_), data(size(data_.size()) * 2, id_) {
		for (int i = 0; i < data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = merge(data[i * 2], data[i * 2 + 1]);
	}
	void Update(int p, T val) { // p???????????????val?????´??°
		assert(0 <= p && p < n);
		p += n;
		data[p] = val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	void Add(int p, T val) { // p???????????????val?¢???????
		assert(0 <= p && p < n);
		Update(p, data[p + n] + val);
	}
	T Find(int l, int r) { // ?????????[l, r]??§????????¨???????????????
		return sub(l, r + 1, 1, 0, n);
	}
};


int main()
{
	int n, q;
	int com, x, y;
	cin >> n >> q;
	SegmentTree<int> st(n, 0, [](int a, int b) { return a + b; });
	for (int i = 0; i < q; i++) {
		cin >> com >> x >> y;
		if (com)
			cout << st.Find(x - 1, y - 1) << endl;
		else
			st.Add(x - 1, y);
	}
	return 0;
}

Measured memory_bytes: 3812
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	
	static boolean[] d = new boolean[10];
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		for (int i = 0; i < k; i++) {
			d[sc.nextInt()] = true;
		}
		
		for (int i = n;; i++) {
			if (check(i)) {
				out.println(i);
				break;
			}
		}
		
		out.flush();
	}
	
	static boolean check(int n) {
		while (n > 0) {
			if (d[(n % 10)]) return false;
			n /= 10;
		}
		return true;
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 8148
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

const int N=2e5+5;

int n,m,p[N],sz[N],freq[N],ans;

bool vis[N];

int par(int x)
{
    if (p[x]==x)return p[x];
    return p[x]=par(p[x]);
}

void join(int u,int v)
{
    u=par(u);
    v=par(v);
    if (u==v)return;
    if (rand()&1)swap(u,v);
    p[v]=u;
    sz[u]+=sz[v];
    ans=max(ans,sz[u]);
}

int main()
{
    cin >> n >> m;
    for (int i=1;i<=n;i++)
    {
        p[i]=i;
        sz[i]=1;
    }
    int u,v;
    for (int i=0;i<m;i++)
    {
        cin >> u >> v;
        join(u,v);
    }
    cout << max(1,ans) << endl;
    return 0;
}


Measured memory_bytes: 5164
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

string A[16] = {"KIHBR",
               "KIHBRA",
               "KIHBAR",
               "KIHBARA",
               "AKIHBR",
               "AKIHBRA",
               "AKIHBAR",
               "AKIHBARA",
               "KIHABR",
               "KIHABRA",
               "KIHABAR",
               "KIHABARA",
               "AKIHABR",
               "AKIHABRA",
               "AKIHABAR",
               "AKIHABARA",
};


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    rep(i, 16) {
        if (S == A[i]) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;

    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001;
const int INFLL=1001001001001001001ll;
const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
const double PI=acos(-1);
const double EPS=1e-7;

signed main(){
    int N;cin>>N;
    vint R(N);rep(i,N)cin>>R[i];

    sort(all(R));
    reverse(all(R));
    double ans=0;

    for(int k=3;k<=N;k++){
        vint r(R.begin(),R.begin()+k);
        sort(all(r));
        do{
            vector<double>L(k);
            rep(i,k)L[i]=r[i]*r[(i+1)%k]/2.0;
            double mi=*min_element(all(L));
            double lb=-mi;
            double ub=mi;
            rep(i,28){
                double mid=(ub+lb)/2;
                double sum=0;
                rep(j,k)sum+=acos(mid/L[j]);
                if(sum>=2*PI)lb=mid;
                else ub=mid;
            }

            double sum=0;
            rep(j,k)sum+=acos(lb/L[j]);
            if(abs(sum-2*PI)>EPS)continue;
            double val=0;
            rep(j,k)val+=sin(acos(lb/L[j]))*L[j];
            chmax(ans,val);
        }while(next_permutation(all(r)));
    }
    printf("%.20f\n",ans);
    return 0;
}

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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2;
    REP(i,x2-x1) cout << 'R';
    REP(i,y2-y1) cout << 'U';
    REP(i,x2-x1) cout << 'L';
    REP(i,y2-y1) cout << 'D';

    cout << 'D';
    REP(i,x2-x1+1) cout << 'R'; 
    REP(i,y2-y1+1) cout << 'U';
    cout << 'L'; 
    cout << 'U'; 
    REP(i,x2-x1+1) cout << 'L';
    REP(i,y2-y1+1) cout << 'D';
    cout << 'R';
    cout << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
map<int,int> dp;
int n,cnt[N][26],state[N];
char s[N];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for (int i=1;i<=n;i++){
		for (int j=0;j<26;j++) cnt[i][j]=cnt[i-1][j];
		cnt[i][s[i]-'a']^=1;
		for (int j=0;j<26;j++) state[i]|=(cnt[i][j]<<j);
	}
	dp[0]=0;
	for (int i=1;i<=n;i++){
		int now=state[i];
		if (!dp.count(now)) dp[now]=1e9;
		int v=dp[now]+1;
		for (int j=0;j<26;j++)
			if (dp.count(now^(1<<j))) v=min(v,dp[now^(1<<j)]+1);		
		dp[now]=min(dp[now],v);
		if (i==n) printf("%d\n",v);
	}
	return 0;
}

Measured memory_bytes: 30848
n = int(input())
total = []

for i in range(1, n + 1):
    if (i % 3 == 0) and (i % 5 == 0):
        "FizzBuzz"
    elif i % 3 == 0:
        "Fizz"
    elif i % 5 == 0:
        "Buzz"
    else:
        total.append(i)

print(sum(total))

Measured memory_bytes: 29848
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cmath>

using namespace std;

using ull_t = unsigned long long;

int main()
{
    int R;
    cin >> R;
    cout << 2 * R * M_PI << endl;
}


Measured memory_bytes: 3784
/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n' 
#define F first
#define S second
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


int pwmod(int x,int n)
{
    int ans=1;
    while(n)
    {
        if(n&1)
            ans=(ans%mod * x%mod )%mod;
        n>>=1;
        x=(x%mod * x%mod)%mod;
    }
    return ans;
}

void solve()
{ 
  int n,k;
  cin >> n >> k;
  int cnt[k+1];
  int ans=0;
  fr(i,k,1)
  {
      int x=k/i;
      cnt[i]=pwmod(x,n);
     for(int j=2*i;j<=k;j+=i)
      {
          cnt[i]-=cnt[j];
          cnt[i]+=mod;
          if(cnt[i]>=mod)
            cnt[i]-=mod;
      }
      ans= (ans%mod +  (i%mod * cnt[i]%mod)%mod)%mod;
  }
  cout << ans << '\n';
  return;
}

signed main()
{
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 4392
#N=gets.to_i
#S=gets.chomp
#A=(0...N).map{gets.to_i}
#sum=A.inject(&:+)
#B=gets.split.map(&:to_i)
 

N,M,K=gets.split.map(&:to_i)

MOD=10**9+7

def pow(a,b,m)
  return 1 if b==0
  return a*pow(a,b-1,m)%m if b%2==1
  return pow(a**2%m,b/2,m)
end

def hoge(n)
  return (n*(n-1)*(n+1)/6)%MOD
end

def inv(i,m)
  return pow(i,m-2,m)
end
def fact(i)
  return 1 if i==0
  ret=1
  i.times do |a|
    ret=ret*(a+1)%MOD
  end
  return ret
end
def combination(n,m)
  return fact(n)*inv(fact(m),MOD)*inv(fact(n-m),MOD)%MOD
end

puts (N*N*hoge(M)+M*M*hoge(N))*combination(N*M-2,K-2)%MOD



Measured memory_bytes: 3836
#include<stdio.h>

int main(void)
{
	int W, H, x, y, r;
	
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if((x + r <= W) && (y + r <= H) && (x - r >= 0) && (y - r >= 0))
	{
		printf("Yes\n");
	}

	else
	{
		printf("No\n");
	}
		
	return 0;
}

Measured memory_bytes: 580
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
from itertools import accumulate
AA = [0]+list(accumulate(A))
BB = [0]+list(accumulate(B))
ans = 0
j = M
for i in range(N+1):
    if AA[i]>K:
        break
    while BB[j]>K-AA[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI p(n);
	rep(i, n) cin >>p[i];
	int ans=0;
	rep2(i,1, n-1){
		if((p[i-1] < p[i] && p[i] < p[i+1]) ||
		(p[i+1] < p[i] && p[i] < p[i-1]))  ans++;
		
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };






int main() {
	int N;
	int a[101];
	cin >> N;
	REP(i, N)cin >> a[i];
	int ans = 0;
	REP(i, N - 1) {
		int c = i;
		if (a[i + 1] == a[i]) {
			c = i;
			int cnt = 1;
			while (a[c + 1] == a[c]) {
				cnt++;
				c++;
			}
			ans += cnt / 2;
		}
		i = c;
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long LL;

int N, M;

void Solve()
{
  int tot = 1900 * M + 100 * (N - M);
  int p = 1 << M;
  int ans = tot * p;
  printf("%d\n", ans);
}

int main()
{
#ifdef linjian
freopen("in", "r", stdin);
#endif
  scanf("%d%d", &N, &M);
  Solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
typedef long long ll;
int main()
{
	ll N;
	scanf("%lld",&N);
	int flag=0;
	for(ll h=1;h<=3500;h++)
	{
		if (flag) break;
		for(ll n=1;n<=3500;n++)
		{
			if(flag) break;
			if(N-4*n>0) continue;
				ll de=4*h*n-N*(h+n);
				ll bde=N*h*n;
				if(de<=0||bde<=0) continue;
				if(de>0&&bde>0&&bde%de==0)
				{
					printf("%lld %lld %lld\n",h,n,bde/de);
					flag=1; 
				} 
				
				
		}
		
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string a,b,c;cin>>a>>b>>c;
  int a_long=a.size();
  int b_long=b.size();
  int c_long=c.size();
  char card='a';
  int i=0,j=0,k=0;
  while(i<=a_long && j<=b_long && k<=c_long){
    if(card=='a'){
      if(i==a_long){
        P('A');
        break;
      }
      card=a[i];
      i++;
    }
    if(card=='b'){
      if(j==b_long){
        P('B');
        break;
      }
      card=b[j];
      j++;
    }
    if(card=='c'){
      if(k==c_long){
        P('C');
        break;
      }
      card=c[k];
      k++;
    }
  }
  return 0;
}


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

const int N = 50005;
int n, m, q, MOD, a[N], b[N], c[N], fa[6 * N];
bool pw4[1000005];

int gcd(int a, int b) {
	return !b ? a : gcd(b, a % b);
}
int find(int x) {
	return !fa[x] ? x : fa[x] = find(fa[x]);
}
void link(int a, int b) {
	if (find(a) != find(b)) fa[find(a)] = find(b);
}
int id(int a, int b, int c) {
	return (a - 1) * 6 + b * 3 + c + 1;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m >> q >> MOD;
	int g = MOD;
	for (int i = 1; i <= m; ++i)
		cin >> a[i] >> b[i] >> c[i], g = gcd(g, abs(c[i] - c[1]));
	MOD = gcd(3 * g, MOD);
	int z = c[1] % g;
	for (int i = 1; i <= m; ++i) {
		int t = (c[i] - z) / g;
		for (int p = 0; p < 2; ++p)
			for (int q = 0; q < 3; ++q) {
				link(id(a[i], p, q), id(b[i], !p, (2 * q + t) % 3));
				link(id(b[i], p, q), id(a[i], !p, (2 * q + t) % 3));
			}
	}
	for (int i = 0, pw = z; i <= MOD; ++i, pw = 4 * pw % MOD) pw4[pw] = true;
	for (int s, t, r; q--;) {
		cin >> s >> t >> r;
		bool ans = false;
		for (int p = 0; p < 2 && !ans; ++p)
			for (int q = 0; q < 3 && !ans; ++q)
				ans = find(id(s, p, q)) == find(id(t, 0, 0)) && pw4[(r + z + (3 - q) * g << p) % MOD];
		cout << (ans ? "YES\n" : "NO\n");
	}
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll isused[500005];
vector<ll>adj[500005];
deque<ll>res;
int main() {
    fastread;
    ll t, n, i, j, k, l, m;
    cin>>n;
    while(n!=0){
        if(n%10==7){
            cout<<"Yes";
            return 0;
        }
        n/=10;
    }
    cout<<"No";
}


Measured memory_bytes: 15376
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    
    if (A <= C && C <= B) {
      System.out.println("Yes");
    } else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 26944
#include <iostream>
#include <cstdio>
#define il inline
#define ri register
#define Size 5500
#define intmax 0x7fffffff
using namespace std;
bool a[Size],b[Size];
int A[Size],B[Size],at,bt;
il void get(char&);
il int get_ans(int);
int main(){
	int n;char c;scanf("%d",&n);
	for(int i(1);i<=n;++i)get(c),a[i]=c^48;
	for(int i(1);i<=n;++i)get(c),b[i]=c^48;
	for(int i(2);i<=n;++i){
		if(a[i]!=a[i-1])A[++at]=i-1;
		if(b[i]!=b[i-1])B[++bt]=i-1;
	}A[at+1]=B[bt+1]=n;
	int ans(intmax),beg(a[A[1]]==b[B[1]]?1:0);
	int L(beg-n-(n&1)),R(beg+n+(n&1)),lmid,rmid,
		l(0),r((R-L)/2);
	while(l<r){
		lmid=l+(r-l)/3,rmid=r-(r-l)/3;
		if(get_ans(lmid*2+L)>get_ans(rmid*2+L))l=lmid+1;
		else r=rmid-1;
	}printf("%d",get_ans(L+l*2));
	return 0;
}
il int get_ans(int i){int sum(0);
	for(int j(i<=0?1:2-i),k(i<=0?i:1);j<=at||k<=bt;++j,++k){
		int u(j),v(k);
		if(u<0)u=0;if(u>at)u=at+1;
		if(v<0)v=0;if(v>bt)v=bt+1;
		sum+=abs(A[u]-B[v]);
	}return sum;
}
il void get(char &c){
	while(c=getchar(),c==' '||c=='\n'||c=='\r');
}

/*#include <iostream>
#include <cstdio>
#define il inline
#define ri register
#define Size 5500
#define intmax 0x7fffffff
using namespace std;
bool a[Size],b[Size];
int A[Size],B[Size],at,bt;
il void get(char&);
int main(){
	int n;char c;scanf("%d",&n);
	for(int i(1);i<=n;++i)get(c),a[i]=c^48;
	for(int i(1);i<=n;++i)get(c),b[i]=c^48;
	for(int i(2);i<=n;++i){
		if(a[i]!=a[i-1])A[++at]=i-1;
		if(b[i]!=b[i-1])B[++bt]=i-1;
	}A[at+1]=B[bt+1]=n;
	int ans(intmax),beg(a[A[1]]==b[B[1]]?1:0);
	for(int i(beg-n-(n&1)),j,k,sum;i<=(beg+n+(n&1));i+=2){sum=0;
		for(j=(i<=0?1:2-i),k=(i<=0?i:1);j<=at||k<=bt;++j,++k){
			int u(j),v(k);
			if(u<0)u=0;if(u>at)u=at+1;
			if(v<0)v=0;if(v>bt)v=bt+1;
			sum+=abs(A[u]-B[v]);
		}ans=min(ans,sum);
		cout<<sum<<endl;
	}printf("%d",ans);
	return 0;
}
il void get(char &c){
	while(c=getchar(),c==' '||c=='\n'||c=='\r');
}
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> h(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    vector<vector<int>> grp(n+1);
    for(int i=1;i<=m;i++)
    {
        int a,b;
        cin>>a>>b;
        grp[a].push_back(b);
        grp[b].push_back(a);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {  int flag=1;
        for(int j=0;j<grp[i].size();j++)
        {
            if(h[i]<=h[grp[i][j]])
            flag=0;
        }
        if(flag)
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8736
import java.io.*;
import java.util.*;
class Main {
	public static final int MAX = 100000;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String input[] = (br.readLine()).trim().split("\\s+");
		int ar[] = new int[n];
		for(int i = 0; i < n; i++) {
			ar[i] = Integer.parseInt(input[i]);
		}
		int dp[][] = new int[n][2];
		for(int i = n - 1; i >= 0; i--) {
			if(i == n - 1) {
				dp[i][0] = dp[i][1] = 0;
				continue;
			}
			// dp[i][0] : one step
			// dp[i][1] : two step
			if(i + 1 < n) {
				dp[i][0] = Math.min(dp[i + 1][0], dp[i + 1][1]) + (int) Math.abs(ar[i + 1] - ar[i]);
			}
			else {
				dp[i][0] = MAX;
			}
			if(i + 2 < n) {
				dp[i][1] = Math.min(dp[i + 2][0], dp[i + 2][1]) + (int) Math.abs(ar[i + 2] - ar[i]);
			}
			else {
				dp[i][1] = MAX;
			}
		}
		System.out.println(Math.min(dp[0][0], dp[0][1]));
	}
}


Measured memory_bytes: 35892
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define MOD int(1e9 + 7)

int main()
{
    long long N, K;
    cin >> N >> K;
    cout << min(N % K, abs(K - N % K)) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

constexpr long long MOD = 1000000007;

int main()
{
  long long N;
  std::cin >> N;
  long long Ga, Sa, Ba;
  std::cin >> Ga >> Sa >> Ba;
  long long Gb, Sb, Bb;
  std::cin >> Gb >> Sb >> Bb;
  std::vector<long long> dp(N + 1, 0);
  for (int i = 1; i <= N; ++i)
  {
    dp[i] = i;
    if (0 <= i - Ga)
      dp[i] = std::max(dp[i], dp[i - Ga] + Gb);
    if (0 <= i - Sa)
      dp[i] = std::max(dp[i], dp[i - Sa] + Sb);
    if (0 <= i - Ba)
      dp[i] = std::max(dp[i], dp[i - Ba] + Bb);
  }
  std::vector<long long> dp2(dp.back() + 1, 0);
  for (int i = 1; i < dp2.size(); ++i)
  {
    dp2[i] = i;
    if (0 <= i - Gb)
      dp2[i] = std::max(dp2[i], dp2[i - Gb] + Ga);
    if (0 <= i - Sb)
      dp2[i] = std::max(dp2[i], dp2[i - Sb] + Sa);
    if (0 <= i - Bb)
      dp2[i] = std::max(dp2[i], dp2[i - Bb] + Ba);
  }
  std::cout << dp2.back() << std::endl;
  return 0;
}



Measured memory_bytes: 195584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll ans = 0;
    bool g = false;
    for(int i = n-1; i > 0; i--){
        if(a[i]-a[i-1] == 1){
            if(g){
                continue;
            }else{
                g = true;
                ans += a[i];
            }
        }
        else if(a[i]-a[i-1]<1){
            if(!g){
                ans += a[i];
            }
            g = false;
        }
        else{
            cout << "-1" << endl;
            return 0;
        }
    }
    if(a[0] == 0){
        cout << ans << endl;
    }else{
        cout << "-1" << endl;
    }

    return 0;
}


Measured memory_bytes: 1152