akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define show(x) cout << #x << " = " << x << "\n"
#define fi first
#define se second

using namespace std;

const int MAX_N = 1000001;

typedef pair<int,int>P;
typedef pair<P,P>PP;

bool is_prime[MAX_N];

void sieve(){
    rep(i,MAX_N){
        is_prime[i] = true;
    }
    is_prime[0] = is_prime[1] = false;
    for(int i=2;i<MAX_N;i++){
        if(is_prime[i]){
            for(int j=2*i;j<MAX_N;j+=i){
                is_prime[j] = false;
            }
        }
    }
}

int pos[1005][1005];
P bue[MAX_N];
const int dx2[3] = {1,1,1};
const int dy2[3] = {-1,0,1};
P dp[1005][1005];
int L=502,R=502;

int main()
{
    sieve();
    pos[L][R] = 1;
    bue[1] = P(L,R);
    int cnt = 1;
    int i = 0, id = 1;
    int nx = L, ny = R;
    while(cnt != MAX_N-1){
        if(i%4 == 0){
            rep(j,i/2+1){
                pos[nx][++ny] = ++id;
                bue[id] = P(nx,ny);
                cnt++;
                if(cnt == MAX_N-1){
                    break;
                }
            }
        }else if(i%4 == 1){
            rep(j,i/2+1){
                pos[--nx][ny] = ++id;
                bue[id] = P(nx,ny);
                cnt++;
                if(cnt == MAX_N-1){
                    break;
                }
            }
        }else if(i%4 == 2){
            rep(j,i/2+1){
                pos[nx][--ny] = ++id;
                bue[id] = P(nx,ny);
                cnt++;
                if(cnt == MAX_N-1){
                    break;
                }
            }
        }else{
            rep(j,i/2+1){
                pos[++nx][ny] = ++id;
                bue[id] = P(nx,ny);
                cnt++;
                if(cnt == MAX_N-1){
                    break;
                }
            }
        }
        i++;
    }
    while(1){
        int n,m;
        cin >> n >> m;
        if(n == 0){
            break;
        }
        rep(i,1005){
            rep(j,1005){
                dp[i][j] = P(-1,-1);
            }
        }
        queue<PP> que;
        que.push(PP(bue[m],P(is_prime[m],is_prime[m]?m:0)));
        dp[bue[m].fi][bue[m].se] = P(is_prime[m],is_prime[m]?m:0);
        P ans = dp[bue[m].fi][bue[m].se];
        while(!que.empty()){
            auto p = que.front();
            que.pop();
            P npos = p.fi, val = p.se;
            if(dp[npos.fi][npos.se] > val) continue;
            rep(i,3){
                int nx = npos.fi+dx2[i], ny = npos.se+dy2[i];
                if(pos[nx][ny] && pos[nx][ny] <= n && dp[nx][ny] < P(val.fi+is_prime[pos[nx][ny]],is_prime[pos[nx][ny]]?pos[nx][ny]:val.se)){
                    dp[nx][ny] = P(val.fi+is_prime[pos[nx][ny]],is_prime[pos[nx][ny]]?pos[nx][ny]:val.se);
                    ans = max(ans,dp[nx][ny]);
                    que.push(PP(P(nx,ny),dp[nx][ny]));
                }
            }
        }
        cout << ans.fi << " " << ans.se << "\n";
    }
}



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

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


const int MOD = 1000000007;
using mint = Fp<MOD>;


int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}
int gyaku(int n){
    return modpow(n,MOD-2);
}

//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap
auto pfactor(int n){
  map<int,int> res;
  int t=sqrt(n);
  for(int i=2;i<=t;i++){
    for(;n%i==0;n/=i)res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
vector<int>kai(0);
void kaizyou(vector<int>&kai){
    rep(i,kai.size()){
        kai[i+1]=kai[i]*(i+1)%MOD;
      }
  }
int comb(int a,int b){
  return (kai[a]*gyaku(kai[a-b]))%MOD*gyaku(kai[b])%MOD;
}
////////////////////////////////////////////////////////////////////////
signed main() {
  int n;
  cin>>n;
  vector<int>a(n);
  int sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  sum/=2;
  for(int i=1;i<=n-2;i+=2){
    sum-=a[i];
  }
  vector<int>ans(n);
  ans[0]=sum*2;
  rep(i,n-1){
    ans[i+1]=(a[i]-ans[i]/2)*2;
  }
  rep(i,n){
    cout<<ans[i]<<' ';
  }
  }


Measured memory_bytes: 4912
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static List<long> list = new List<long>();
    static long N = long.Parse(Console.ReadLine());
    static void Main(string[] args)
    {
        Scanner cin = new Scanner();

        foreach (var x in "357")
        {
            hoge(long.Parse(x.ToString()));
        }

        Console.WriteLine(list.Count(x => x.ToString().ToCharArray().Distinct().Count() == 3));
        Console.ReadLine();
    }

    static void hoge(long x)
    {
        if (x <= N)
        {
            list.Add(x);
            hoge(10 * x + 3);
            hoge(10 * x + 5);
            hoge(10 * x + 7);
        }

    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


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

int main(){
        int q;
        scanf("%d",&q);
        while(q--){
                string str1,str2;
                cin >> str1 >> str2;
                vector<vector<int>> dp(str1.size()+1,vector<int>(str2.size()+1,0));
                for(int i = 0; i < str1.size(); i++){
                        for(int j = 0; j < str2.size(); j++){
                                if(str1[i] == str2[j]){
                                        dp[i+1][j+1] = dp[i][j] + 1;
                                }else{
                                        dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
                                }
                        }
                }
                cout << dp[str1.size()][str2.size()] << endl;
        }
        return 0;
}


Measured memory_bytes: 6972
H,W = map(int,input().split())
A = [list(input()) for i in range(H)]
A_line = ['.'] * W
de_row = []
de_column = []
s = 0
t = 0
ind = 0
for a in A:
    if a == A_line:
        de_column.append(ind)
    ind += 1
for d in de_column:
    del A[d-s]
    s += 1

for i in range(W):
    flag = 0
    for j in range(len(A)):
        if A[j][i] == '.':
            flag += 1
            if flag == len(A):
                de_row.append(i)
            continue
        else:
            break

for d in de_row:
    for i in range(len(A)):
        del A[i][d-t]
    t += 1
for a in A:
    print(''.join(a))


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;

int main(){
  int N;
  cin >> N;
  int a[N];
  int all_sum = 0b0;
  F(i, N){
    cin >> a[i];
    all_sum ^= a[i];
  }
  string result = "Yes";
  if(all_sum != 0b0){
    result = "No";
  }
  cout << result << endl;
  return 0;
}


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

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

    int p[n];

    int abs_min = 110;
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }

    int ans;

    for(int i = 0; i < 100; i++){
        int lrg = x + i;
        int sml = x - i;
        bool ok_s = true;
        bool ok_l = true;

        for(int j = 0; j < n; j++){
            if(sml == p[j])ok_s = false;
            if(lrg == p[j])ok_l = false;
        }
        if(ok_s){
            ans = sml;
            break;
        }
        else if(ok_l){
            ans = lrg;
            break;
        }

    }



    cout << ans << endl;



    return 0;
}

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


using namespace std;

typedef long long ll;

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

ll dp[100100] = { 0 };

int main(void){
	ll n, m;

	cin >> n >> m;


	vector<int> a(m);
	for (int i = 0; i < m; i++){
		cin >> a[i];
	}

	vector<bool> broken(n);
	for (int i = 0; i < n; i++){
		broken[i] = false;
	}
	for (int i = 0; i < m; i++){
		broken[a[i]] = true;
	}


	dp[0] = 1;

	for (int i = 0; i < n; i++){
		if (!broken[i]){
			dp[i + 1] += dp[i];
			dp[i + 2] += dp[i];
			dp[i + 1] %= MOD;
			dp[i + 2] %= MOD;
		}
	}


	cout << dp[n] << endl;
}


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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  
  vector<int> v(n);
  int a;
  for(int i = 0; i < q; i++){
    cin >> a;
    v.at(a - 1)++;
  }
  
  for(int i = 0; i < n; i++){
    if(q - v.at(i) >= k) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	int c[3][3];
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> c[i][j];
		}
	}
	bool can = false;
	if (c[1][0] - c[0][0] == c[1][1] - c[0][1]&&c[1][1]-c[0][1] == c[1][2] - c[0][2]
		&& c[2][0] - c[1][0] == c[2][1] - c[1][1] && c[2][1]-c[1][1] == c[2][2] - c[1][2]
		&& c[0][1] - c[0][0] == c[1][1] - c[1][0] &&c[1][1]-c[1][0] == c[2][1] - c[2][0]
		&& c[0][2] - c[0][1] == c[1][2] - c[1][1] &&c[1][2]-c[1][1] == c[2][2] - c[2][1]) {
		can = true;
	}
	if (can)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
if __name__ == "__main__":
    A, B, C, K = list(map(int, (input().split(' '))))

    if A == B:
        print(0)
        sys.exit()
    if abs(A-B) > pow(10, 18):
        print('Unfair')
        sys.exit()

    plus_flag = 1
    if A < B:
        plus_flag = 0
    if K % 2 == 1:
        if plus_flag == 1:
            plus_flag = 0
        else:
            plus_flag = 1
    if plus_flag == 1:
        print(abs(A-B))
    else:
        print(-abs(A-B))

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] A = in.nextIntArray(N);
            for (int i = 0; i < N; i++) {
                if (A[i] % 2 == 0 && !(A[i] % 3 == 0 || A[i] % 5 == 0)) {
                    out.println("DENIED");
                    return;
                }
            }
            out.println("APPROVED");
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

    }
}



Measured memory_bytes: 23380
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   unik(v)       v.erase(unique(all(v)),v.end())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
void solve()
{
    ll x1,x2,x3,x4,x5;
    cin>>x1>>x2>>x3>>x4>>x5;
    if(x1==0)cout << 1 <<"\n";
    else if(x2==0)cout << 2 <<"\n";
    else if(x3==0)cout << 3 <<"\n";
    else if(x4==0)cout << 4 <<"\n";
    else if(x5==0)cout << 5 <<"\n";
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>

int main()
{
	int i = 1, j = 1;
	for(i = 1;i < 10; i++)
	{
		for(j = 1;j < 10;j++)
		{
			printf("%dx%d=%d\n", i, j, i*j);
		}
	}
	
}


Measured memory_bytes: 2576
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    int mid = 0;
    REP(i,n) {
        REP(j,s[i].length()-1) {
            if (s[i][j] == 'A' && s[i][j+1] == 'B') mid++;
        }
    }

    int ba = 0;
    int xa = 0;
    int bx = 0;
    REP(i,n) {
        if (s[i].front() == 'B' && s[i].back() == 'A') ba++;
        else if (s[i].back() == 'A') xa++;
        else if (s[i].front() == 'B') bx++;
    }

    int ans = 0;
    ans += mid;
    if (ba > 0) {
        ans += (ba-1);
        if (xa > 0) {
            ans++;
            --xa;
        }
        if (bx > 0) {
            ans++;
            --bx;
        }
    }
    ans += min(xa,bx);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;
ll N, W, v[110], w[110];
ll dp[110][100010];
ll f(int pos, int weight){
    if(weight > W) return -1e9;
    if(pos == N) return 0;
    ll &ans = dp[pos][weight];
    if(ans != -1) return ans;
    ans = -1e9;
    ans = max(ans, f(pos + 1, weight + v[pos]) + w[pos]);
    ans = max(ans, f(pos + 1, weight));
    return ans;
}
int main(){
    fast;
    memset(dp, -1, sizeof dp);
    cin >> N >> W;
    for(int i = 0; i < N; i++)
        cin >> v[i] >> w[i];
    cout << f(0, 0) << "\n";
	return 0;
}


Measured memory_bytes: 89592
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, m, q, i, j, k, x, y, xx, yy, ss;
	cin >> n >> m >> q;
	vector<string> s(n);
	for (i = 0; i < n; i++) cin >> s[i];

	vector<vector<int>> v(n + 1, vector<int>(m + 1, 0)), ct = v, c1 = v, c2 = v, v1 = v, v2 = v;

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			if (s[i][j] == '1') v[i][j] = 1;
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m - 1; j++) {
			if (v[i][j] && v[i][j + 1]) v1[i][j] = 1;
		}
	}
	for (i = 0; i < n - 1; i++) {
		for (j = 0; j < m; j++) {
			if (v[i][j] && v[i + 1][j]) v2[i][j] = 1;
		}
	}

	for (i = 1; i <= n; i++) {
		ss = 0;
		for (j = 1; j <= m; j++) {
			ss += v[i - 1][j - 1];
			ct[i][j] = ct[i - 1][j] + ss;
		}
	}

	for (i = 1; i <= n; i++) {
		ss = 0;
		for (j = 1; j <= m; j++) {
			ss += v1[i - 1][j - 1];
			c1[i][j] = c1[i - 1][j] + ss;
		}
	}

	for (i = 1; i <= n; i++) {
		ss = 0;
		for (j = 1; j <= m; j++) {
			ss += v2[i - 1][j - 1];
			c2[i][j] = c2[i - 1][j] + ss;
		}
	}

	while (q--) {
		cin >> x >> y >> xx >> yy;

		int cct = ct[xx][yy] - ct[x - 1][yy] - ct[xx][y - 1] + ct[x - 1][y - 1];
		yy--;
		int cc1 = c1[xx][yy] - c1[x - 1][yy] - c1[xx][y - 1] + c1[x - 1][y - 1];
		yy++; xx--;
		int cc2 = c2[xx][yy] - c2[x - 1][yy] - c2[xx][y - 1] + c2[x - 1][y - 1];

		int ans = cct - cc1 - cc2;
		cout << ans << "\n";
	}



	return 0;
}


Measured memory_bytes: 102272
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

auto GCD(auto a,auto b){ //ユークリッドの互助法で最大公約数
    if (a%b == 0){
        return b;
    }
    else {
        return GCD(b,a%b);
    }
}

auto LCM(auto a,auto b){ //GCDを使って最小公倍数を求める
    auto g = GCD(a,b);
    return (a/g)*b;  // (a*b)/GCD(a,b) なんだけど、こうしないとa,b=INFとかだとはみ出しちゃう
}

int two(int x){
    LL ct = 0;
    while(x % 2 == 0){
        ct++;
        x /= 2;
    }
    return ct;
}

int main(){
    LL N,M;cin >> N >> M;
    vector<LL> a(N);
    rep(i,N)cin >> a[i];

    bool same = true;
    LL tmp = two(a[0]);
    rep(i,N){
        if(tmp != two(a[i]))same = false;
        a[i] /= 2;
    }


    if(same){
        LL lcm = a[0];
        rep(i,N)lcm = LCM(lcm,a[i]);
        LL ans = M/lcm;
        ans = (ans + 2 -1)/2;
        cout << ans << endl;
    }
    else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
    int a[10];
    for(int i=0;i<10;i++)cin>>a[i];
    
    int x=-1,y=-1,z=-1;
    for(int i=0;i<10;i++){
        if(a[i]>x){
            z=y;
            y=x;
            x=a[i];
        }else if(a[i]>y){
            z=y;
            y=a[i];
        }else if(a[i]>z){
            z=a[i];
        }
    }
    cout<<x<<endl<<y<<endl<<z<<endl;
    
    return 0;
}

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

#define ull unsigned long long int
#define ll long long
#define vi vector<int>
#define mii map<int,int>
#define all(x) x.begin(),x.end()
#define endl "\n"
#define pb push_back
#define MOD 1e9+7
#define INF 0x3f3f3f3f

using namespace std;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main()
{
  ll N; cin >> N;
    int ans = 0;
    for(int i= 2;i<= 1000010;i++) {
        int cur = 0;
        while (N % i == 0) {
            cur++;
            N /= i;
        }
    for(int j=1; j<=10000; j++) {
            if (cur < j) break;
            ans++; cur -= j;
        }
    }
    if (N > 1) ans++;
    cout << ans <<endl;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i <= b+1; i++)
        cout << "#";
    cout << endl;
    for (int i = 0; i < a; i++) {
        cout << "#";
        for (int j = 0; j < b; j++) {
            char t;
            cin >> t;
            cout << t;
        }
        cout << "#" << endl;
    }
    for (int i = 0; i <= b+1; i++)
        cout << "#";
    return 0;
}


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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  int N = S.length();
  vector<vector<int>> next(26, vector<int>(N));
  for (int ci = 0; ci < 26; ci++) {
    char c = 'a' + ci;
    int next_c = -1;
    for (int i = 0; i < N; i++) {
      if (S[i] == c) {
        next_c = i;
        break;
      }
    }
    for (int i = N - 1; i >= 0; i--) {
      if (S[i] == c) next_c = i;
      next[ci][i] = next_c;
    }
  }
  long long i = -1;
  for (char c : T) {
    int ci = c - 'a';
    int n = next[ci][(i + 1) % N];
    if (n == -1) {
      cout << -1 << endl;
      return 0;
    }
    int idx = i % N;
    if (idx < 0) {
      idx += N;
    }
    i += n - idx;
    if (n <= idx) {
      i += N;
    }
  }
  i++;
  cout << i << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 11136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long[] a = sc.LongArray();

        a = a.OrderByDescending(num => num).ToArray();

        long answer = 0;

        for (int i = 0; i < n; i++)
        {
            if (i == 0)
            {
                continue;
            }
            answer += a[i / 2];
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 53152
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;

int main(void){
    string S;
    cin >> S;
    long long momentum = 0, mass = 0;;
    for(int i = 0; i < S.length(); i++){
        if(S[i] == 'W'){
            momentum += i;
            mass++;
        }
    }
    cout << momentum - mass * (mass - 1) / 2 << endl;
    return 0;
}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

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

  ll a, b;
  cin >> a >> b;
  rep1(i, 3) {
    if (i != a && i != b) cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 100;
const int MAX_K = 1E+05;

int N, K;

ll A[MAX_N + 1], dp[MAX_N + 1][MAX_K + 1];

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

    cin >> N >> K;

    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    for (int i = 0; i <= N; i++) {
        dp[i][0] = 1;
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= K; j++) {
            dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MOD;
            if (j - 1 >= A[i]) {
                dp[i][j] = (dp[i][j] - dp[i - 1][j - 1 - A[i]] + MOD) % MOD;
            }
        }
    }


    cout << dp[N][K] << "\n";

    return 0;
}

Measured memory_bytes: 81664
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  ll ans = 1;
  REP(i, n) {
    ans *= (i+1);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <map>
#include <set>

using namespace std;

class UF{
public:
    int n;
    vector<int> parent;
    vector<int> size;

    UF(int n){
        parent.resize(n);
        size.resize(n);
        for(int i = 0; i < n; i++){
            parent[i] = i;
            size[i] = 1;
        }
    }

    bool unite(int a, int b){
        int parentA = find(a);
        int parentB = find(b);

        if(parentA == parentB){
            return false;
        }
        else{
            int sizeA = size[parentA];
            int sizeB = size[parentB];
            if(sizeA < sizeB){
                parent[parentA] = parentB;
                size[parentB] += sizeA;
            }
            else{
                parent[parentB] = parentA;
                size[parentA] += sizeB;
            }
            return true;
        }
    }

    int find(int node){
        int p = parent[node];
        if(p == node){
            return p;
        }
        else{
            int newP = find(p);
            parent[node] = newP;
            return newP;
        }
    }
};

int main(){

    int N;
    cin >> N;

    map<int, int> xMap;
    map<int, int> yMap;
    vector<pair<int, int>> xy(N);
    UF uf(N);

    int x, y;
    for(int i = 0; i < N; i++){
        cin >> x >> y;
        xy[i] = make_pair(x, y);

        auto tempX = xMap.find(x);
        if(tempX == xMap.end()){
            xMap[x] = i;
        }
        else{
            uf.unite(i, tempX->second);
        }

        auto tempY = yMap.find(y);
        if(tempY == yMap.end()){
            yMap[y] = i;
        }
        else{
            uf.unite(i, tempY->second);
        }
    }

    vector<set<int>> xSet(N);
    vector<set<int>> ySet(N);

    for(int i = 0; i < N; i++){
        auto tempXY = xy[i];
        int p = uf.find(i);
        xSet[p].insert(tempXY.first);
        ySet[p].insert(tempXY.second);
    }

    long long ans = 0;
    for(int i = 0; i < N; i++){
        if(uf.parent[i] == i){
            ans += ((long long)xSet[i].size() * ySet[i].size() - uf.size[i]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 20608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    ll sum = 0;
    REP(i, 0, n) {
        cin >> a[i];
        sum += a[i];
    }

    auto check = [a, k](ll x) -> bool {
        vector<ll> vec;
        for (ll t : a) {
            t %= x;
            if (t != 0) {
                vec.push_back(t);
            }
        }

        if (vec.size() == 0) {
            return true;
        }
        sort(vec.begin(), vec.end());
        ll r = vec.size() * x - accumulate(vec.begin(), vec.end(), 0LL);
        ll l = 0;
        REP(i, 0, vec.size() - 1) {
            r -= (x - vec[i]);
            l += vec[i];
            if (max(l, r) <= k) {
                return true;
            }
        }
        return false;
    };

    ll ans = 1;
    for (ll i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            if (check(i)) {
                ans = max(ans, i);
            }
            if (check(sum / i)) {
                ans = max(ans, sum / i);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  bool p = false;
  for (int i = 1; i < 10; i++){
    for (int j = 1; j < 10; j++){
      if (i*j==N) p=true;
    }
  }
  if (p){
    cout << "Yes";
  } else {
    cout << "No";
  }
}

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

typedef long long ll;
typedef vector<int> vi;

const double PI=acos(-1.0);

int k,a,b;
void input()
{
    cin>>k>>a>>b;
}

void solve()
{
    bool flag=false;
    for(int i=a;i<=b;++i){
        if(i%k==0) {
            flag=true;
            break;
        }
    }
    if(flag) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

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

typedef long long ll;
const int mod = 1e9 + 7;

int main() {
	int n, m; cin >> n >> m;
	vector<ll>x(n), y(m); for (auto&& xx : x)cin >> xx; for (auto&& xx : y)cin >> xx;
	sort(x.begin(), x.end()); sort(y.begin(), y.end());

	ll a = 0, b = 0;
	for (int i = 0; i < n; i++)a -= x[i] * (n - 1 - i - i);
	for (int i = 0; i < m; i++)b -= y[i] * (m - 1 - i - i);
	cout << (a % mod) * (b % mod) % mod << endl;

	return 0;
}

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

int main(void)
{
    int n;
    double x1, x2, x3, y1, y2, y3;
    cin >> n;
    while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3) {
        double a = 2 * (x1 - x2);
        double b = 2 * (y1 - y2);
        double c = x1*x1 - x2*x2 + y1*y1 - y2*y2;
        double d = 2 * (x1 - x3);
        double e = 2 * (y1 - y3);
        double f = x1*x1 - x3*x3 + y1*y1 - y3*y3;
        double p1 = (e * c - b * f) / (e * a - b * d);
        double p2 = (d * c - a * f) / (d * b - a * e);
        double r = sqrt(pow(x1 - p1, 2) + pow(y1 - p2, 2));
        cout << fixed << std::setprecision(3);
        cout << p1 << " " << p2 << " " << r << endl;;
    }
    return 0;
}





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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    if(a > b) swap(a, b);
    if(b > c) swap(b, c);
    
    int ans = 0;
    if((b-a) % 2){
        b++;
        c++;
        ans++;
    }
    ans += (b-a)/2;
    ans += c-b;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
#define For(i,a,b) for(i=(a),i##end=(b);i<=i##end;++i)
#define Forward(i,a,b) for(i=(a),i##end=(b);i>=i##end;--i)
#define Rep(i,a,b) for(register int i=(a),i##end=(b);i<=i##end;++i)
#define Repe(i,a,b) for(register int i=(a),i##end=(b);i>=i##end;--i)
using namespace std;
template<typename T>inline void read(T &x){
	T s=0,f=1;char k=getchar();
	while(!isdigit(k)&&k^'-')k=getchar();
	if(!isdigit(k)){f=-1;k=getchar();}
	while(isdigit(k)){s=s*10+(k^48);k=getchar();}
	x=s*f;
}
const int MAXN=1e5+7;
static int n,x[MAXN],y[MAXN],t[MAXN];
inline void init()
{
    read(n);
    Rep(i,1,n)read(t[i]),read(x[i]),read(y[i]);
}
inline void solve()
{
    Rep(i,1,n)if(t[i]-t[i-1]<abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
        ||((t[i]-t[i-1])^(x[i]-x[i-1]+y[i]-y[i-1]))&1)
    {puts("No");exit(0);}
    puts("Yes");
}
int main(void){
    init();
    solve();
	return 0;
}


Measured memory_bytes: 1408
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n: usize,
        a: [u64; n],
    }
    let ans = a.into_iter().fold(1u64, |s, a| s.saturating_mul(a));
    if ans > 10u64.pow(18) {
        println!("-1");
    }else{
        println!("{}", ans);
    }
}


Measured memory_bytes: 4656
#include <iostream>
using namespace std;
int main()
{
    char s[3], t[3];
    int ans = 0;
    for(int i = 0; i < 3; i++){
        cin >> s[i];
    }
    for(int i = 0; i < 3; i++){
        cin >> t[i];
    }
    for(int i = 0; i < 3; i++){
        if(s[i] == t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

ll d[2][2] = {{0, 1}, {1, 0}};
ll h, w;
vector<vector<ll>> a, b;
vector<vector<vector<bool>>> dp;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    cin >> h >> w;
    a.resize(h, vector<ll>(w));
    b.resize(h, vector<ll>(w));
    rep(i, h) rep(ii, w) cin >> a[i][ii];
    rep(i, h) rep(ii, w) cin >> b[i][ii];
    dp.resize(h, vector<vector<bool>>(w, vector<bool>((h + w) * 80 + 1, false)));
    dp[0][0][abs(a[0][0] - b[0][0])] = true;
    rep(i, h) {
        rep(ii, w) {
            ll diff = abs(a[i][ii] - b[i][ii]);
            if (i > 0) {
                rep(iii, sz(dp[i - 1][ii])) {
                    if (!dp[i - 1][ii][iii]) continue;
                    dp[i][ii][iii + diff] = true;
                    dp[i][ii][abs(iii - diff)] = true;
                }
            }
            if (ii > 0) {
                rep(iii, sz(dp[i][ii - 1])) {
                    if (!dp[i][ii - 1][iii]) continue;
                    dp[i][ii][iii + diff] = true;
                    dp[i][ii][abs(iii - diff)] = true;
                }
            }
        }
    }
    ll ans = LONG_LONG_MAX;
    rep(i, sz(dp[h - 1][w - 1])) {
        if (dp[h - 1][w - 1][i]) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10880
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,m,r;
    cin>>n>>m>>r;
    int dp[n][n];
    int inf=500000000;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)dp[i][j]=0;
            else dp[i][j]=inf;
        }
    }
    int s[r];
    for(int i=0;i<r;i++){
        cin>>s[i];
    }
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        dp[a][b]=c;
        dp[b][a]=c;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    /*for(int i=0;i<n;i++){
        cout<<endl;
        for(int j=0;j<n;j++){
            cout<<dp[i][j];
        }
    }
    */
    vector<int> v;
    for(int i=0;i<r;i++)v.push_back(s[i]-1);
    int ans=inf;
    sort(v.begin(),v.end());
    do{
        int sm=0;
        for(int i=0;i<r-1;i++){
            sm+=dp[v[i]][v[i+1]];
            //cout<<ans<<endl;
        }
        ans=min(ans,sm);
    }
    while(next_permutation(v.begin(),v.end()));
    cout<<ans<<endl;
}


Measured memory_bytes: 384
sx, sy, tx, ty = map(int, input().split())
ver = ty - sy
hor = tx - sx
go1 = 'U'*ver+"R"*hor
back1 = "D"*ver+"L"*hor
go2 = "D"+"R"*(hor+1)+'U'*(ver+1)+"L"
back2 = "U"+"L"*(hor+1)+"D"*(ver+1)+"R"
print(go1+back1+go2+back2)

Measured memory_bytes: 3060
//
//  AOJ0025.c
//  
//
//  Created by 中野 優 on 2014/02/22.
//
//

#include <stdio.h>
int main(void){
    int count=0,a[4],b[4],ans[100][2],hit,blow,i,j;
    while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=-1) {
        scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
        hit=0,blow=0;
        for(i=0;i<4;i++) {
            if(a[i]==b[i]) hit++;
        }
        ans[count][0]=hit;
        for(i=0;i<4;i++){
            for(j=0;j<4;j++){
                if (b[i]==a[j]) blow++;
            }
        }
        ans[count][1]=blow-hit;
        count++;
    }
    for(i=0;i<count;i++) printf("%d %d\n",ans[i][0],ans[i][1]);
    return 0;
}

Measured memory_bytes: 596
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

// https://atcoder.jp/contests/abc166/tasks/abc166_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();


		String[] array = new String[n];
		for(int i=0;i<n;i++){
			array[i]="hoge";
		}

		for(int i=0;i<k;i++) {
			int d = sc.nextInt();
			for(int j=0;j<d;j++) {
				int flag = sc.nextInt();
				array[flag-1] = "aa";
			}
		}
		sc.close();

		List<String> list = new ArrayList<>(Arrays.asList(array));
		List<String> set = new ArrayList<>();
        Collections.addAll(set, "hoge");
		list.removeAll(set);
		list.size();
		System.out.println(n-list.size());




	}
}


Measured memory_bytes: 37124
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
#define INF 1e15
#define MOD 1000000007
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define END system("PAUSE");return 0
int a, b, k, cnt;
signed main() {
	cin >> a >> b >> k;
	for (int i = 100; i >= 1; i--) {
		if (a%i == 0 && b%i == 0)cnt++;
		if (cnt == k) {
			cout << i << endl;
			END;
		}
	}
	END;
}


Measured memory_bytes: 504
import java.util.Scanner;

public class Main {

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

		String A = sc.next();

		if (A.charAt(2) == A.charAt(3) && A.charAt(4) == A.charAt(5)) {

			System.out.print("Yes");

		} else {
			System.out.print("No");
		}
	}
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    ll sum = 0;
    repf(i, n){
        ll y = floor(1.0*n/i);
        sum += (y+1)*y*i/2;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3760
import itertools
n, m, R = map(int, input().split())
r = list(map(int, input().split()))

d = [[10**10 for j in range(n)] for i in range(n)]
for i in range(m):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1
  d[a][b] = c
  d[b][a] = c

for i in range(n):
  d[i][i] = 0

for k in range(n):
  for i in range(n):
    for j in range(n):
      d[i][j] = min(d[i][k]+d[k][j],d[i][j])

# print (d)
ans = 10**10
for i in itertools.permutations(r):
  x = i
  k = 0
  for j in range(R-1):
    a,b = x[j+1],x[j]
    a -= 1
    b -= 1
    k += d[b][a]
  ans = min(ans,k)
print (ans)

Measured memory_bytes: 47064
#include <stdio.h>
int n,A[50];
int solve(int i, int j);
int main(){
    int q,r,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&r);
        if(solve(0,r)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}
int solve(int i, int j){
if(j==0)return 1;
    if(i>=n)return 0;
    int c=solve(i+1,j) || solve(i+1,j-A[i]);
    return c;
    }


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll memo[100001];
ll findans(ll h[],ll i,ll n,ll k)
{
    if(i==n-1)
    {
        return 0;
    }
    if(i>n-1)
    {
        return 10000000000000000;
    }
    if(memo[i]!=-1)
    {
        return memo[i];
    }
    ll ans=100000000000000;
    for(ll j=1;j<=k;j++)
    {
        ans=min(ans,abs(h[i]-h[i+j])+findans(h,i+j,n,k));
    }
    //ans2=abs(h[i]-h[i+2])+findans(h,i+2,n);
    return memo[i]=ans;
}
int main(){
    // Your code here!
    ll n,k;
    cin>>n>>k;
    ll h[n];
    for(ll i=0;i<n;i++)
    {
        cin>>h[i];
    }
    for(ll i=0;i<=100000;i++)
    {
        memo[i]=-1;
    }
    cout<<findans(h,0,n,k);
    
    
}


Measured memory_bytes: 9600