akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
 
public class Main {
	
		
	
	public static void main(String args []) {
		InputReader obj = new InputReader(System.in);
		
		int a=obj.nextInt();
		int b=obj.nextInt();
		int c=obj.nextInt();
		System.out.println(Math.max(0, c-(a-b)));
	}
	public static class InputReader {
	    public BufferedReader reader;
	    public StringTokenizer tokenizer;
 
	    public InputReader(InputStream stream) {
	        reader = new BufferedReader(new InputStreamReader(stream), 32768);
	        tokenizer = null;
	    }
 
	    public String next() {
	        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }
 
	    public int nextInt() {
	        return Integer.parseInt(next());
	    }
 
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    
 
	}
}

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

int main() {
  int H, W, D, Q, N;
  cin >> H >> W >> D;
  N = H * W;
  vector X(N, 0), Y(N, 0), R(N, 0);
  for (int i = 0; i < H; i++) {
    for (int j = 0, a; j < W && cin >> a; j++) X.at(--a) = j, Y.at(a) = i;
  }
  for (int i = D; i < N; i++) {
    R.at(i) = R.at(i - D) + abs(X.at(i) - X.at(i - D)) + abs(Y.at(i) - Y.at(i - D));
  }
  cin >> Q;
  for (int l, r; cin >> l >> r;) cout << R.at(--r) - R.at(--l) << "\n";
}

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

int main() {
    int n,c=1;
    cin>>n;
    vector<string> t(n);
    for(int i=0;i<n;++i)
    cin>>t[i];
    sort(t.begin(),t.end());
    for(int i=1;i<n;++i){
        if(t[i]!=t[i-1])
        ++c;
    }
    cout<<c;
}

Measured memory_bytes: 9544
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,b;
  double a;
  cin >>n;
  
  a = ceil(n/1.08);
  b = floor(a*1.08);
  
  if(n==b) cout << a << endl;
  else cout << ":(" << endl;
  
  return 0;
}

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
ll m,n,k;
string s,t;
ll dp[N][105][2];
int digitdp(int index,int rem,int tight) // backup code
{
  if(index==sz(t))
  {
    if(rem==0)return 1;
    return 0;
  }
  if(dp[index][rem][tight]!=-1)return dp[index][rem][tight];
  int limit=(tight)?(t[index]-'0'):9;
  int ans=0;
  rep(d,0,limit)
  {
    int ct=0;
    if(d==(t[index]-'0'))ct=tight;
    ans=(ans+digitdp(index+1,(rem+d)%k,ct))%hell;
  }
  return dp[index][rem][tight]=ans;
}
void solve(){
    // ll k,d;
    cin>>t>>k;
    memset(dp,-1,sizeof(dp));
    ll curr=digitdp(0,0,1);
    curr=(curr-1+hell)%hell;
    cout<<curr;
    // while(k!=0){

    // }

}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

using namespace std;

int N;
int pre[105];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N;
    for(int i =1 ; i<=N; i++){
        cin >> pre[i];
    }
    for(int i = 1; i<=N; i++){
        pre[i] += pre[i-1];
    }
    int ans = pre[N];
    for(int i =0 ; i<=N; i++){
        ans = min(abs(pre[N]-pre[i]-pre[i]), ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    vector<int> v(26, -1);
    for(int i=n-1; i>=0; --i)
        v[s[i]-'a'] = n + i;
    vector<vector<int> > next(n, vector<int>(26, -1));
    for(int i=n-1; i>=0; --i){
        for(int j=0; j<26; ++j){
            if(v[j] != -1)
                next[i][j] = v[j] - i;
        }
        v[s[i]-'a'] = i;
    }

    long long ans = -1;
    for(int i=0; i<m; ++i){
        int k = (ans + n) % n;
        if(next[k][t[i]-'a'] == -1){
            cout << -1 << endl;
            return 0;
        }
        ans += next[k][t[i]-'a'];
    }
    cout << (ans + 1) << endl;

    return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)

using namespace std;
using ll = long long;
using ii = pair<int,int>;

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int x,n; cin >> x >> n;
  set<int> s;
  while (n--) {
    int a; cin >> a;
    s.insert(a);
  }
  for (int d = 0; ; ++d) {
    if (s.find(x-d) == s.end()) {
      cout << x-d << '\n';
      return 0;
    }
    if (s.find(x+d) == s.end()) {
      cout << x+d << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>

using namespace std;

int popcount(int n);

int main() {
	int  n;
	string x;
	cin >> n;
	cin >> x;
	int num_of_1=0;
	int* y = new int[n];
	for (int i = 0;i < n;i++) {
		if (x[i] == '1') {
			num_of_1++;
			y[n - 1 - i] = 1;
		}
		else {
			y[n - 1 - i] = 0;
		}
		
	}
	int h = num_of_1 + 1;
	int l = num_of_1 - 1;
	if (l < 1)l = 1;
	int *mod_h = new int[n];
	int *mod_l = new int[n];
	mod_h[0] = mod_l[0] = 1;
	mod_h[0] %= h;
	mod_l[0] %= l;
	for (int i = 1;i < n;i++) {
		mod_h[i] = 2 * mod_h[i - 1];
		mod_h[i] %= h;
		mod_l[i] = 2 * mod_l[i - 1];
		mod_l[i] %= l;
		
	}
	int y_mod_h, y_mod_l;
	y_mod_h = y_mod_l = 0;
	for (int i = 0;i < n;i++) {
		if (y[i]) {
			y_mod_h += mod_h[i];
			y_mod_l += mod_l[i];
			y_mod_h %= h;
			y_mod_l %= l;
		}
	}
	int* f = new int[n + 1];
	f[0] = 0;
	for (int i = 1;i <= n;i++) {
		int j = i % popcount(i);
		f[i] = 1 + f[j];
		
	}

	for (int i = n - 1;i >= 0;i--) {
		if (y[i] == 1) {
			if (num_of_1 == 1)cout << "0\n";
			else {
				cout <<1 + f[(y_mod_l + l - mod_l[i]) % l] << endl;
			}
		}
		else {
			cout << 1 + f[(y_mod_h + mod_h[i]) % h] << endl;
		}
	}
}

int popcount(int n) {
	int ans = 0;
	while (n > 0) {
		if (n % 2)ans++;
		n /= 2;
	}
	return ans;
}

Measured memory_bytes: 6460
// C - Vacation
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int A=0, B=0, C=0;
	for(int a,b,c; N--; A=a,B=b,C=c){
		cin>>a>>b>>c;
		a+=max(B,C); b+=max(C,A); c+=max(A,B);
	}
	cout<< max({A,B,C}) <<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 1;
  for (int i = 0; i < n; i++) {
    if (ans * 2 < ans + k) {
      ans *= 2;
    } else {
      ans += k;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3144
//   __                    .__              ________ .________ ________   ______  
//  |  | __  ____    ______|  |__   __ __  /  _____/ |   ____//   __   \ /  __  \ 
//  |  |/ /_/ __ \  /  ___/|  |  \ |  |  \/   __  \  |____  \ \____    / >      < 
//  |    < \  ___/  \___ \ |   Y  \|  |  /\  |__\  \ /       \   /    / /   --   \
//  |__|_ \ \___  >/____  >|___|  /|____/  \_____  //______  /  /____/  \______  /
//       \/     \/      \/      \/               \/        \/                  \/ 

#include<bits/stdc++.h>
#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<
#define int long long 
using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int n;
ii a[100010];
set<ii> S;
int output = 0 ;
signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].fi;
		a[i].se = i;
	}
	sort(a+1,a+n+1,greater<ii>());
	S.insert({0,0});
	S.insert({0,-1});
	S.insert({n+1,n+1});
	S.insert({n+1,n+2});
	for(int i=1;i<=n;i++){
		auto it1 = S.lower_bound({a[i].se,a[i].fi});
		it1--;
		int leftmax = a[i].se - it1->fi;
		auto it2 = it1;
		it2--;
		int leftse = it1->fi - it2->fi;
		auto it3 = S.upper_bound({a[i].se,a[i].fi});
		int rightmax = it3->fi - a[i].se;
		auto it4 = it3;
		it4++;
		int reightse = it4->fi - it3->fi;
		output+=((a[i].fi)*(reightse*leftmax + leftse*rightmax));
		S.insert({a[i].se,a[i].fi});
	}
	cout<<output;
	return 0;
}


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

int main() {
    int n, b;
    cin >> n;
    vector<int> a(n+1);
    ll ans = 0;

    for (int i = 0; i <= n; i++) {
        cin >> a.at(i);
    }

    for (int i = 0; i < n; i++) {
        cin >> b;
        if (a.at(i) < b) {
            ans += a.at(i);
            b -= a.at(i);
            if (a.at(i+1) < b) {
                ans += a.at(i+1);
                a.at(i+1) = 0;
            } else {
                ans += b;
                a.at(i+1) -= b;
            }
        } else {
            ans += b;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
V, E = map(int, input().split())
edge = [[] for _ in range(V)]
for _ in range(E):
    s, t = map(int, input().split())
    edge[s].append(t)
    edge[t].append(s)

group = [-1] * V
cnt = 0
for i in range(V):
    if group[i] == -1:
        group[i] = cnt
        stack = [i]
        while stack:
            v = stack.pop()
            for c in edge[v]:
                if group[c] == -1:
                    group[c] = cnt
                    stack.append(c)
        cnt += 1
for _ in range(int(input())):
    s, t = map(int, input().split())
    print('yes' if group[s] == group[t] else 'no')

Measured memory_bytes: 26600
a = list(map(int, input().split()))

ans = 10**5
for i in range(3):
    for j in range(3):
        for k in range(3):
            if i != j and j != k and i != k:
                cost = abs(a[j] - a[i]) + abs(a[k] - a[j])
                if ans > cost:
                    ans = cost
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Piont;
int a;
bitset<32> b;
vector<unsigned long > ans;
void f(bitset<32> curr, int i=0){
	// cout << "i = " << i << endl;
	if(i>=32){
		ans.push_back(curr.to_ulong());
		return;
	}
	if(b[i]){
		curr[i] = 1;
		f(curr, i+1);
		curr[i] = 0;
		f(curr, i+1);
	}else{
		f(curr, i+1);
	}
}
main(){
	ios::sync_with_stdio(false);
	int a,b;
	while(cin>>a>>b){
		cout << a*b << endl;
	}
}

Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int a=n%10,b=n/10%10;
        if(a==9||b==9)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;
    long[] p;
    int N;
    ArrayList<ArrayList<Integer>> list;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        int Q = sc.nextInt();
        
        int[] t = new int[N];
        
        for(int i = 0;i<N-1;i++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            t[b] = a;
        }
        p = new long[N];
        for(int i= 0;i<Q;i++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt();
            p[a] += b;
        }
        
        for(int i= 1;i<N;i++){
            p[i] += p[t[i]];
        }
        for(int i =0;i<N;i++){
            System.out.println(p[i]);
        }
    }
}


Measured memory_bytes: 164688
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
int sign(const float &d) {
	return (d == 0) ? 0 : (d > 0) ? 1 : -1;
}
struct Gradient {
	float gradient{ 0 };
	Gradient() {};
	Gradient(const float diffx, const float diffy) : gradient{ (sign(diffx) * diffy > 0) ? (diffx / diffy) : std::abs(diffy / diffx) } {}
	bool operator>(const Gradient g) const {
		return gradient > g.gradient;
	}
	bool operator<(const Gradient g) const {
		return gradient < g.gradient;
	}
	bool operator==(const Gradient g) const {
		return gradient == g.gradient;
	}
}; 
struct Point {
	float x{ 0 }, y{ 0 };
	Point() {};
	Point(const float ax, const float ay) :x{ ax }, y{ ay } {}
	bool operator<(const Point &other) const {
		return (x == other.x) ? y < other.y : x < other.x;
	}
	bool operator>(const Point &other) const {
		return (x == other.x) ? y > other.y : x > other.x;
	}
	bool operator==(const Point &other) const {
		return x == other.x && y == other.y;
	}
};
class MidPoint {
private:
	float length{};
	Point mid_point{};
	Gradient gradient{};
public:
	MidPoint() {}
	MidPoint(const float lengthSquare, const Point &mid, const Gradient &g) :length{ lengthSquare }, mid_point{ mid }, gradient{ g } {}
	bool operator>(const MidPoint &other) const {
		if (length == other.length) {
			if (mid_point == other.mid_point) return gradient > other.gradient;
			else return mid_point > other.mid_point;
		}
		else return length > other.length;
	}
	bool operator<(const MidPoint &other) const {
		if (length == other.length) {
			if (mid_point == other.mid_point) return gradient < other.gradient;
			else return mid_point < other.mid_point;
		}
		else return length < other.length;
	}
	bool operator==(const MidPoint &other) const {
		return length == other.length && mid_point == other.mid_point && gradient == other.gradient;
	}
	int square_size() const { return static_cast<int>(length) / 2; }
};
MidPoint midPointBetween(const Point &a, const Point &b) {
	return MidPoint((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y), Point{ (a.x + b.x) / 2, (a.y + b.y) / 2 }, Gradient(a.x - b.x, a.y - b.y));
}

std::vector<int> solve(int n) {
	std::vector<int> res;
	while (n != 0){
		std::vector<Point> pilars(n);
		for (auto &pilar : pilars) std::cin >> pilar.x >> pilar.y;
		std::vector<MidPoint> mid_points(n * (n - 1) / 2);
		int index{ 0 };
		for (auto i = 0; i < n; ++i) {
			for (auto j = i + 1; j < n; ++j) {
				mid_points[index++] = midPointBetween(pilars[i], pilars[j]);
			}
		}
		std::sort(mid_points.begin(), mid_points.end());
		--index;
		for (; index > 0; --index) {
			if (mid_points[index] == mid_points[index - 1]) break;
		}
		if (index != 0) res.push_back(mid_points[index].square_size());
		else res.push_back(0);
		std::cin >> n;
	}
	return res;
}
int main() {
	int n;
	std::cin >> n;
	auto res = solve(n);
	for (auto r : res) std::cout << r << std::endl;
}


Measured memory_bytes: 75132
/**
*    author:  yuya1234
*    created: 14.07.2020 09:51:38
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  //std::cout << std::fixed << std::setprecision(15);

  ll n,m;
  string s,t;
  cin>>n>>m>>s>>t;

  ll _gcd=gcd(n,m);
  ll lcm=_gcd*n/_gcd*m/_gcd;
  ll ans=-1;
  ll ss[n];
  ll tt[m];
  REP(i,n){
    ss[i]=1+(lcm/n)*i;
  }
  REP(i,m){
    tt[i]=1+(lcm/m)*i;
  }
  int i=0;
  int j=0;
  for(;;)
  {
    if(ss[i]==tt[j])
    {
      if(s[i]!=t[j])break;
      i++;
      j++;
    }
    else
    {
      if(ss[i]>tt[j])j++;
      else i++;
    }

    if(i==n || j==m)
    {
      ans=lcm;
      break;
    }
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 4932
#include<iostream>
#include<cstring> 
#include<cstdio>
#include<algorithm>
#include<stack>
using namespace std;
typedef long long ll;
//(())
//))())()((()())
const int maxn=1e5+10;
stack<char>q; 
char s[maxn];
int ans;
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len;++i)
	{
		if(!q.empty()&&q.top()!=s[i])
		{
			q.pop();
			ans+=2;
			continue;
		}
		else q.push(s[i]);
	}
	printf("%d\n",ans);
	return 0;
}

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

ll s, c;
const ll MOD = (ll)1e9 + 7;

int main(){
  cin >> s >> c;
  ll ans = 0;
  if(2 * s >= c){
    ans = c / 2;
  }else{
    ans = s + (c - 2 * s) / 4;
  }
  cout << ans;
}

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 FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {

	string s;
	cin >> s;

	bool ans;

	if (s.size() % 2 == 0)ans = false;
	else ans = true;

	if (s[0] == s[s.size() - 1])ans ^= 1;

	if (ans)cout << "First" << endl;
	else cout << "Second" << endl;

}

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

int main(){
  int n,len,cnt;
  cin>>n;
  string s,abc="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  cin>>s;
  len = s.length();
  
  vector<string> ans;
  for(int i=0;i<len;i++){
    string tmp;
    cnt = s.compare(i,1,abc,0,1);
    if(cnt+n<26){tmp = abc.substr(cnt+n,1);ans.emplace_back(tmp);}
    else{tmp = abc.substr(cnt+n-26,1);ans.emplace_back(tmp);}
  }
  
  for(int i=0;i<len;i++){
    if(i!=len-1){cout<<ans[i];}
    else{cout<<ans[i]<<endl;}
  }

  return 0;

}

Measured memory_bytes: 768
n,k=map(int,input().split())
s=list(input())
if s[k-1]=='A':
    s[k-1]='a'
elif s[k-1]=='B':
    s[k-1]='b'
else:
    s[k-1]='c'
ans=''
for i in range(n):
    ans+=s[i]
print(ans)
  

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
#include<regex>
#include<numeric>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
	bool ans = true;
	ll h, w, n,komx,komy;
	string tak, ao;
	cin >> h >> w>>n>>komy>>komx>>tak>>ao;
	komx--;
	komy--;
	ll oku=0, okd=h-1, okl=0, okr=w-1;
	for (int i = n - 1; i >= 0; i--) {
		if (oku != 0 && ao[i] == 'D')oku--;
		if (okd != h-1 && ao[i] == 'U')okd++;
		if (okl != 0 && ao[i] == 'R')okl--;
		if (okr != w-1 && ao[i] == 'L')okr++;


		if (tak[i] == 'D')okd--;
		if (tak[i] == 'U')oku++;
		if (tak[i] == 'L')okl++;
		if (tak[i] == 'R')okr--;


		if (okd < oku || okr < okl) {
			ans = false;
			break;
		}
	}
	if (okd < oku || okr < okl)ans = false;
	if (ans && (oku <= komy) && (komy <= okd) && (okl <= komx) && (komx <= okr))cout << "YES" << endl;
	else cout << "NO" << endl;
}



Measured memory_bytes: 776
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
  
#define int long long int 
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

double EPS = 1e-9; 
int INF = 1000000005; 
long long INFF = 1000000000000000005LL;
const int mod = 1e9 + 7; 

//#define CI cpp_int
string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << " " ;
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define setBits(n) __builtin_popcountll(n)
#define MX *max_element
#define MN *min_element
#define TC int t; cin >> t; while (t--) 

void Panda() {
    int n;
    cin >> n;
    cout << n + (n * n) + (n * n * n) << endl;
}
  
int32_t main() {
 
    FAST;

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

    return 0; 
} 

Measured memory_bytes: 3648
inputstr1 = input().split()
n = inputstr1[0]
k = inputstr1[1]
s = input()

N = int(n)
K = int(k)

for i in range(0, N):
    if(i == (K-1)):
        print(s[i].lower(), end="")
    elif(i == (N-1)):
        print(s[i])
    else:
        print(s[i], end="")


Measured memory_bytes: 3060
import Control.Monad
import Control.Applicative
import Data.List

main = do
  xs <- input words
  putStrLn $ solve xs

solve :: [String] -> String
solve xs = mfw ++ " " ++ maxl
  where maxl = (head . sortBy (\x y -> compare (length y) (length x))) xs
        mfw = (snd . head . sortBy (\x y -> compare (fst y) (fst x)) . map (\x -> (length x, head x)) . group . sort) xs

input :: (String -> a) -> IO a
input f = f <$> getLine

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long f[200005];
int main()
{
	int i,n,m;
	long long sum = 0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%lld",&f[i]);
	if(m<n)
	{
		sort(f,f+n);
		for(i=0;i<n-m;i++)
			sum += f[i];
	}
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 5344
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct Sieve{
	int n;
	vector<int> f, primes;
	Sieve(int n):n(n), f(n+1){
		f[0] = f[1] = -1;
		for(long long i = 2; i <= n; i++){
			if(f[i]) continue;
			primes.push_back(i);
			f[i] = i;
			for(long long j = i*i; j <= n; j += i){
				if(!f[j]) f[j] = i;
			}
		}
	}
	bool isPrime(int x){return f[x] == x;}
	vector<int> factorList(int x){
		vector<int> res;
		while(x != 1){
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}
	vector<pair<int, int>> factor(int x){
		vector<int> fl = factorList(x);
		if(fl.size() == 0) return {};
		vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0));
		for(int p : fl){
			if(res.back().first == p){
				res.back().second++;
			}
			else{
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};

const ll mod = 1000000007;

ll mod_pow(ll x, ll n, ll mod){
	ll res = 1;
	while(n > 0){
		if(n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    Sieve sie(1e6);
    map<int, int> mp;
    rep(i,n){
        cin >> a[i];
        vector<P> fl = sie.factor(a[i]);
        for(auto p : fl){
            chmax(mp[p.first], p.second);
        }
    }
    ll lcm = 1;
   for(auto p : mp){
        rep(j,p.second){
            lcm = (lcm * p.first) % mod;
        }
    }
    ll ans = 0;
    rep(i,n){
        ll b = (lcm * mod_pow(a[i], mod-2, mod)) % mod;
        ans = (ans + b) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4984
n = int(input())
t_count = 0
h_count = 0
for i in range(n):
    t_animal,h_animal = map(str,input().split())
    if t_animal < h_animal:
        h_count+=3
    elif t_animal > h_animal:
        t_count+=3
    else:
        t_count+=1
        h_count+=1
print("{} {}".format(t_count,h_count))


Measured memory_bytes: 5600
import itertools
length = int(input())
target = input()
target = [n == "o" for n in target]
for before,after in itertools.product([True,False],repeat = 2):
    tmp_answer = [0 for n in range(length)]
    tmp_answer[0] = before
    tmp_answer[1] = after
    for i in range(1,length-1):
        tmp_answer[i+1] = before ^ after ^ target[i]
        before,after = after,tmp_answer[i+1]

    if tmp_answer[length - 2] ^ tmp_answer [length - 1] ^ target[length - 1]  == tmp_answer[0] and \
    tmp_answer[length - 1] ^ tmp_answer [0] ^ target[0]  == tmp_answer[1]:
        print("".join(["S" if n else "W" for n in tmp_answer]))
        break
else:
    print(-1)

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


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

    vector<ll> h(n+1);
    for(ll i=1;i<=n;i++){
        cin>>h.at(i);
    }

    vector<ll> dp(n+1,0);

    for(ll i=2;i<=n;i++){
        if(i==2){
            dp.at(i) = abs(h.at(i)-h.at(i-1));
        }else{
            dp.at(i) = min(dp.at(i-1)+abs(h.at(i)-h.at(i-1)),
                    dp.at(i-2)+abs(h.at(i)-h.at(i-2)));
        }
    }

    cout<<dp.at(n)<<endl;
}







Measured memory_bytes: 1792
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

static int cnt;

void get_N (int64 *n)
{
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  cnt = scanf("%lld %lld", n, k);

  return;
}

void get_N1234 (int64 *n1, int64 *n2, int64 *n3, int64 *n4)
{
  if (n2 == NULL) {
    cnt = scanf("%lld", n1);
    return;
  }
  if (n3 == NULL) {
    cnt = scanf("%lld %lld", n1, n2);
    return;
  }
  if (n4 == NULL) {
    cnt = scanf("%lld %lld %lld", n1, n2, n3);
    return;
  }
  cnt = scanf("%lld %lld %lld %lld", n1, n2, n3, n4);
  return;
}

void omit_LF (void)
{
  char c;

  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;

  buf = (char *)malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  n;

  buf = (char *)malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = (int64 *)malloc((size_t)(n * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;

typedef int64 simple_t;

int compare_simple(const void *a, const void *b)
{
  simple_t *x;
  simple_t *y;

  x = (simple_t *)a;
  y = (simple_t *)b;

  if (x > y) return 1;
  if (y < x) return -1;

  return 0;
}
void qsort_simple (simple_t *array, int size)
{
  qsort(array, size, sizeof(simple_t), compare_simple);
}

int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}


int resolve1()
{
  int64 R;
  double pi=3.14159;
  double L;

  get_N(&R);

  L = pi*R*2;

  printf("%lf", L);
  return 0;
}

int64 e[102];

int resolve2()
{
  int64 X, N;
  int64 *p;
  int64 i,offset;

  get_NK(&X, &N);
  p = get_NSeq(N);

  for (i=0; i < N; i++) {
    e[p[i]] = 1;
  }

  for (offset=0; offset <= 101; offset++) {
    if (X - offset >= 0) {
      if (e[X-offset] == 0) {
        printf("%lld", (X-offset));
        return 0;
      }
    }
    if (X + offset <= 101) {
      if (e[X+offset] == 0) {
        printf("%lld", (X+offset));
        return 0;
      }
    }
  }

  return 0;
}


int main()
{

  resolve2();
  
  return 0;
}



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

const long long int r = 1e9 + 7;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  long long int sum = 0;
  for (long long int i = k; i <= n+1; ++i){
	sum += (n*(n+1)*1LL)/2 - ((n-i)*(n-i+1)*1LL)/2 - (i*(i-1)*1LL)/2 + 1;
       sum = (sum + r) % r;	
  }
  cout << sum << "\n";
return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main() {
	int q1, q2, q3;
	scanf("%d %d %d", &q1, &q2, &q3);
	for (int i = 0; i < q2; i++) {
		cout << q3 << " ";
	}
	for (int i = q2; i < q1; i++) {
		if (q3 > 100000)cout << q3 - 5 << " ";
		else cout << q3 + 5 << " ";
	}
	return 0;
}

Measured memory_bytes: 1280
#ifndef DEBUG
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,popcnt,tune=native")
#endif // DEBUG
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <stack>
using namespace std;
typedef long long ll;
inline ll read()
{
    int ch=getchar(),f=1;
    ll ans=0;
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=0;
    for(;ch>='0'&&ch<='9';ch=getchar())
        ans=(((ans<<2)+ans)<<1)+(ch^'0');
    return f?ans:-ans;
}
int n;
int main()
{
    n=read();
    double ans=0;
    for(int i=1;i<=n;++i)
        ans+=(1.0/read());
    ans=1./ans;
    printf("%.10f",ans);
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
// need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <queue>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
// utility
#define all(i) (i).begin(), (i).end()
#define rep(i, n) for(int i=0;i<int(n);++i)
#define rrep(i, n) for(int i=int(n)-1;i>=0;--i)
#define in(a, x, b) (a<=x && x<b)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

template<typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")"; return os;
}

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int MOD = 1000000007;


signed main() {
  int N;
  std::cin >> N;

  std::vector<int> a(N);
  rep(i, N) std::cin >> a.at(i);

  std::vector<int> flag(N);

  int next = 1;
  int cnt = 0;
  flag.at(0) = 1;
  while(true){
    next = a.at(next-1);
    flag.at(next-1)++;
    cnt++;
    if(next == 2){
      std::cout << cnt;
      break;
    }
    if(flag.at(next-1) == 2){
      std::cout << -1;
      break;
    }
  }
  std::cout << std::endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
using namespace std;

int main() {
    int n, q;
    string s;
    cin >> n >> q;
    cin >> s;
    vector<int> sum(n+1, 0);
    for(int i = 1; i < n; i++) {
        if(s[i-1] == 'A' && s[i] == 'C') {
            sum[i] = sum[i-1] + 1;
        } else {
            sum[i] = sum[i-1];
        }
    }

    for(int i = 0; i < q; i++) {
        int L, R;
        cin >> L >> R;
        int ans = sum[R-1] - sum[L-1];
        cout << ans << endl;
    }
}



Measured memory_bytes: 1408
#![allow(unused_imports)]

use text_io::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let mut a:usize = read!();
    let mut b:usize = read!();
    let mut c:usize = read!();
    if a<=b*c {
        println!("Yes");
    }
    else { 
        println!("No");
    }
}

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

using namespace std;

int main(void)
{
    unsigned long int A;
    float B;
    cin >> A >> B;

    int C = 100 * B + 0.5;
    if(A == 0 || C == 0){
        cout << 0 << endl;
    }
    else{
    cout <<  A * C / 100 << endl;
    }
    return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    string s = a + b + c;
    YES(stoi(s) % 4 == 0);
    return 0;
}



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

int gcd (int p,int q){
  if(p % q == 0)return q;
  return gcd(q, p % q);
}

int main(){
  int K;
  unsigned long long sum = 0;

  cin >> K;

  for(int i = 1; i <= K; i++){
    for(int j = 1; j <= K; j++){
      for(int l = 1; l <= K; l++){
        sum += gcd(i, gcd(j,l));
      }
    }
  }

  cout << sum << endl;

}


Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main()
{
	int n, a;
    pair<int, int> no1(0, 0), no2(0, 0); // <index, value>
    cin >> n;

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

        if(no1.second < a) 
            no1 = make_pair(i, a);
        else if(no2.second < a)
            no2 = make_pair(i, a);
    }

    for(int i = 0; i < n; ++i) {
        if(no1.first == i) 
            cout << no2.second << '\n';
        else
            cout << no1.second << '\n';
    }
}


Measured memory_bytes: 1664
computeGreatestCommonFactor :: [Int] -> Int
computeGreatestCommonFactor list = foldr1 gcd list

main :: IO ()
main = do
  [number, start] <- map read . words <$> getLine
  positions <- map read . words <$> getLine
  let distances = map (abs . (\x -> x - start)) positions
  let greatestCommonFactor = computeGreatestCommonFactor distances
  print greatestCommonFactor

Measured memory_bytes: 36220
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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 A,B;
inline void solve(){
  IN2(A,B);
  if(A%3==0)OUT("Possible");
  else if(B%3==0)OUT("Possible");
  else if((A+B)%3==0)OUT("Possible");
  else OUT("Impossible");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

int main(){
	ll N,ans=0,mina=1000000,a;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a;
		if(a<=mina){
			ans++;
		}
		mina = min(mina,a);
	}
	cout << ans << endl;
}

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

using namespace std;

int main() 
{
    int n;
    cin >> n;
    int ans = n;
    for (int i = 0; i <= n; i++) {
        int den;
        int cnt = 0;
        for (den = 1; den <= i; den *= 6);
        den /= 6;
        if (den) 
            for (; den > 0; den /= 6)
                cnt += (i/den) % 6;
        for (den = 1; den <= n-i; den *= 9);
        den /= 9;
        if (den) 
            for (; den > 0; den /= 9)
                cnt += ((n-i)/den) % 9;
        if (cnt < ans) ans = cnt;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n =int(raw_input())
lis=[]
for i in range(1,26):
    lis.append(4*i)
for i in range(1,15):
    lis.append(7*i)
for i in range(1,20):
    for j in range(1,20):
        lis.append(4*i+7*j)
if n in lis:
    print "Yes"
else:
    print "No"


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
char s[15];
int n;
long long ans = 0, p[12];

inline long long calc(int a, int b){
	long long ret = 0, tmp = 1;
	for(int i = b; i >= a; --i){
		ret += tmp * (s[i] - '0'); tmp *= 10;
	}
	return ret;
}

int main()
{
    p[0] = 1; for(int i = 1; i <= 10; ++i) p[i] = p[i - 1] << 1;
    scanf("%s", s + 1); n = strlen(s + 1);
    for(int i = 1; i <= n; ++i)
        for(int j = i; j <= n; ++j){
            ans += calc(i, j) * p[max(0, i - 2)] * p[max(0, n - j - 1)];        	
        }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import sys


TEST_INPUT = [
    """
    red blue
    3 4
    red
    """,
    """
    red blue
    5 5
    blue
    """
]
ANSWER = [
    "2 4",
    "5 4"
]


class InputHandler:

    def __init__(self, text_lines="", is_test=False):
        self.data = list(text_lines.split("\n"))
        self.index = 0
        self.is_test = is_test

    def input(self):
        if self.is_test:
            self.index += 1
            return self.data[self.index].strip()
        else:
            return sys.stdin.readline().rstrip()


def solve(s, t, a, b, u):
    if s == u:
        return str(a - 1) + " " + str(b)
    else:
        return str(a) + " " + str(b - 1)


def input_and_solve(ih):
    s, t = ih.input().split()
    a, b = map(int, ih.input().split())
    u = ih.input()
    res = solve(s, t, a, b, u)
    return res


def main():
    ih = InputHandler()
    res = input_and_solve(ih)
    print(res)


def test():
    for test_input, ans in zip(TEST_INPUT, ANSWER):
        ih = InputHandler(test_input, True)
        res = input_and_solve(ih)
        assert str(res) == str(ans)


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using ll = long long;

////////////////////////// templates

template<class U>
void PRINT(std::vector<U> &x) {
    for (int i=0;i<x.size();++i) {
        cout << x[i];
    }
}

template<class U>
void PRINTLN(std::vector<U> &x) {
    PRINT<U>(x);
    cout << endl;
}

////////////////////////// functions
int dfs(int M, const vector<int> X) {
    int N = X.size()-1;
    if (M==N) {
        return 1;
    }
    int temp = 1;
    for (int i=1;i<=(N-M);++i) {
        temp *= i;
    }
    int ans = 0;
    for (int i=M;i<=N;++i) {
        if(X[i] < X[M]) ans += temp;
    }
    ans += dfs(M+1, X);
    return ans;
}

////////////////////////// main

int main() {
    ll N;
    cin >> N;
    vector<int> P(N+1,-1), Q(N+1,-1);
    for (int i=1;i<=N;++i){
        cin >> P[i];
    }
    for (int i=1;i<=N;++i){
        cin >> Q[i];
    }
    int a = dfs(1, P);
    int b = dfs(1, Q);
    // cout << a << ", " << b << endl;
    cout << abs(a-b) << endl;
    return 0;
}

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

int main() {
	int N,a;
	double sum = 0;
	double iti = 0;
	vector<double> v;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		v.emplace_back(a);
	}
	for (int i = 0; i < N - 1; i++) {
		sort(v.begin(), v.end());
		for (int j = N - 2 - i; j >= 0; j--) {
			double sa = v[j + 1] - v[j];
			double min = 10000000;
			if (min >= sa) {
				min = sa;
				iti = j + 1;
			}
		}
		v.push_back((double)(v[iti] + v[iti - 1]) / (double)2);
		v.erase(v.begin() + iti);
		v.erase(v.begin() + iti - 1);
	}
	cout << v[0] << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
def main():
  _map, _input, _int = map, input, int
  n, q = _map(_int, _input().split())
  values = [0] * n
  links = [[] for _ in range(n)]
  for _ in range(n - 1):
    a, b = _map(_int, _input().split())
    links[a - 1].append(b - 1)
    links[b - 1].append(a - 1)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p - 1] += x
  d = deque()
  d.append((0, -1))
  while len(d) != 0:
    i, p = d.popleft()
    for j in links[i]:
      if j == p:
        continue
      values[j] += values[i]
      d.append((j, i))
  print(*values)
main()


Measured memory_bytes: 62132
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long 
using namespace std;

signed main() {
	int A,B,C;
	cin >> A >> B >> C;
	if(A + B == C || A + C == B || B + C == A) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  vector<vector<int>> c(3, vector<int>(3));
  rep(i, 3)
  {
    rep(j, 3)
    {
      cin >> c.at(i).at(j);
    }
  }
  vector<int> a(3), b(3);
  // a1 = 0
  a[0] = 0;
  b[0] = c.at(0).at(0) - a[0];
  b[1] = c.at(0).at(1) - a[0];
  b[2] = c.at(0).at(2) - a[0];
  a[1] = c.at(1).at(0) - b[0];
  a[2] = c.at(2).at(0) - b[0];
  rep(i, 3)
  {
    rep(j, 3)
    {
      if (c.at(i).at(j) != a[i] + b[j])
      {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
#define mp make_pair
#define x first
#define y second

ll modm[100003];

int main () {
	ll n;
	cin>>n;
	ll m,x;
	cin>>x>>m;
	if(n<m){
		ll s=0ll;
		for(int i=1;i<=n;i++){
			s+=x;
			x=(x*x)%m;
		}
		cout<<s;
		return 0;
	}
	ll br=1,cik,s=0ll,scik=0ll,sost=0ll;
	while(true){
		if(modm[x]==0){
			modm[x]=br;
			s+=x;
		}
		else{
			cik=br-modm[x];
			break;
		}
		br++;
		x=(x*x)%m;
	}
	n-=br-1;
	ll brc=n/cik;
	ll ost=n%cik;
	ll y=x;
	int novibr=0;
	while(true){
		scik+=x;
		novibr++;
		if(novibr==ost){
			sost=scik;
		}
		if((x*x)%m==y) break;
		x=(x*x)%m;
	}
	s+=brc*scik+sost;
	cout<<s;
	



return 0;
}



Measured memory_bytes: 4404
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair

typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//find_by_order(x) -> returns an iterator to the element at a given position
//order_of_key(x) -> returns the position of a given element

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;

const int mod = (int)1e9 + 7;
const int MAXN = 1e5+12;
//indexed_set s;

double x[2*MAXN],y[2*MAXN];
int n;
double d;

int main() {

    cin >> n >> d;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        double dist = sqrt(x[i]*x[i] + y[i]*y[i]);
        if (dist <= d) ans++;
    }

    cout << ans;

return 0;
}


Measured memory_bytes: 6864
a,b,k = map(int,input().split())

A = []
B = []
for i in range(1,a+1):
    if a % i == 0:
        A.append(i)
for i in range(1,b+1):
    if b % i == 0:
        B.append(i)
common = list(set(A) & set(B))
common.sort(reverse=True)

print(common[k-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define max 20 
 
bool vis[max][max];   
char z[max+5][max+5];
int a,b,c;
int maxx;
int dir[4][2]={-1,0,0,1,1,0,0,-1}; //(¾ßÌåÇé¿öÉèÖÃ)   
struct state{   
    int x,y;   
    int step;   }e;   
queue<state>q;   
bool check(state s){   
    if(s.x>=0&&s.y>=0&&s.x<a&&s.y<b&&vis[s.x][s.y]==0&&z[s.x][s.y]=='.') return 1;   
    else return 0;   
}   
void bfs(state st){ 
	memset(vis,0,sizeof(vis)); 
	maxx=0;
    state now,next;   
     st.step=0;   
     q.push(st);   
     vis[st.x][st.y]=1;   
    while(!q.empty()){   
    now=q.front();   
      for(int i=0;i<4;i++){  
        next.x=now.x+dir[i][0];   
        next.y=now.y+dir[i][1];   
        next.step=now.step+1;   
        if(check(next)){   
        q.push(next);   
        vis[next.x][next.y]=1; 
        if(maxx<next.step)maxx=next.step;
        }   
      }   
    q.pop();   
    }   
}

int main()
{
	scanf("%d%d",&a,&b);
	c=0;
	for(int i=0;i<a;i++)scanf("%s",&z[i]);
	for(int i=0;i<a;i++)
	{
		for(int j=0;j<b;j++)
		{
			if(z[i][j]=='.')
			{
				e.x=i;
				e.y=j;
				bfs(e);
				if(c<maxx)c=maxx;
			}
		}
	}
	printf("%d",c);
}


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

int main(){
    int k,x;
    cin >> k >> x;
    for(int i=0;i<2*k-1;i++){
        cout << x-k+i+1 << " ";
    }
    cout << endl;
    }

Measured memory_bytes: 256