akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)

#include <atcoder/all>
using namespace atcoder;

int main() {
	int T; cin >> T;
	while (T--) {
		ll N, M, A, B; cin >> N >> M >> A >> B;
		cout << floor_sum(N, M, A, B) << endl;
	}
}

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

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N; cin >> N;
	
	int n = 0;
	int tmp = N;
	while (N) {
		n += N % 10;
		N /= 10;
	}
	if (tmp%n == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
//بسم الله الرحمن الرحيم
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define el << endl
#define PI 3.141592653589793238
#define _test_ int t; cin >> t; while(t--)
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
ll gcd ( ll  a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }
int dx[]={0,0,+1,-1,+1,-1,-1,+1};
int dy[]={+1,-1,0,0,+1,-1,+1,-1};
///*......................*//* LET'S BEGIN (-_^) *//*............................///
const int mx= 1e6+123;

void _case_()
{
    int n,m,sum=0,scr=0;
    vector<int>pen;
    cin >> n >> m;
    map<int,int>mp;
    while (m--)
    {
        int i;string s;
        cin >> i >> s;
        if(s=="AC") mp[i]++;
        if(s=="WA" and !mp[i]) pen.push_back(i) ;
    }
    for(auto i:mp)
        if(i.second) scr++;
    for(auto i:pen)
    {
        if(mp[i]) sum++;
    }
    cout << scr << ' ' << sum << endl;
}



int main()
{
    optimize();
    //_test_
      _case_();
}

///////////*  N A Y E M  *///////////

Measured memory_bytes: 8260
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
struct edge{int to; ll cost;};
using Graph = vector<vector<edge>>;
const int inf = 1e9;

// 使われうる辺集合
set<pair<int,int> > use;

// s を始点とする Dijkstra
vector<ll> Dijkstra(const Graph &G, int s) {
    vector<ll> dist((int)G.size(), inf);
    vector<vector<int> > prev((int)G.size()); // prev[v] := v から復元できる辺たち
    dist[s] = 0;
    priority_queue<pair<ll,int>, vector<pair<ll,int> >, greater<pair<ll,int> > > que;
    que.push({0, s});
    while (!que.empty()) {
        auto cur = que.top(); que.pop();
        ll cur_dist = cur.first;
        int v = cur.second;
        if (cur_dist > dist[v]) continue; // 効く枝刈り
        for (auto e : G[v]) {
            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                que.push({dist[e.to], e.to});

                // 復元のための
                prev[e.to].clear();
                prev[e.to].push_back(v);
            }
            else if (dist[e.to] == dist[v] + e.cost) {
                prev[e.to].push_back(v);
            }
        }
    }

    // 使われうる辺集合
    for (int v = 0; v < (int)G.size(); ++v) {
        for (auto u : prev[v]) {
            use.insert(make_pair(min(u, v), max(u, v)));
        }
    }
    return dist;
}

int main(){
    int n, m; cin >> n >> m;
    Graph g(n);
    rep(i,m){
        int a,b; ll c; cin >> a >> b >> c; a--; b--;
        g[a].push_back(edge{b,c});
        g[b].push_back(edge{a,c});
    }
    rep(v, n) Dijkstra(g, v);
    cout << m - (int)use.size() << endl;
}

Measured memory_bytes: 764
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ll a=read();
	cout<<a+a*a+a*a*a<<endl;
	return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
ll num;

ll ge(ll n) {
    if(n == 1) return 0;
    ll cnt = 0;
    ll i = 2;
    for(; i*i<n;i++) {
        if(n % i == 0) cnt += 2;
    }
    if(n % i == 0) cnt ++;
    return cnt+1;
}

ll get(ll n) {
    ll cnt = 0;
    ll i = 2;
    
    for(; i*i <= n; i ++) {
        if(n%i) continue;
        ll z = n;
        while(z%i == 0) z /= i;
        if(z%i == 1) cnt ++;
    }
    return cnt;
}
int main() {
    cin >> num;
    //cout << ge(9) << endl;
    //if(num == 2) cout << 1 << endl;
    cout << get(num) + ge(num-1) + 1 << endl;
    return 0;
}

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

void printA(int A[], int N){
	printf("%d",A[0]);
	for(int i=1; i<N; ++i){
		printf(" %d",A[i]);
	}
	printf("\n");
}

main(){
	int N;
	cin >> N;
	
	int A[N];
	for(int i=0; i<N; ++i){
		cin >> A[i];
	}
	printA(A, N);
	for(int i=1; i<N; ++i){
		int v = A[i];
		int j = i - 1;
		while(j >= 0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		
		printA(A, N);
	}
}


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



int main() {
    int N, judge=0, count=0;
    ll max=LLONG_MIN, min=LLONG_MAX, value;
    
    cin >> N;
    
    rep(i,N) {
    cin >> value;
    if(value<min) min=value;
    if(value>max) max=value;
    }
    
    cout << max-min;
    
      
}

Measured memory_bytes: 3640
#include <iostream>

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


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


struct trump{
    int value;
    char mark;
};

std::vector<trump> selectionSort(std::vector<trump> a, int n){
    int minj;
    trump tmp;
    for(int i = 0;  i < n; i++){
        minj = i;
        for(int j = i; j < n; j++){
            if(a[j].value < a[minj].value){
                minj = j;
            }
        }
        tmp = a[i];
        a[i] = a[minj];
        a[minj] = tmp;
        
    }
    return a;
}

std::vector<trump> bubbleSort(std::vector<trump> a, int n){
    bool flag = true;
    trump tmp;
   
    while(flag){
        flag = false;
        for(int j = n-1; j > 0; --j){
            if(a[j].value < a[j-1].value){
                tmp = a[j-1];
                a[j-1] = a[j];
                a[j] = tmp;
                flag = true;
            }
        }
    }
    return a;
}

void displayVector(std::vector<trump> a, int n){
    for(int i = 0; i < n; i++){
        std::cout << a[i].mark << a[i].value;
        if(i != n-1){
            std::cout << " ";
        }
    }
    std::cout << std::endl;
}

int check(std::vector<trump> a, std::vector<trump> c, int n){
    bool flag;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(a[i].value != a[j].value){
                continue;
            }else{
                //std::cout << "a value is same" << std::endl;
                //flag1 = true;
                for(int k = 0; k < n; k++){
                    if(a[i].value == c[k].value && a[i].mark == c[k].mark){
                    }else{
                        continue;
                    }
                    for(int l = k + 1; l < n; l++){
                       if(a[j].value == c[l].value){
                            if(a[j].mark == c[l].mark){
                                flag = true;
                            }else{
                                std::cout << "Not stable" << std::endl;
                                return -1;
                            }
                       }else if(l = n - 1){
                            std::cout << "Not stable" << std::endl;
                            return -1;
                       }else{
                           continue;
                       }
                       if(flag) break;
                    }
                    if(flag) break;    
                }
                
            }
            if(flag){
                flag = false;
                break;
            } 
        }
    }
    std::cout << "Stable" << std::endl;
    return 0;
}


int main(void){
    int n;
    std::string tmp;
    scanf("%d", &n);
    std::vector<trump> a(n), c(n);

    for(int i = 0; i < n; i++){
        //scanf("%s", tmp);
        std::cin >> a[i].mark >> a[i].value;
    }
    //std::cout << std::endl;
    //displayVector(a, n);

    c = bubbleSort(a, n);
    displayVector(c, n);
    check(a, c, n);

    c = selectionSort(a, n);
    displayVector(c, n);
    check(a, c, n);


    return 0;
}


Measured memory_bytes: 3228
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<utility>
#include<functional>
typedef long long ll;
using namespace std;
typedef pair<int,int> p;

#define MAX 2000000000

struct Edge{
  int to;
  int cost;
};

ll kyori[100001];
vector<Edge> edges[100001];
int Dijkstra(){

}

int main(){
  int V,E,r;

  priority_queue<p,vector<p>,greater<p> > pq;


  cin >> V >> E >> r;

  for(int i=0;i<E;i++){
    int s,t,d;
    cin >> s >> t >> d;
    edges[s].push_back(Edge{t,d});
  }

  for(int i=0;i<V;i++){
    kyori[i] = MAX;
  }
  kyori[r]=0;
  pq.push(p(0,r));

  while(!pq.empty()){
    r = pq.top().second;
    if(kyori[r]>=pq.top().first){
      //kyori[r]=pq.top().first;
      pq.pop();
    }else{
      pq.pop();
      continue;
    }
    for(int i=0;i<edges[r].size();i++){
      if(kyori[edges[r][i].to]>kyori[r]+edges[r][i].cost){
        kyori[edges[r][i].to] = kyori[r]+edges[r][i].cost;
        pq.push(p(kyori[r]+edges[r][i].cost,edges[r][i].to));
      }
    }
  }

  for(int i=0;i<V;i++){
    if(kyori[i] < MAX){
      cout << kyori[i] << endl;
    }else{
      cout << "INF" << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 13320
#include<bits/stdc++.h>
#define N int(2e5+1)
#define M int(1e9+7)
#define LL long long int
using namespace std;
int main()
{
	int n,ans=0;
	string s;
	cin>>n>>s;
	for(int i=0;i<n-2;i++)
		if(s[i]=='A' and s[i+1]=='B' and s[i+2]=='C')
			ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
AUTHOR: Aman Raj
LANG: C++
*/

using namespace std;

typedef   long long  int ll;
#include <bits/stdc++.h>


//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define all(a) a.begin(),a.end()
//#define mod 998244353


#define mod   1000000007

#define inf 1e18
//#define mod 3
#define flush fflush(stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<ll, ll, hash< ll > > ht;

// find_by_order()  // order_of_key
typedef tree<
    ll,
    null_type,
    less<ll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;






ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }



 struct less_then_greater {
    template<typename T, typename U>
    bool operator()(T const& lhs, U const& rhs) const {
        if (lhs.first < rhs.first) return true;
        if (rhs.first < lhs.first) return false;
        return lhs.second > rhs.second;
    }
};
 /*std::priority_queue<std::pair<int, int>,
                    std::vector<std::pair<int, int>>,
                    less_then_greater
                   > pq;*/
  /*   #define MAXN 1000001
ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)

        // marking smallest prime factor for every
        // number to be itself.
        spf[i] = i;

    // separately marking spf for every even
    // number as 2
    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (int i=3; i*i<MAXN; i++)
    {
        // checking if i is prime
        if (spf[i] == i)
        {
            // marking SPF for all numbers divisible by i
            for (int j=i*i; j<MAXN; j+=i)

                // marking spf[j] if it is not
                // previously marked
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
vector<ll> getFactorization(ll x)
{
    vector<ll> ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
*/
// take multiset of all edges
// meanwhile for all cc keep record of all edges in multiset too which can be used to digest
// one line or two lines
//

int main()
{   ll n,d;cin>>n>>d;
      ll ans=0;
       while(n--)
       {
           ll x,y;cin>>x>>y;
           if(x*x+y*y<=d*d)ans++;
       }
       cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3576
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.Callable;



interface Command {
    int runCommand(int a, int b);
}

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);

        Map<Character, Command> methodMap = new HashMap<Character, Command>();

        methodMap.put('+', new Command() {
            public int runCommand(int a, int b) { return a + b; };
        });
        methodMap.put('-', new Command() {
            public int runCommand(int a, int b) { return a - b; };
        });
        methodMap.put('/', new Command() {
            public int runCommand(int a, int b) { return a / b; };
        });
        methodMap.put('*', new Command() {
            public int runCommand(int a, int b) { return a * b; };
        });

        while(true) {
            int one = input.nextInt();
            char op = input.next().charAt(0);
            if(op =='?') break;
            int two = input.nextInt();
            int result = methodMap.get(op).runCommand(one,two);
            System.out.println(result);
        }
    }
}


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

int main(void)
{
    long long h, w, ans, i;

    cin >> h >> w;

    if (h * w % 3 == 0)
		ans = 0;
	else
		ans = min(h, w);

    for (i = 1; i <= h; i++)
	{
        long long A = i * w,
			B = (w / 2 + w % 2) * (h - i),
			C = w / 2 * (h - i);

		ans = min(ans, max(A, max(B, C)) - min(A, min(B, C)));
	}

	for (i = 1; i <= w; i++)
	{
        long long A = i * h,
			B = (h / 2 + h % 2) * (w - i),
			C = h / 2 * (w - i);

		ans = min(ans, max(A, max(B, C)) - min(A, min(B, C)));
	}

	cout << ans;
	return 0;
}

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

int main() {
  int N, T;
  cin >> N >> T;
  vector<int> t(N);
  for (int i = 0; i < N; i++) cin >> t.at(i);
  
  int ans = T;
  for (int i = 0; i < N - 1; i++) {
    ans += min(t.at(i + 1) - t.at(i), T);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
n,k = map(int, input().split())
a = list(map(int, input().split()))
s = len(set(a))
ans = 0
dic = {}
for i in range(n):
    dic[a[i]] = 0
for i in range(n):
    dic[a[i]] += 1
ans = 0
for i in sorted(dic.items(), key = lambda x:x[1]):
    if s <= k:
        break
    ans += i[1]
    s -= 1
print(ans)

Measured memory_bytes: 48284
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl;
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef queue<int> Q;

int main()
{
    int n;
    cin >> n;
    V s(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    sort(ALL(s));
    int sum = accumulate(ALL(s), 0);
    for (auto i : s)
    {
        if (sum%10 == 0 && i%10 != 0)
        {
            sum -= i;
        }
    }
    if (sum%10 == 0)
    {
        OUT(0);
    }
    else
    {
        OUT(sum);
    }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] count = new int[n + 1];
    int max = 0;
    for(int i = 0; i < n; i++) {
      int num = sc.nextInt();
      if (i == 0 && num != 0) {
        System.out.println(0);
        return;
      }
      count[num]++;
      max = Math.max(max, num);
    }
    if (count[0] != 1) {
      System.out.println(0);
      return;
    }
    for(int i = max; i >= 0; i--) {
      if (count[i] == 0) {
        System.out.println(0);
        return;
      }
    }
    long ans = 1;
    for(int i = 1; i <= max; i++) {
      long prev = count[i - 1];
      long base = 1;
      long num = count[i];
      for(int j = 0; j < num; j++) {
        base *= prev;
        base %= 998244353;
      }
      ans *= base;
      ans %= 998244353;
    }
    System.out.println(ans);
  }
}


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

vector<long> stc;
long dfs(int key, vector<vector<int>> &V, vector<bool> &f, vector<long> &t, long M){
    long mn=M;
    for(int i=0; i<V[key].size(); ++i){
        if(f[V[key][i]]){
            if(mn>t[V[key][i]]){
                stc.push_back(mn);
                mn=t[V[key][i]];
            }
            else stc.push_back(t[V[key][i]]);
            f[V[key][i]]=false;
            mn=dfs(V[key][i], V, f, t, mn);
        }
    }
    return mn;
}

int main() {
    int N, M; cin >> N >> M;
    vector<long> a(N);
    for(int i=0; i<N; ++i) cin >> a[i];
    vector<vector<int>> v(N);
    for(int i=0; i<M; ++i){
        int x, y; cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    if(2*(M+1)<N){
        cout << "Impossible" << endl;
        return 0;
    }
    if(N-M<2){
        cout << 0 << endl;
        return 0;
    }
    vector<bool> INC(N, true);
    long ans=0;
    for(int i=0; i<N; ++i){
        if(INC[i]){
            INC[i]=false;
            ans += dfs(i, v, INC, a, a[i]);
        }
    }
    sort(stc.begin(), stc.end());
    for(int i=0; i<N-M-2; ++i) ans += stc[i];
    cout << ans << endl;
    return 0;
}


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

int main(){
  int n, AC = 0, WA = 0, TLE = 0, RE = 0;
  string s;
  cin>> n;
  
  for(int i=0;i<n;i++){
    cin>>s;
    if(s == "AC")AC++;
    else if(s == "WA")WA++;
    else if(s == "TLE")TLE++;
    else RE++;
  }
  
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", AC, WA, TLE, RE);
  
  return 0;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool compareg(Pi a, Pi b) {
    if(a.second != b.second){
        return a.second > b.second;
        
    }else{
        return a.first > b.first;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};




int main() {
    ll N,W;
    cin>>N>>W;
    vector<ll> v(N);
    vector<ll> w(N);

    rep(i,N){
        cin>>v[i]>>w[i];
    }

    vector<vector<ll>> dp(N+2,vector<ll>(W+2));

    rep(i,N){
        rep(j,W+1){
            if(j-w[i]>=0){
                dp[i+1][j] = max({dp[i][j],dp[i][j-w[i]]+v[i],dp[i+1][j-w[i]]+v[i]});
            }else{
                dp[i+1][j] = dp[i][j];
            }
            
        }
    }
 
    cout<<dp[N][W]<<endl;
    return 0;
    

}



Measured memory_bytes: 11000
#include <stdio.h>

int solve(int,int);

int n,a[20];

int main(){
  int m[200],q,i;
  int x,y=0;

  scanf("%d",&n);
  for(i = 0; i < n; i++)
  scanf("%d",&a[i]);
  
  scanf("%d",&q);
  for(i = 0; i < q; i++)
  scanf("%d",&m[i]);

  for(i = 0; i < q; i++){
    x = solve(y,m[i]);
    if(x == 1) printf("yes\n");
    else printf("no\n");
  }

  return 0;
    }

int solve(int i,int m)
{
  int res;
  if(m == 0) return 1;

  if(i >= n) return 0;

  res = solve(i+1,m) || solve(i+1,m-a[i]);
  return res;
}

Measured memory_bytes: 580
n,m = map(int,input().split())
a = []
b = []
ans = 0
for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))
for i in range(n-m+1):
    for j in range(n-m+1):
        cnt = 0
        for s in range(m):
            for t in range(m):
                if b[s][t] == a[s+i][t+j]:
                    cnt += 1
        if cnt == m*m:
            ans = 1
if ans == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9212
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

struct UnionFind{
    vector<ll> link;
    UnionFind(ll n):link(n,-1){}
    ll find(ll v){
        if(link[v]<0) return v;
        else return link[v]=find(link[v]);
    }
    bool unite(ll v,ll w){
        v=find(v); w=find(w);
        if(v==w) return 0;
        if(link[v]>link[w]) swap(v,w);
        link[v]+=link[w];
        link[w]=v;
        return 1;
    }
    bool same(ll v,ll w){
        return find(v)==find(w);
    }
};

int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    UnionFind uf(n);
    ll a,b;
    vector<ll> frnd(n,0);
    rep(i,m){
        cin>>a>>b;
        a--; b--;
        frnd[a]++;
        frnd[b]++;
        uf.unite(a,b);
    }
    vector<ll> block(n,0);
    rep(i,k){
        cin>>a>>b;
        a--; b--;
        if(uf.same(a,b)){
            block[a]++;
            block[b]++;
        }
    }
    rep(i,n){
        cout<<-uf.link[uf.find(i)]-1-frnd[i]-block[i]<<' ';
    }
    cout<<endl;
    return 0;
}

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

int main() {
int a[100],n,x,sum=0;
cin>>n;
cin>>x;
for (int i=0;i<n;i++)
cin>>a[i];
for (int i=0;i<n;i++){
	sum=sum+a[i];
}
sort(a,a+n);
int left=x-sum;
int b=left/a[0];
int ans=b+n;
cout<<ans;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int i=0;
int k[100];

void push(int);
int pop (void);

int main(){

  int a,b,c;
  char d[100];

  while(scanf("%s",d)!=EOF){
    if(d[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(d[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(d[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    
    else{
     c=atoi(d);
      push(c);
    }
  }
  printf("%d\n",k[i]);
  return 0;
}

void push(int j){
  i++;
  k[i]=j;
}

int pop(void){
  i--;
  return k[i+1];
}


Measured memory_bytes: 2108
from sys import stdin
import numpy as np

lines = stdin.readlines()
n, m, c = [int(x) for x in lines[0].rstrip().split()]
b = [int(x) for x in lines[1].rstrip().split()]
a_s = np.zeros((n, m))
count = 0
for i in range(n):
    a_s[i] = [int(x) for x in lines[i+2].rstrip().split()]
    prod = sum(a_s[i] * b)
    if prod + c > 0:
        count += 1
print(count)


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

bool chmax(ll &a, ll b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

int main() {

    ll n, t, s; cin >> n >> t >> s;
    vector<ll> a(n+1), b(n+1);
    a[0] = b[0] = 0;
    for (ll i = 0; i < n; i++) {
        cin >> a[i+1] >> b[i+1];
    }

    vector<vector<ll>> dp(n+1, vector<ll>(t+1, 0));
    
    for (ll i = 1; i <= n; i++) {
        for (ll j = 0; j <= t; j++) {
            if (j + b[i] <= t && !(j < s && s < j + b[i])) {
                chmax(dp[i][j + b[i]], dp[i-1][j] + a[i]);
            }
            chmax(dp[i][j], dp[i-1][j]);
        }
    }

    cout << *max_element(dp[n].begin(), dp[n].end()) << endl;

}


Measured memory_bytes: 73384
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#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 Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN4(a,b,c,d);
  if(a!=c) OUT(1);
  else OUT(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int toInt(vector<int> i) {
  return i[0] * 1000 + i[1] * 100 + i[2] * 10 + i[3];
}

vector<int> toVec(int n) {
  vector<int> result;
  result.pb(n / 1000);
  result.pb((n / 100) % 10);
  result.pb((n / 10) % 10);
  result.pb(n % 10);
  return result;
}

vector<int> calc(vector<int> v) {
  sort(v.rbegin(), v.rend());
  int L = toInt(v);

  sort(v.begin(), v.end());
  int S = toInt(v);

  int N = L - S;
  return toVec(N);
}

int main() {
  int N;
  while (cin >> N) {
  if (N == 0) break;
    vector<int> input = toVec(N);

    if(input[0] == input[1] &&
      input[1] == input[2] &&
      input[2] == input[3] ) {
        cout << "NA" << endl;
    } else {
      int count = 0;
      while (toInt(input) != 6174) {
        count++;
        input = calc(input);
      }
      cout << count << endl;
    }
  }
}



Measured memory_bytes: 3156
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;

#define FOR(i,a) for(int i=0;i<a;i++)
#define MOD 1000000007LL

long long int beki(long long int a,long long int b){
	long long int ans=1;
	int t=0;
	long long int beki2[70];
	beki2[0]=a;
	for(int i=1;i<70;i++){
		beki2[i]=(beki2[i-1]*beki2[i-1])%MOD;
	}
	while((1LL<<t) < b){
		if(b&(1LL<<t)){
			ans=(ans*beki2[t])%MOD;
		}
	}
	return ans;
}


int main(){
	long long int count[60][2];
	FOR(i,60){count[i][0]=0LL;count[i][1]=0LL;}
	int n;cin>>n;
	FOR(i,n){
		long long int a;
		cin>>a;
		FOR(j,60){
			if(a&(1LL<<j)){
				count[j][1]++;
			}
			else{
				count[j][0]++;
			}
		}
	}
	long long int ans=0LL;
	FOR(i,60){
		long long int temp=((count[i][0]*count[i][1]%MOD)*((1LL<<i)%MOD))%MOD;
		ans=(ans+temp)%MOD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>

using namespace std;

int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  
  while(true){
    c-=b;
    if(c<=0){
      cout<<"Yes";
      break;
    }
    
    a-=d;
    if(a<=0){
      cout<<"No";
      break;
    }
  }
  
  return 0;
}

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

using namespace std;
#define ll long long


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

	ll ans = 0;

	ll len = s.length();

	for (int i = 0; i < len; ++i)
	{
		if(s[i] == 'p'){
			ans--;
		}
	}

	cout << ans + len/2  << endl;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    int n=log10(b)+1;
    //int m=1;
    for(int i=0;i<n;i++)
         a=a*10;
    a=a+b;
   // printf("%d\n",a);
    double c=sqrt(a);
    int d=sqrt(a);
    if(c==d)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 5010;
LL d[SIZEN];
LL t[SIZEN];
int K,Q;

int num0[SIZEN];
int main(){
    scanf("%d%d",&K,&Q);
    for(int i = 1;i <= K;i++)scanf("%d",&d[i]);
    for(int i = 1;i <= Q;i++){
        LL n,x,m;
        scanf("%lld%lld%lld",&n,&x,&m);
        x %= m;
        for(int j = 1;j <= K;j++){
            t[j] = d[j] % m;
            if(t[j] == 0)num0[j] = 1;
            else num0[j] = 0;
            num0[j] += num0[j-1];
        }
        for(int j = 1;j <= K;j++)t[j] += t[j-1];
        LL num = (n-1) / K;
        
        int rest = (n-1) % K; 
        LL num00 = num0[K] * num + num0[rest];

        LL a = x + num * t[K] + t[rest];

        printf("%lld\n",n-1 - a / m - num00);
    }
    return 0;
}

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

int sum(int n) {
    int sum = 0;
    while (n>0) {
        sum += n %10;
        n /= 10;
    }
    return sum;
}

int main() {
    int n;
    cin >> n;
    if(n%sum(n) == 0){
        cout << "Yes" <<endl;
    }
    else {
        cout << "No" <<endl;
    }
}


Measured memory_bytes: 384
#include <iostream>

int main(){
  int isprime[100001],isprime2[100001];;
  int prime[100001];
  for(int i=2;i<=100000;++i){
    bool f=true;
    for(int j=2;j*j<=i;++j){
      if(i%j==0){
        f=false;
        break;
      }
    }
    if(f)isprime[i]=1;
    //std::cout<<f<<" ";
  }
  for(int i=2;i<100001;++i){
    if(isprime[i] && isprime[(i+1)/2])isprime2[i]=1;
  }
  for(int i=1;i<100001;++i){
    prime[i]=prime[i-1]+isprime2[i];
//    std::cout<<prime[i]<<" ";
  }
  int q;
  std::cin>>q;
  while(q--){
    int l,r;
    std::cin>>l>>r;
    std::cout<<prime[r]-prime[l-1]<<std::endl;
  }//*/
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h> 
#define Re register
#define fo(i, a, b) for (Re int i = (a); i <= (b); ++i)
#define fd(i, a, b) for (Re int i = (a); i >= (b); --i)
#define edge(i, u) for (Re int i = head[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define pb push_back
#define F first
#define S second
#define ll long long
#define inf 1000000007
#define mp std::make_pair
#define lowbit(x) (x & -x)
#define eps 1e-4
#define itset std::set<node>::iterator
#define lb lower_bound
#define N 605
#define M 4000005
#define mod 1000000007
int n, m, k;
int main ()
{
    scanf("%d", &n);
    if (n == 25)
        printf("Christmas");
    else
        if (n == 24)
            printf("Christmas Eve");
        else
            if (n == 23)
                printf("Christmas Eve Eve");
            else
                printf("Christmas Eve Eve Eve");
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main( int argc, char *argv[] ) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c;
	cin >> a >> b >> c;

	cout << c << " " << a << " " << b << "\n";

	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  long long N, M;
  cin >> N >> M;
  
  vector<long long> d0, d1;
  for (int i = 1, j = 0; i * i <= M; i++, j++)
  {
    if (M % i == 0)
    {
      if (i * i != M) d1.insert(d1.begin(), M / i);
      d0.push_back(i);
    }
  }
  
  d0.insert(d0.end(), d1.begin(), d1.end());
  d0.push_back(INF);
  
  long long ans;
  for (int i = 0; i < d0.size(); i++)
  {
    if (d0.at(i) > M / N)
    {
      ans = d0.at(i - 1);
      break;
    }
  }
  
  cout << ans << endl;
}

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

using LL = long long int;

using namespace std;

string S;
LL cMap['z' - 'a' + 1];

int main()
{
  cin >> S;
  for (size_t i = 0; i < S.length(); i++) {
    cMap[S[i] - 'a']++;
  }

  LL ans = (S.length() * (S.length() - 1) / 2) + 1;

  for (size_t i = 0; i < 'z' - 'a' + 1; i++) {
    ans -= cMap[i] * (cMap[i] - 1) / 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int h, w;
    cin >> h >> w;

    int hh, ww;
    cin >> hh >> ww;

    int ans = (h - hh) * (w - ww);
    Cout(ans);

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws Exception {

        ModScanner ms = new ModScanner();
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        int n = ms.nextInt();
        int[] heights = new int[n];
        for (int i = 0; i < n; i++) {
            heights[i] = ms.nextInt();
        }
        int[] dp = new int[n];
        dp[1] = Math.abs(heights[0] - heights[1]);
        for (int i = 2; i < n; i++) {
            dp[i] = Math.min(dp[i - 2] + Math.abs(heights[i - 2] - heights[i]),
                    dp[i - 1] + Math.abs(heights[i - 1] - heights[i]));
        }
        out.println(dp[n - 1]);
        out.close();
    }


}

class ModScanner {

    BufferedReader br;
    StringTokenizer st;

    public ModScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String nextToken() throws Exception {
        while (st == null || !st.hasMoreElements()) {
            st = new StringTokenizer(br.readLine());

        }
        return st.nextToken();
    }

    String nextString() throws Exception {
        return br.readLine();
    }


    int nextInt() throws Exception, Exception {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }

}


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

char s[50][50];

int main(){
	int h, w;
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> s[i][j];
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '#'){
				if(i != 0 && s[i - 1][j] == '#') continue;
				if(i != h - 1 && s[i + 1][j] == '#') continue;
				if(j != 0 && s[i][j - 1] == '#') continue;
				if(j != w - 1 && s[i][j + 1] == '#') continue;
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    long long int N,K;
    cin >>N>>K;

    if(N%2==1 && K%2==1){
        printf("Yes");
    }else{
        printf("No");
    }


    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MOD 1000000007
#define MP make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
lld l,x,y,n,m,i,z,p,s,e,q,j,k,c,d,t,a,b;string s1,s2;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin>>a>>b;
  if((a*b)%2==0)
    cout<<"Even";
  else
    cout<<"Odd";
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-
X=list(input())
A,B,C,D=map(int,X)
if A+B+C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'+'+C+'+'+D+'=7')
  exit()
elif A+B+C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'+'+C+'-'+D+'=7')
  exit()
elif A+B-C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'-'+C+'+'+D+'=7')
  exit()
elif A-B+C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'+'+C+'+'+D+'=7')
  exit()
elif A-B-C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'-'+C+'+'+D+'=7')
  exit()
elif A+B-C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'-'+C+'-'+D+'=7')
  exit()
elif A-B+C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'+'+C+'-'+D+'=7')
  exit()
elif A-B-C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'-'+C+'-'+D+'=7')
  exit()
else:
  print('None')

Measured memory_bytes: 3192
let () =
  Scanf.scanf "%d" @@ fun n ->
  let ts = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let tl = Array.fold_left (+) 0 ts in
  let vs = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in

  let a = Array.make (2*tl+1) 0 in
  Array.fold_left (fun (c,i) t ->
    a.(c) <- min a.(c) vs.(i);
    Array.fill a (c+1) (2*t) vs.(i);
    (c+2*t, i+1)
  ) (0, 0) ts |> ignore;
  a.(2*tl) <- 0;

  let b = Array.map (( * ) 2) a in
  for i = 1 to 2*tl do
    b.(i) <- min b.(i) (b.(i-1) + 1);
  done;
  for i = 2*tl-1 downto 0 do
    b.(i) <- min b.(i) (b.(i+1) + 1);
  done;

  Array.fold_left (+) 0 b
  |> float_of_int
  |> fun z -> Printf.printf "%.10f\n" (z /. 4.0)

Measured memory_bytes: 2816
#include<bits/stdc++.h>
    #include<algorithm>
    using namespace std;
    #define mod 1000000007
    #define FOR(a,c)   for ( long long int (a)=0; (a)<(c); (a)++)
    #define FORL(a,b,c)  for ( long long int (a)=(b); (a)<=(c); (a)++)
    #define FORR(a,b,c)  for (  long long int (a)=(b); (a)>=(c); (a)--)
    #define INF 1000000000000000003
    typedef long long int ll;
    typedef vector<long long int> vi;
    typedef pair<long long int,long long int> pi;
    typedef priority_queue<long long int> max_pq;
    typedef priority_queue<long long int, vector<long long int>, greater<long long int>> min_pq;
    #define F first
    #define S second
    #define PB push_back
    #define POB pop_back
    #define MP make_pair
    #define pi 3.1415926535
    #define buff cin.ignore(numeric_limits<streamsize>::max(),'\n')

    // Use inbuilt function  __gcd(a,b), __builtin_popcount(n), Use (x&-x) for last set Bit;
    
    int main()
    {
        ios::sync_with_stdio(NULL);
        cin.tie(NULL);
        cout.tie(NULL);

        ll n,m;
        cin>>n>>m;
        string mat[n];
        ll arr[n][m];
        for(ll i=0;i<n;i++)
            cin>>mat[i];
        for(ll i=0;i<n;i++)
        {
            for(ll j=0;j<m;j++)
            {
                if(mat[i][j]=='.')
                    arr[i][j]=0;
                else
                    arr[i][j]=1;
            }
        }
        ll dp[n][m];
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        for(ll i=1;i<m;i++)
        {
            if(arr[0][i]==0)
                dp[0][i]=dp[0][i-1];
        }
        for(ll i=1;i<n;i++)
        {
            if(arr[i][0]==0)
                dp[i][0]=dp[i-1][0];
        }
        for(ll i=1;i<n;i++)
        {
            for(ll j=1;j<m;j++)
            {
                if(arr[i][j]==0)
                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
        }
        cout<<(dp[n-1][m-1])%mod<<endl;

        return 0;
    }

Measured memory_bytes: 16896
#include<bits/stdc++.h>
using namespace std;
#define inf 1e4+10
#define LL long long


int main(){
	
	LL n, k;
	cin>>n>>k;
	LL h[n];
	for(LL i=0; i<n; i++) cin>>h[i];

	LL dp[n+1];
	memset(dp, inf, sizeof(dp));
	//dp[i] --> minimum cost incurred to reach i
	

	for(LL i=0; i<=n; i++){
		if(i==0 || i==1) {dp[i]=0; continue;}
		for(LL j=1; j<=k; j++){
			if(i>j){
				dp[i]=min(dp[i], dp[i-j]+llabs(h[i-1]-h[i-j-1]));
			}
		}
	}
	cout<<dp[n];
	return 0;

}

Measured memory_bytes: 1792
import java.util.*;

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

    public void main() {
        Scanner scanner = new Scanner(System.in);
        String[] line = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(line[0]);
        int k = Integer.parseInt(line[1]);

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(scanner.nextLine());
        }
        Arrays.sort(arr);

        int memorySize = 0;
        Integer min = null;
        for (int i = 0; i < n; i++) {
            if (i >= k - 1) {
                int x = arr[i] - arr[i - k + 1];
                if (min == null || x < min) {
                    min = x;
                }
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 94280
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
import numpy as np
#decimal.getcontext().prec = 10

H, W, K = MAP()
s = [input() for _ in range(H)]

ans = [[0]*W for _ in range(H)]

tmp = 1
for y in range(H):
	for x in range(W):
		if s[y][x] == "#":
			ans[y][x] = tmp
			tmp += 1

for y in range(H):
	for x in range(1, W):
		if ans[y][x] == 0 and ans[y][x-1]!= 0:
			ans[y][x] = ans[y][x-1]

for y in range(H):
	for x in range(W-2, -1, -1):
		if ans[y][x] == 0 and ans[y][x+1]!= 0:
			ans[y][x] = ans[y][x+1]

for y in range(1, H):
	for x in range(W):
		if ans[y][x] == 0 and ans[y-1][x]!= 0:
			ans[y][x] = ans[y-1][x]

for y in range(H-2, -1, -1):
	for x in range(W):
		if ans[y][x] == 0 and ans[y+1][x]!= 0:
			ans[y][x] = ans[y+1][x]

for i in range(H):
	print(*ans[i])

Measured memory_bytes: 30640
#include <stdio.h>
 
int main(void)
{
    int n,max=0,p[10000],a=0,x=0,i;
    scanf("%d",&n);
  
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
        if(max<p[i]){
           max=p[i];
           a=i;
        }  
    }
    
    for(i=0;i<n;i++){
        if(i!=a)  x=x+p[i];
    }
    
    printf("%d\n",(max/2)+x);
  
    return 0;
}  

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

main()
{
        int n,k,q; cin>>n>>k>>q;
        vi score(n,k-q);
        rep(i,q)
        {
                int a; cin>>a;
                score[a-1]++;
        }
        each(it,score)
        {
                if(it>0)cout<<"Yes"<<endl;
                else cout<<"No"<<endl;
        }
}


Measured memory_bytes: 1024
K = gets.to_i
Lim = 5 * (10 ** 6)

mod10s = []
for i in 1..Lim do
  if i == 1 then
    mod10s[i-1] = (1 % K)
  else
    mod10s[i-1] = (mod10s[i-2] * 10) % K
  end
end

ans = -1
current_mod = 0
for i in 1..Lim do
  current_mod = (current_mod + mod10s[i-1] * 7) % K
  if current_mod == 0 then
    ans = i
    break
  end
end
  
puts ans

Measured memory_bytes: 53800