akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9+7
L = [0 for _ in range(N)]
R = [0 for _ in range(N)]

for i in range(N):
  num = A[i]
  for j in range(i):
    if num > A[j]:
      L[i] += 1
  for k in range(i, N):
    if num > A[k]:
      R[i] += 1

answer = 0
for i in range(N):
  answer = (answer + L[i]*K*(K-1)//2%MOD + R[i]*K*(K+1)//2%MOD)%MOD
print(answer)

Measured memory_bytes: 9380
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define F first
#define S second 
#define pb(n) push_back(n)
const int N=1e5+6;
const ll M=1e9+7;
const ll INF=1e18;
int main()
{
	int n;
	scn(n);
	ll dp[n][n],a[n],pre[n];
	for(int i=0;i<n;i++)
	{
		lscn(a[i]);
		pre[i]=a[i];
		if(i)
			pre[i]+=pre[i-1];

	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i==j)
				dp[i][j]=0;
			else dp[i][j]=INF;
		}
	}

	for(int len=1;len<n;len++)
	{
		for(int i=0;i<n-len;i++)
		{
			int j=i+len;
			//merging from i...j
			ll val=INF;
			for(int k=i;k<j;k++)
			{
				ll val2=pre[j];
				if(i)
					val2-=pre[i-1];

				val=min(val,val2+dp[i][k]+dp[k+1][j]);
			}
			dp[i][j]=val;
		}
	}
	lpri(dp[0][n-1]);
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

int main() {
  int x1, y1;
  cin >> x1 >> y1;
  int x2, y2;
  cin >> x2 >> y2;

  int x3, y3, x4, y4;
  x3 = x2 - (y2 - y1);
  y3 = y2 - (x1 - x2);
  x4 = x1 - (y2 - y1);
  y4 = y1 - (x1 - x2);

  cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
}

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

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef long long ll;


int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    int t,f;
    char c;
    int flag=0;
    string head,rear;
    for(int i=0;i<q;i++){
        cin >> t;
        if(t==1){
            flag=(flag+1)%2;
        }else{
            cin >> f >> c;
            if(flag==0){
                if(f==1){
                    head+=c;
                }else{
                    rear+=c;
                }
            }else{
                if(f==1){
                    rear+=c;
                }else{
                    head+=c;
                }
            }
        }
    }
    reverse(head.begin(),head.end());
    string ans=head+s+rear;
    if(flag) reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4248
A,B=map(int,input().split())
S=input()

ans='Yes'
if S[A]!='-':
    ans='No'

for i in range(A):
    if S[i]=='-':
        ans='No'

for j in range(A+1,A+B+1):
    if S[j]=='-':
        ans='No'

print(ans)

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

#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;

int main(){
        long long n;cin >> n;
        long long a[n+1];for(int i = 0;i<=n;i++) cin >> a[i];
        long long b[n]; rep cin >> b[i];
        long long ans = min(a[n],b[n-1]);
        b[n-1] -= ans;
        for(int i = n-1;i>0;i--){
                long long aa = min(a[i],b[i]);
                ans +=aa;a[i]-=aa;b[i] -= aa;
                long long bb = min(a[i],b[i-1]);
                ans += bb; a[i] -=bb;b[i-1] -= bb;
        }
        ans += min(a[0],b[0]);
        cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class calc {

	int ans = 1;

	void func(int n) {
		for (int i = 0; i < 3; i++) {
			ans *= n;
		}
		System.out.println(ans);
	}

}

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		calc cl = new calc();

		int n = sc.nextInt();

		cl.func(n);

	}

}


Measured memory_bytes: 26144
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int n,a,b,c; 
string s[100005];
char ans[100005];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>a>>b>>c;
	FOR(i,1,n)cin>>s[i];
	FOR(i,1,n){
		if(s[i]=="AB"){
			if(!a&&!b){
				cout<<"No";RE 0;
			}
			if(a>b||(a==b&&s[i+1]=="BC")){
				a--;b++;ans[i]='B';
			}else{
				a++;b--;ans[i]='A';
			}
		}else if(s[i]=="AC"){
			if(!a&&!c){
				cout<<"No";RE 0;
			}
			if(a>c||(a==c&&s[i+1]=="BC")){
				a--;c++;ans[i]='C';
			}else{
				a++;c--;ans[i]='A';
			}
		}else{
			if(!b&&!c){
				cout<<"No";RE 0;
			}
			if(b>c||(b==c&&s[i+1]=="AC")){
				b--;c++;ans[i]='C';
			}else{
				b++;c--;ans[i]='B';
			}
		}
	}
	cout<<"Yes\n";
	FOR(i,1,n)cout<<ans[i]<<'\n';
	RE 0;
}




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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int sum = 0;
    if (k != 0){
        sum += min(a, k);
        k -= min(a, k);
    }
    if (k != 0){
        k -= min(b, k);
    }
    if (k != 0){
        sum += min(c, k) * -1;
        k -= min(c, k);
    }

    cout << sum << '\n';

    return 0;
}


Measured memory_bytes: 3652
function main()
	lines=readlines()
	N,M,Q=map(x->parse(Int,x),split(shift!(lines)))
	S=zeros(Int,N+1,N+1)
	for i=1:M
		L,R=map(x->parse(Int,x),split(shift!(lines)))
		S[L+1,R+1]+=1
	end
	for i=2:N+1,j=2:N+1
		S[i,j]+=S[i-1,j]+S[i,j-1]-S[i-1,j-1]
	end
	for i=1:Q
		p,q=map(x->parse(Int,x),split(shift!(lines)))
		println(S[q+1,q+1]-S[q+1,p]-S[p,q+1]+S[p,p])
	end
end
main()


Measured memory_bytes: 174384
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    int f=Integer.parseInt(s.substring(0,2));
    int b=Integer.parseInt(s.substring(2));
    if(0<f&&f<13){
      if(0<b&&b<13){
        System.out.println("AMBIGUOUS");
      }else{
        System.out.println("MMYY");
      }
    }else{
      if(0<b&&b<13){
        System.out.println("YYMM");
      }else{
        System.out.println("NA");
      }
    }
  }
}


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

typedef long long ll;

const int N = 10001;

ll h, n, a[N], b[N], dp[N];

ll solve (ll x) {
	if (dp[x] != -1) {
		return dp[x];
	}
	ll ans = 104206969;
	for (int i = 1; i <= n; i++) {
		if (x-a[i] <= 0) {
			ans = min(ans, b[i]);
		} else {
			ans = min(ans, solve(x-a[i])+b[i]);
		}
	}
	dp[x] = ans;
	return ans;
}

// ll solve (ll x, int chosen) {
// 	cout << "start: " << x << ' ' << chosen << endl;
// 	if (dp[x][chosen] != -1) {
// 		cout << "---: " << dp[x][chosen] << endl;
// 		cout << "end: " << x << ' ' << chosen << endl;
// 		return dp[x][chosen];
// 	}
// 	ll ans = 104206969;
// 	for (int i = 1; i <= n; i++) {
// 		if (x-a[i] <= 0) {
// 			ans = min(ans, b[i]);
// 		} else {
// 			ans = min(ans, solve(x-a[i], i));
// 		}
// 	}
// 	dp[x][chosen] = ans+b[chosen];
// 	cout << "---: " << dp[x][chosen] << endl;
// 	cout << "end: " << x << ' ' << chosen << endl;
// 	return ans;
// }

int main () {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> h >> n;
	memset(dp, -1, sizeof dp);
	a[0] = b[0] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
	}
	
	cout << solve(h) << endl;

	cout << flush;
	return 0;
}

Measured memory_bytes: 640
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: Train Ticket
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int N = 4;
const int M = N - 1;
const int MBITS = 1 << M;
const int A = 7;

/* typedef */

/* global variables */

int ds[N];

/* subroutines */

/* main */

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

  for (int i = 0; i < N; i++) ds[i] = s[i] - '0';
  //for (int i = 0; i < N; i++) printf("%d", ds[i]); putchar('\n');

  for (int bits = 0; bits < MBITS; bits++) {
    int sum = ds[0];
    for (int i = 0, bi = 1; i < M; i++, bi <<= 1) {
      if (bits & bi) sum -= ds[i + 1];
      else sum += ds[i + 1];
    }
    if (sum == A) {
      printf("%d", ds[0]);
      for (int i = 0, bi = 1; i < M; i++, bi <<= 1)
	printf("%c%d", (bits & bi) ? '-' : '+', ds[i + 1]);
      printf("=%d\n", A);
      break;
    }
  }
  return 0;
}


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

int main () 
{
    long long x;
    cin >> x;
    long long hp = 0;
    
    
    //500:
    hp += (x / 500) * 1000;
    x = x % 500;

    //5:
    hp += (x / 5) * 5;
    
    cout << hp << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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 TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

// #include <atcoder/all>

int main() {
    int K;
    cin >> K;
    rep(i,K){
        cout <<"ACL";
    }
    cout << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    vector<int>v;
    for(int i=0;i<n;i++){
        int x=a[i]-b[i];
        if(x>0){
            v.push_back(x);
        }
    }
    cout<<accumulate(v.begin(),v.end(),0)<<endl;
    return 0;
    
}



Measured memory_bytes: 256
# ABC094C - Many Medians (ARC095C)
def main():
    N, *X = map(int, open(0).read().split())
    l, h = sorted(X)[N // 2 - 1 : N // 2 + 1]
    ans = [h if i <= l else l for i in X]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Measured memory_bytes: 25052
#include <iostream>
#include <cstdlib>

using namespace std;

int main(void) {
  long a, b, x;
  cin >> a >> b >> x;

  long res = 0;
  for (long i = a; i <= b; i += x - i % x) {
    if (i % x == 0) {
      res = 1 + (b - i) / x;
      break;
    }
  }
  cout << res << endl;
  return EXIT_SUCCESS;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vb vector<bool>
#define vi vector<ll>
#define vs vector<string>
#define vvi vector<vi>
#define vii vector<pair<ll, ll>>
#define pii pair<ll, ll>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(a) (a).begin(), (a).end()
#define INF 1000*1000*1000
//#define mod (INF + 7)
#define mod1 (mod-1)
#define endl '\n'
#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

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

    string ans = "";

    if(n == 0)
    {
        cout << "0" << endl;
        return 0;
    }

    while(n)
    {
        int r = n%(-2);
        n /= -2;

        if(r < 0)
        {
            r += 2;
            n++;
        }

        ans.pb(r + '0');
    }
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    int arr[n],dp[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    dp[0]=0;
    dp[1]=fabs(arr[1]-arr[0]);
    for(i=2;i<n;i++)
    {
        if((fabs(arr[i]-arr[i-1])+dp[i-1])<(fabs(arr[i]-arr[i-2])+dp[i-2]))
            dp[i]=fabs(arr[i]-arr[i-1])+dp[i-1];
        else
            dp[i]=fabs(arr[i]-arr[i-2])+dp[i-2];
    }
    cout<<dp[n-1];
}

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

int main()
{
    string S;
    cin >> S;
    string yyyy = S.substr(0, 4);
    string mm = S.substr(5, 2);
    string dd = S.substr(8, 2);

    int y = stoi(yyyy);
    int m = stoi(mm);
    int d = stoi(dd);

    if( y <= 2019 and m <= 4 and d<=30){
        cout << "Heisei" << endl;
    }
    else{
        cout << "TBD" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}

const int maxn = 2000 + 5;
const ll mod = 1e9 + 7;

ll dp[maxn];
ll solve(int sum){
	if(sum == 0)
		return 1ll;

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

	ll ans = 0;
	for(int x = 3; x <= sum; x++)
		ans = (ans + solve(sum - x)) % mod;

	return dp[sum] = ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	// freopen("settling.in", "r", stdin);
	// freopen("settling.out", "w", stdout);

	int s;
	cin >> s;
	memset(dp, -1, sizeof(dp));

	cout << solve(s) << endl;
	
	return 0;
}


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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)
#define fi first
#define se second

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

string s[2];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i, 2) cin >> s[i];
    if(s[0][0] == s[1][2] && s[0][1] == s[1][1] && s[0][2] == s[1][0] && s[1][0] == s[0][2] && s[1][1] == s[0][1] && s[1][2] == s[0][0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main(void)
{
  long N, K;
  cin >> N >> K;
  long i;
  long array[100001] = {};
  for (i = 0; i < N; i++)
  {
    long a, b;
    cin >> a >> b;
    array[a] += b;
  }
  for (i = 0; i < 100001; i++)
  {
    K -= array[i];
    if (K <= 0)
    {
      cout << i << endl;
      return 0;
    }
  }
}


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

using namespace std;

#define ll long long

ll N, M;
vector<vector<pair<ll, ll> > > G;

ll edo(ll zac, ll kon){
	ll F = 0;
	while(true){
		queue<ll> Q;
		vector<ll> vzd(N, -1), pred(N, -1), tok(N);
		Q.push(zac);
		vzd[zac] = 0;
		tok[zac] = LONG_LONG_MAX;
		while(Q.size() != 0){
			ll v = Q.front();
			Q.pop();
			for(ll w = 0; w < N; w++){
				ll f1 = G[v][w].first, f2 = G[w][v].first, c = G[v][w].second, r = c - f1 + f2;
				if(r > 0 && vzd[w] == -1){
					vzd[w] = vzd[v]++;
					pred[w] = v;
					tok[w] = min(tok[v], r);
					Q.push(w);
				}
			}
		}
		if(vzd[kon] == -1) break;
		F += tok[kon];
		ll v = kon;
		while(v != zac){
			ll w = pred[v], f1 = G[w][v].first, f2 = G[v][w].first, c = G[w][v].second, o = min(f2, tok[kon]);
			G[v][w].first -= o;
			G[w][v].first += tok[kon] - o;
			v = w;
		}
	}
	return F;
}


int main(){
	ios::sync_with_stdio(false);
	cin >> N >> M;
	G.resize(N, vector<pair<ll, ll> >(N, {0, 0}));
	for(ll m = 0; m < M; m++){
		ll A, B, C;
		cin >> A >> B >> C;
		G[A][B].second = C;
	}
	cout << edo(0, N-1) << endl;
	return 0;
}

Measured memory_bytes: 3308
s = input()
print('Second' if (s[0] == s[-1]) == (len(s) % 2) else 'First')

# 最後の操作後の形
# 頭と尾が同じ->奇数
# 違う->偶数

# sの文字数と最後の操作後の形の偶奇
# 一致->先手負け
# 不一致->後手負け


Measured memory_bytes: 3316
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, M: int, A: "List[int]"):
    ans = N-sum(A)
    if ans<0:
        print(-1)
    else:
        print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27816
#include <stdio.h>

int main(void)
{
	int sum, kei;
	int i, cost;
	
	while (scanf("%d", &kei)){
		if (kei == 0){
			break;
		}
	
		sum  = 0;
		for (i = 0; i < 9; i++){
			scanf("%d", &cost);
			sum += cost;
		}
	
		printf("%d\n", kei - sum);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, M; cin >> N >> M;
  vector<ll> A(N), B(N), C(M+1), D(M+1);
  for (ll i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  for (ll i = 1; i <= M; i++) {
    cin >> C[i] >> D[i];
  }
  for (ll i = 0; i < N; i++) {
    ll jmin = -1;
    ll dmin = 1e10;
    for (ll j = 1; j <= M; j++) {
      ll d = abs(A[i] - C[j]) + abs(B[i] - D[j]);
      if (d < dmin) {
	jmin = j;
	dmin = d;
      }
    }
    cout << jmin << "\n";
  }


  return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define at(x,y) (x)*30+y
using namespace std;

int main(){
	int w,h;
	while(cin >> w >> h,w||h){
		vector<vector<int>> v(w*31);
		for(int i=0;i<2*h-1;i++){
			for(int j=0;j<w-((i+1)%2);j++){
				int c;
				cin >> c;
				if(c) continue;
				if(i%2){//???
					v[at(j,i/2)].emplace_back(at(j,i/2+1));
					v[at(j,i/2+1)].emplace_back(at(j,i/2));
				} else{//?¨?
					v[at(j,i/2)].emplace_back(at(j+1,i/2));
					v[at(j+1,i/2)].emplace_back(at(j,i/2));
				}
			}
		}
		priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
		pq.push(make_pair(1,at(0,0)));
		bool passed[31*30];
		for(int i=0;i<31*30;i++) passed[i]=false;
		int ans = 0;
		while(!pq.empty()){
			pair<int,int> x = pq.top();
			pq.pop();
			if(x.second == at(w-1,h-1)){
				ans = x.first;
				break;
			}
			
			if(passed[x.second]) continue;
			passed[x.second] = true;
			for(int unsigned i = 0;i<v[x.second].size();i++){
				pq.push(make_pair(x.first+1,v[x.second][i]));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    ll n, m; cin >> n >> m;
    vector<pair<ll,ll>> a(n);
    rep(i, n){
        ll b, c; cin >> b >> c;
        a.emplace_back(b, c);
    }
    sort(a.begin(), a.end());
    ll count = 0;
    ll nedan = 0;
    ll kosuu;
    ll i = 0;

    while(count < m){
        kosuu = min(m - count, a[i].second);
        count += kosuu;
        nedan += kosuu * a[i].first;
        /*cout << kosuu << " " <<  nedan << endl;*/
        i++;
    }
    cout << nedan << endl;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#include <map>
 #define rep(i,n) for(int i=0;i<n;i++)
 using namespace std;
  int main(){
      int d,t,s;
      cin >> d >> t >> s;
      if(d>t*s){
          cout << "No" << endl;
      }
      else{
          cout << "Yes" << endl;
      }
      return 0;
  }

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
using Graph = vector<vector<pair<int, int>>>;
template <class T>
using priority_queue_min = priority_queue<T, vector<T>, greater<T>>;
Graph minimum_spanning_tree(const Graph &g) {
    Graph ans(g.size());
    priority_queue_min<tuple<int, int, int>> Q;
    vector<bool> used(g.size());
    int cnt = 0;
    used[0] = true;
    cnt++;
    for (auto &e : g[0]) {
        Q.emplace(e.second, 0, e.first);
    }
    while (cnt < g.size()) {
        int cost, src, dst;
        tie(cost, src, dst) = Q.top();
        Q.pop();
        if (!used[dst]) {
            used[dst] = true;
            cnt++;
            ans[src].emplace_back(dst, cost);
            ans[dst].emplace_back(src, cost);
            for (auto &e : g[dst]) {
                if (!used[e.first]) Q.emplace(e.second, dst, e.first);
            }
        }
    }
    return ans;
}
Int sum_edge(const Graph &g) {
    Int ans = 0;
    for (auto &es : g) for (auto &e : es) ans += e.second;
    return ans / 2;
}
vector<vector<int>> max_edge(const Graph &g) {
    vector<vector<int>> ans(g.size(), vector<int>(g.size()));
    stack<pair<int, int>> S;
    for (int i = 0; i < g.size(); i++) {
        S.emplace(i, -1);
        while (!S.empty()) {
            int curr, prev;
            tie(curr, prev) = S.top();
            S.pop();
            for (auto &e : g[curr]) if (prev != e.first) {
                S.emplace(e.first, curr);
                ans[i][e.first] = max(ans[i][curr], e.second);
            }
        }
    }
    return ans;
}
int main() {
    int N, M; cin >> N >> M;
    Graph G(N);
    for (int i = 0; i < M; i++) {
        int a, b, c; cin >> a >> b >> c; a--, b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }
    G = minimum_spanning_tree(G);
    auto sum = sum_edge(G);
    auto maxE = max_edge(G);
    int Q; cin >> Q;
    for (int i = 0; i < Q; i++) {
        int s, t; cin >> s >> t; s--, t--;
        cout << sum - maxE[s][t] << '\n';
    }
    return 0;
}


Measured memory_bytes: 66712
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int x[101],y[101],h[101];
	cin>>n;
	int bx,by,bh;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i]>>h[i];	
		if(h[i]>0){
			bx=x[i];
			by=y[i];
			bh=h[i];
		}
	}
	int he;
	bool flg;
	for(int i=0;i<101;i++){
		for(int j=0;j<101;j++){
			int H=abs(i-by)+abs(j-bx)+bh;
			H=max(H,0);
			flg=false;
			for(int k=0;k<n;k++){
				he=H-abs(i-y[k])-abs(j-x[k]);
				he=max(he,0);
				if(he!=h[k])	flg=true;
			}
			if(!flg){
				cout<<j<<" "<<i<<" "<<H;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main()
{
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);
  char s[n + 1];
  scanf("%s",&s);
  int i = 0;
  int countera = 0;
  int counterb = 0;
  while (s[i])
  {
    if (s[i] == 'c')
    {
      printf("No\n");
    }
    else if (s[i] == 'a')
    {
      if (countera < a + b)
      {
      	printf("Yes\n");
      	countera++;
      }
      else
      {
        printf("No\n");
      }
    }
    else if (s[i] == 'b')
    {
      if (countera < a+b && counterb < b)
      {
      	printf("Yes\n");
      	counterb++;
      	countera++;
      }
      else
      {
        printf("No\n");
      }
    }
    else
    {
      printf("No\n");
    }
    i++;
  }
}

Measured memory_bytes: 640
n=int(input())
l=list(map(int,input().split()))
c=0
for i in range(n-1):
  if l[i]==i+1:
    c+=1
    l[i],l[i+1]=l[i+1],l[i]
if l[n-1]==n:
  c+=1
print(c)

Measured memory_bytes: 14008
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int answer = 1;
        for (int i = 0; i < 3; i++) {
            answer *= N;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
int main(void)
{
	int a;
	int b;
	int x;
	for (a=1;a<10;a++)
	{
		for (b=1;b<10;b++)
		{
			x=a*b;
			printf("%dx%d=%d\n", a, b, x);
		}
	}
	return 0;
}

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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;

  if( A % 3 == 0 || B % 3 == 0 || ( A + B ) % 3 == 0 )
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
  return 0;
}

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

#define ull unsigned long long int
#define ll long long int
#define pb(x) push_back(x)
#define MOD (ull)(double)(1e9 + 7)

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin  >> n;
	
	string s;
	cin >> s;
	
	map<char, vector<int>> mp;
	
	for(int i=0;i<s.size();i++){
		mp[s[i]].pb(i);
	}
	
	int cnt=0;
	for(int i=0;i<1000;i++){
	    int flag[n] = { 0 };
		vector<int> v;
		int x=i;
		while(x != 0){
			v.pb(x%10);
			x = x / 10;
		}
		
		for(int j=v.size();j<3;j++){
			v.pb(0);
		}
		
		int a=v[2],b=v[1],c=v[0];
		
		if(mp[char(a+48)].size()){
			flag[mp[char(a+48)][0]] = 1;
			
			if(mp[char(b+48)].size()){
				int sr=-1;
				for(auto it : mp[char(b+48)]){
					if(!flag[it] && it > mp[char(a+48)][0]){
						sr = it;
						flag[it] = 1;
						break;
					}
				}
				
				if(sr != -1){
					if(mp[char(c+48)].size()){
						int sr2=-1;
						for(auto it : mp[char(c+48)]){
							if(!flag[it] && it > sr){
								sr2 = it;
								flag[it] = 1;
								break;
							}
						}
						
						if(sr2 != -1){
						    //cout << a << b << c << endl;
						    cnt++;
						}
					}
				}
			}
		}
	}
	
	cout << cnt;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef struct node
{
	char name[101];
	int time;
}NODE,*PNODE;
NODE a[50];
char s[101];
int main()
{
	int n,i;
	long long cnt=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",a[i].name);
		scanf("%d",&a[i].time);
	}
	scanf("%s",s);
	int fla=0;
	for(i=0;i<n;i++)
	{
		if(strcmp(a[i].name,s)==0)
		{
			fla=1;
			continue;
		}
		if(fla)
			cnt+=a[i].time;	
	}
	printf("%d",cnt);
	return 0;
}


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

typedef long long ll;

int main() {
    int N, ans = 1e9;
    cin >> N;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, 1 << N) {
        //cout << i << endl;
        vector<vector<int>> e(0, vector<int>(2)), o(0, vector<int>(2));
        rep(j, N) {
            if ((i >> j) & 1) {
                if (j % 2) e.push_back({B[j], j});
                else o.push_back({B[j], j});
            } else {
                if (j % 2) o.push_back({A[j], j});
                else e.push_back({A[j], j});
            }
        }
        /*
        rep(j, e.size()) cout << e[j][0] << " " << e[j][1] << endl;
        cout << endl;
        rep(j, o.size()) cout << o[j][0] << " " << o[j][1] << endl;
        cout << endl;
        */
        if (o.size() != N / 2) continue;
        sort(e.begin(), e.end());
        sort(o.begin(), o.end());
        bool f = 0;
        rep(j, N - 1) {
            if (j % 2 == 0 && e[j / 2][0] > o[j / 2][0]) f = true;
            if (j % 2 == 1 && o[j / 2][0] > e[j / 2 + 1][0]) f = true;
        }
        if (f) continue;
        /*
        rep(j, N) {
            if (j % 2 == 0) cout << e[j/2][0] << " " << e[j/2][1] << endl;
            else cout << o[j/2][0] << " " << o[j/2][1] << endl;
        }
        */
        vector<int> v(N);
        rep(j, N) {
            if (j % 2 == 0) v[j] = e[j / 2][1];
            else v[j] = o[j / 2][1];
        }
        int t = 0;
        rep(j, N - 1) {
            for (int k = j + 1; k < N; k++) {
                if (v[j] > v[k]) t++;
            }
        }
        ans = min(ans, t);
    }
    if (ans == 1e9) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL r;
    LL c;
    LL k;
    cin >> r >> c >> k;
    vector<vector<LL>> v(r, vector<LL>(c, 0));
    LL tmp_r;
    LL tmp_c;
    LL tmp_v;
    for(LL i=0; i<k; i++){
        cin >> tmp_r >> tmp_c >> tmp_v;
        tmp_r--;
        tmp_c--;
        v[tmp_r][tmp_c]=tmp_v;
    }
    vector<vector<vector<LL>>> dp(r, vector<vector<LL>>(c,vector<LL>(4,0)));
    for(LL i=0; i<r; i++){
        for(LL j=0; j<c; j++){
            for(LL k=0; k<4; k++){
                if(i==0 && j==0){
                    dp[i][j][1]=max(dp[i][j][1],dp[i][j][0]+v[i][j]);
                }
                if(i!=0){
                    dp[i][j][0]=max(dp[i][j][0], dp[i-1][j][k]);
                    if(v[i][j]!=0){
                        dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][k]+v[i][j]);
                    }
                }
                if(j!=0){
                    dp[i][j][k]=max(dp[i][j][k], dp[i][j-1][k]);
                    if(v[i][j]!=0 && k>=1){
                        dp[i][j][k]=max(dp[i][j][k], dp[i][j-1][k-1]+v[i][j]);
                    }
                }
            }
        }
    }

    LL max_ans=0;
    for(LL i=0; i<4; i++){
        max_ans=max(max_ans, dp[r-1][c-1][i]);
    }

    cout << max_ans << endl;

    return 0;
}


Measured memory_bytes: 706724
#include <stdio.h>
// left -> 1, right -> 0
int is_left(char c, char left[]){
  int i;
  for(i=0;left[i]!=0;i++){
    if(c==left[i])return 1;
  }
  return 0;
}

int main(void){
  char s[100];
  char left[] = "qwertasdfgzxcvb";
  int i,ans;
  int current_hand,next_hand;
  while(1){
    scanf("%s", s);
    if(s[0]=='#')break;
    current_hand = -1;
    ans=0;
    for(i=0;s[i]!=0;i++){
      next_hand = is_left(s[i], left);
      if(current_hand==-1){
	current_hand=next_hand;
	continue;
      } 
      if(current_hand != next_hand){
	current_hand=next_hand;
	ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 540
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    ll N, K;
    cin >> N >> K;

    ll ans = N;
    if (N <= K) {
        ans = min(ans, abs(N-K));
        cout << ans << endl;
        return 0;
    } else {
        
        ans = N % K;
        ans = min(ans, abs(ans-K));
        cout << ans << endl;
        return 0;
    }

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#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 IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sx,sy,gx,gy ;
    cin >> sx >> sy >> gx >> gy ;
    REP(i,gx-sx){
        cout <<"R" ;
    }
    REP(i,gy-sy){
        cout <<"U" ;
    }
    REP(i,gx-sx){
        cout <<"L" ;
    }
    REP(i,gy-sy+1){
        cout <<"D" ;
    }
    REP(i,gx-sx+1){
        cout <<"R" ;
    }
    REP(i,gy-sy+1){
        cout <<"U" ;
    }
    cout <<"LU" ;
    REP(i,gx-sx+1){
        cout <<"L" ;
    }
    REP(i,gy-sy+1){
        cout <<"D" ;
    }
    cout << "R" <<endl ;

    return 0;
}


Measured memory_bytes: 3676
// Problem : A - Registration
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define ll long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<ll,ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=b;i>=a;i--)
#define maxn 1005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
using namespace std;
void solve()
{
	string s,t;
	cin >> s >> t;
	if(s.size()>=t.size()  || t.size()>s.size()+1)
	{
		cout << "No";
		return;
	}
	rep(i,0,s.size())
	{
		if(s[i]!=t[i])
		{
			cout << "No";
			return;
		}
	}
	cout<< "Yes";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int,int> P;

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

int H,W;
char maze[20][20];


int bfs(int sx,int sy){
    int ans[20][20];
    for(int i=0;i<20;i++){
        for(int j=0;j<20;j++){
            ans[i][j]=INF;
        }
    }
    ans[sx][sy]=0;

    queue<P> pos;
    pos.push(P(sx,sy));

    while(pos.size()){
        P p=pos.front();
        pos.pop();
        
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];

            if(0<=nx && nx<H && 0<=ny && ny<W &&
                maze[nx][ny]=='.' && ans[nx][ny]==INF){
                pos.push(P(nx,ny));
                ans[nx][ny]=ans[p.first][p.second]+1;
            }     
        }
    }

    int max=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(ans[i][j]!=INF && ans[i][j]>max){
                max=ans[i][j];
            }
        }
    }
    
    return max;
}

int main(){
    cin>>H>>W;

    int max=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>maze[i][j];
        }
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(maze[i][j]=='.'){
                int res=bfs(i,j);
                if(res>max){
                    max=res;
                }
            }
        }
    }
 
    cout<<max;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
s = [list(map(lambda s: int(s) - 1, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))

ret = 0
for i in range(2 ** N):
    on = list(map(int, bin(i)[2:]))
    on = ([0] * N + on)[-N:]
    for si, pi in zip(s, p):
        if sum(on[sij] for sij in si) % 2 != pi:
            break
    else:
        ret += 1
print(ret)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (b==0) return a;
    else{
    	return gcd(b,a%b);
    }
}
 
int main() {
	ll a,b;
  	cin >> a >> b;
 	if(a+b>=10){
      cout << "error" << endl;
    }
  	else{
      cout << a+b << endl;
    }
  	
  	
}


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

typedef unsigned long long  ULL;
typedef long long LL;

#define pb push_back
#define mp make_pair
#define reset(a, b) memset(a, b, sizeof(a))
#define rep(i,b) for(int i=0; i<b; i++)
#define F first 
#define S second

 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
//    cin>>T;
    T=1;
    while(T--){
       
       string s;
       cin>>s;
       bool flag=false;
        rep(i,3){
            if(s[i]=='7') flag=true;
        }
       if(flag) cout<<"Yes";
       else cout<<"No";
       
       
    }
    
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{	
	char p[110], s[110];
	cin >> s >> p;

	int len_s = strlen(s);
	int len_p = strlen(p);

	for (int i = 0; i < len_s; i++)
	{
		if (s[i] == p[0])
		{
			for (int j = 0; j < len_p; j++)
			{
				if (j == len_p - 1 && s[(i + j) % len_s] == p[j])
				{
					cout << "Yes" << endl;
					return 0;
				}
				if (s[(i + j) % len_s] != p[j]) break;
			}
		}
	}

	cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 3104
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
string s,t,fail;
int main(){
	fail="UNRESTORABLE";
	cin>>s>>t;
	for(int i=s.size()-t.size();i>=0;i--)
	{
		bool ok=true;
		for(int j=i;j<=i+t.size()-1;j++)
		{
			if(s[j]=='?')
				continue;
			ok&=(s[j]==t[j-i]);
		}
		if(ok)
		{
			for(int j=i;j<=i+t.size()-1;j++)
				s[j]=t[j-i];
			for(int j=0;j<s.size();j++)
				if(s[j]=='?')
					s[j]='a';
			cout<<s;
			return 0;
		}
	}
	cout<<fail;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include<math.h>
using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> costs(N);
    vector<int> dp(N);
    vector<int> buf(K);
    for(auto &i : costs) cin >> i;

    dp[0] = 0;
    dp[1] = abs(costs[1] - costs[0]);
    if(N > 1){
    for(int i = 2;i < N;i++){
        buf.clear();
        if(i >= K){
            for(int j = 1;j <= K;j++){
                buf.push_back(dp[i - j] + abs(costs[i] - costs[i - j]));
            }
        }else{
            for (int j = 1; j <= i; j++)
            {
                buf.push_back(dp[i - j] + abs(costs[i] - costs[i - j]));
            }
        }
        dp[i] = *min_element(buf.begin(),buf.end());
        }
    }
    cout << endl << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn solve(n:i32, m:i32, a:Vec<i32>) -> i64 {
    let mut map = HashMap::<i32,i32>::new();
    map.reserve((n+1) as usize);

    let mut ans:i64 = 0;

    let mut acc:i32 = 0;
    map.insert(acc, 1);
    for i in 0..n {
        acc = (acc + a[i as usize]) % m;

        let count = map.entry(acc).or_insert(0);
        ans += *count as i64;
        *count += 1;
    }

    ans
}

fn main() {
    let nm = read_vec::<i32>();
    let a = read_vec::<i32>();
    println!("{}", solve(nm[0], nm[1], a));
}


Measured memory_bytes: 8444
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 200005;
typedef long long i64;

class Segment {
public:
  i64 mn[MAX_N << 2], tag[MAX_N << 2];
  Segment() {
    memset(mn, 0x3f, sizeof mn);
    memset(tag, 0, sizeof tag);
  }
  void add(int x, i64 val) {
    tag[x] += val, mn[x] += val;
  }
  void push_down(int x) {
    if (tag[x]) {
      add(x << 1, tag[x]);
      add(x << 1 | 1, tag[x]);
      tag[x] = 0;
    }
  }
  i64 query(int x, int l, int r, int L, int R) {
    if (l <= L && R <= r)
      return mn[x];
    push_down(x);
    int mid = (L + R) >> 1;
    if (mid < l) return query(x << 1 | 1, l, r, mid + 1, R);
    else if (mid >= r) return query(x << 1, l, r, L, mid);
    else return min(query(x << 1 | 1, l, r, mid + 1, R),
		    query(x << 1, l, r, L, mid));
  }
  void modify(int x, int l, int r, int L, int R, i64 val) {
    if (l <= L && R <= r) 
      return add(x, val);
    push_down(x);
    int mid = (L + R) >> 1;
    if (mid >= l) modify(x << 1, l, r, L, mid, val);
    if (mid < r) modify(x << 1 | 1, l, r, mid + 1, R, val);
    mn[x] = min(mn[x << 1], mn[x << 1 | 1]);
  }
  void assign(int x, int pos, int L, int R, i64 val) {
    if (L == R) {
      mn[x] = val;
      return;
    }
    push_down(x);
    int mid = (L + R) >> 1;
    if (mid >= pos) assign(x << 1, pos, L, mid, val);
    else assign(x << 1 | 1, pos, mid + 1, R, val);
    mn[x] = min(mn[x << 1], mn[x << 1 | 1]);
  }
} tr, tr1, tr2;

int X[MAX_N];

int main() {
  int N, Q, A, B;
  scanf("%d%d%d%d", &N, &Q, &A, &B);
  for (int i = 1; i <= Q; ++i) scanf("%d", &X[i]);
  X[0] = B;
  tr.assign(1, A, 1, N, 0);
  tr1.assign(1, A, 1, N, -A);
  tr2.assign(1, A, 1, N, A);

  for (int i = 1; i <= Q; ++i) {
    int d = abs(X[i] - X[i - 1]);

    i64 x = min(tr1.query(1, 1, X[i], 1, N) + X[i], tr2.query(1, X[i], N, 1, N) - X[i]);
    
    tr.modify(1, 1, N, 1, N, d);
    tr1.modify(1, 1, N, 1, N, d);
    tr2.modify(1, 1, N, 1, N, d);
    
    tr.assign(1, X[i - 1], 1, N,  x);
    tr1.assign(1, X[i - 1], 1, N, x - X[i - 1]);
    tr2.assign(1, X[i - 1], 1, N, x + X[i - 1]);
  }

  printf("%lld\n", tr.mn[1]);
  
  return 0;
}


Measured memory_bytes: 38400
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]
blue.sort(key=lambda x:x[0])
ans = 0
for i in range(N):
  maxy=-1
  maxyidx=0
  for j in range(N):
    if blue[i][0]>red[j][0] and blue[i][1]>red[j][1] and red[j][1]>maxy:
      maxy = red[j][1]
      maxyidx = j
  if maxy>-1:
    ans += 1
    red[maxyidx][1]=-1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>
#include <fstream>
#include <ostream>
#include <random>
#include <chrono>

using namespace std;

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

	string s;
	cin >> s;

	int ans = 0;
	int curr = 0;

	for (auto i : s)
	{
		if (i == 'A' || i == 'C' || i == 'T' || i == 'G')
		{
			curr++;
		}
		else
		{
			curr = 0;
		}
		ans = max(ans, curr);
	}
	cout << ans << endl;
}


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

typedef struct Node{
  int value;
  Node *parent, *left, *right;
} Node;

Node *NIL, *root;

void insert(int k){
  Node *y = NIL, *x = root, *z;

  z = (Node *)malloc(sizeof(Node));
  z->value = k;
  z->left = z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->value < x->value) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->value < y->value) y->left = z;
  else y->right = z;
}

Node* find(Node *x, int k){
  //if find the node has k or haven't been able to find the node, return
  if(x == NIL || x->value == k) return x;

  //if k is less than x's value, search a left part of that node
  //else search a right part of that node
  if(k < x->value) return find(x->left, k);
  else return find(x->right, k);
}

void preParse(Node *node){
  if(node == NIL) return ;

  cout << " " << node->value;
  if(node->left != NIL) preParse(node->left);
  if(node->right != NIL) preParse(node->right);
}

void inParse(Node *node){
  if(node == NIL) return ;

  if(node->left != NIL) inParse(node->left);
  cout << " " << node->value;
  if(node->right != NIL) inParse(node->right);
}

int main(){

  int n, key;
  string command;

  //input
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> command;
    if(command == "insert"){
      cin >> key;
      insert(key);
    }else if(command == "print"){
      inParse(root);
      cout << endl;
      preParse(root);
      cout << endl;
    }else if(command == "find"){
      cin >> key;
      //search from root of the tree
      if(find(root, key)) cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }

  return 0;
}




Measured memory_bytes: 21888