akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int maxn = 16 + 2;
const int INF = 0x3f3f3f3f;

struct Point {
    int x;
    int y;
};

Point P[maxn];
bool vis[maxn];
int p1[maxn], p2[maxn];
int n, ans;
double slope[maxn];

double get_slope(int a, int b) {
    if (P[a].x == P[b].x)
        return (double)INF;
    return (double)(P[a].y - P[b].y) / (double)(P[a].x - P[b].x);
}

void dfs(int pr, int step) {
    if (pr == n / 2) {
        int k = 0;

        for (int i = 0; i < n / 2; i++) {
            slope[k++] = get_slope(p1[i], p2[i]);
        }

        int cnt = 0;

        for (int i = 0; i < k; i++) {
            for (int j = i + 1; j < k; j++) {
                if (slope[i] == slope[j]) {
                    cnt++;
                }
            }
        }

        if (ans <= cnt)
            ans = cnt;
        return;
    }

    for (int i = step; i < n; i++) {
        if (!vis[i]) {
            vis[i] = true;
            p1[pr] = i;

            for (int j = i + 1; j < n; j++) {
                if (!vis[j]) {
                    vis[j] = true;
                    p2[pr] = j;
                    dfs(pr + 1, i + 1);
                    vis[j] = false;
                }
            }

            vis[i] = false;
            break;
        }
    }
}

int main() {
    while (~scanf("%d", &n)) {
        memset(vis, false, sizeof(vis));
        ans = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d%d", &P[i].x, &P[i].y);
        }
        dfs(0, 0);
        printf("%d\n", ans);
    }
    return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, a[MAX_N], cnt = 0;
    cin >> n;
    REP(i,n)cin >> a[i];
    REP(i,n){
        if(a[i]>i && a[a[i]-1]==i+1)cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

typedef struct _Node {
    int x;
    struct _Node *prev;
    struct _Node *next;
} Node;

Node *head = NULL, *tail = NULL;

/* Print all elements to stdin */
void dump() {
    int hoge = 0;
    Node *p = head;
    while (p != NULL) {
        if (hoge == 0)  printf("%d",  p->x);
        else            printf(" %d", p->x);
        ++hoge;
        p = p->next;
    }
    printf("\n");
}

void insert(int x) {
    Node *nod = malloc(sizeof(Node));;
    nod->x = x;
    nod->prev = NULL;
    nod->next = NULL;

    if (head == NULL) {
        head = nod;
        tail = nod;
    } else {
        nod->next = head;
        head->prev = nod;
        head = nod;
    }
    //dump();

}

void delete(int x) {
    Node *p = head;
    int flg = 0;
    
    while (flg == 0 && p != NULL) {
        //printf("x = %d\n", p->x);
        if (p->x == x) {
            Node *c = p;
            if (c->prev != NULL) {
                p->prev->next = c->next;
            } else {    /* if delete head */
                head = c->next;
            }
            
            if (c->next != NULL) {
                p->next->prev = c->prev;
            } else {    /* if delete tail */
                tail = c->prev;
            }
            flg = 1;
        } else {
            p = p->next;
        }
    }
}

void deleteFirst() {
    if (head == tail) {
        head = NULL;
        tail = NULL;
    } else if (head != NULL) {
        if (head->next != NULL) head->next->prev = NULL;
        head = head->next;
    }
}

void deleteLast() {
    if (head == tail) {
        head = NULL;
        tail = NULL;
    } else if (tail != NULL) {
        if (tail->prev != NULL) tail->prev->next = NULL;
        tail = tail->prev;
    }
}

int main(int argc, char **argv) {

    int n;
    scanf("%d\n", &n);

    int i;
    int x;
    char buf[256];
    char tmp[256];
    for (i = 0; i < n; ++i) {
        fgets(buf, 256, stdin);
        
        if (buf[0] == 'i' || buf[6] == ' ') {
            /* read x */
            sscanf(buf, "%s %d", tmp, &x);

            if (buf[0] == 'i') insert(x);
            else               delete(x);     
        } else if (buf[6] == 'F') {
            deleteFirst();
        } else if (buf[6] == 'L') {
            deleteLast();
        }
    }

    dump();
    
    return 0;
}

Measured memory_bytes: 36044
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>

using namespace std;

int main()
{
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    int cnt = 0;

    int wall = 0;
    for (int i = a-1; i < max(c, d); i++) {
        if (s[i] == '#') {
            cnt++;
        }
        else {
            if (wall < cnt) {
                wall = cnt;
            }
            cnt = 0;
        }
    }
    if (c < d) {
        if (wall < 2) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
        return (0);
    }

    for (int i = b-1; i < d; i++) {
        if (s[i-1] == s[i] && s[i] == s[i+1] && s[i] == '.') {
            cout << "Yes" << endl;
            return (0);
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.lang.Math;

public class Main
{
	public static void main(String[] args)
	{
		Scanner cin = new Scanner(System.in).useDelimiter(",|\\s+");
		
		int d,a,angle;
		double distx,disty;
		
		angle = 90;
		distx = disty = 0;
		
		while(true)
		{
			d = cin.nextInt();
			a = cin.nextInt();

			if(d==0 && a==0) break;
		
			distx += d*Math.cos(Math.toRadians(angle));
			disty += d*Math.sin(Math.toRadians(angle));
			angle = (angle-a+360)%360;
		}
				
		System.out.println((int)distx);
		System.out.println((int)disty);
	}
}

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

int main(){
  int a,b,c,ans;
  cin >> a >> b >> c;
  ans = 0;
  ans = c - (a-b);
  if(ans < 0){
    ans = 0;
  }
  cout << ans << endl;
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
  string s;
  cin >> s;
  vi chara(26, 0);
  for (int i = 0; i < s.size(); i++) {
  	for(int j = 97; j < 123; j++){
    	if(s[i] == (char)(char)j) chara[j-97] +=1; 
    }
  }
  bool ans = true;
  for(int i = 0; i < 26; i++){
  	if(chara[i] == 0) {
    	ans = false;
        cout << (char)(char)(i + 97) << endl;
      break;
    }
  }
  if(ans) cout <<"None" << endl;
}

Measured memory_bytes: 512
#include <iostream>

int calc_sum_of_digits(int x) {
    int ret = 0;
    while (x) {
        ret += x % 10;
        x /= 10;
    }

    return ret;
}

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

    const int sum_of_digits = calc_sum_of_digits(N);
    const auto ret = (N % sum_of_digits == 0) ? "Yes" : "No";

    std::cout << ret << std::endl;
}


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

int main(){

int n;
cin>>n;
int d[n];
int sum=0;
for(int i=0;i<n;i++)
    cin>>d[i];
for(int i=0;i<n;i++)
{
    for(int j=i+1;j<n;j++)
    {

        sum+=d[i]*d[j];
    }

}
cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int count(string& s, int i) {
  unordered_set<char> a, b;
  rep(k, i) { a.insert(s[k]); }
  REP(k, i, s.size()) { b.insert(s[k]); }
  int ret = 0;
  for (auto& x : a) {
    if (b.find(x) != b.end()) ret++;
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  ll a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if (s == u)
    cout << a - 1 << " " << b << endl;
  else
    cout << a << " " << b - 1 << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

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

	int a, b;
	cin >> a >> b;

	cout << a * b << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


signed main(){
    int N, M;
    while(cin >> N >> M, N+M){
        VI C(M), x(N);
        rep(i, 0, M) cin >> C[i];
        rep(i, 0, N) cin >> x[i];
        vector<VI> dp(N+1, VI(300, INF32));
        dp[0][128] = 0;
        rep(i, 0, N) repe(j, 0, 255) rep(k, 0, M){
            int y = j+C[k];
            if(y < 0) y = 0;
            else if(y > 255) y = 255;
            chmin(dp[i+1][y], dp[i][j]+(y-x[i])*(y-x[i]));
        }
        cout << *min_element(begin(dp[N]), end(dp[N])) << endl;
    }

    return 0;
}


Measured memory_bytes: 50608
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    string s;
    cin>>n;
    map<int,ll> ma;
    while(n)
    {
        cin>>s;
        if(s[0]=='A')
        ma[1]++;
        if(s[0]=='W')
        ma[2]++;
        if(s[0]=='T')
        ma[3]++;
        if(s[0]=='R')
        ma[4]++;
        n--;
    }
    cout<<"AC x "<<ma[1]<<endl;
    cout<<"WA x "<<ma[2]<<endl;
    cout<<"TLE x "<<ma[3]<<endl;
    cout<<"RE x "<<ma[4]<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>

void selectionSort(int *A, int N);

int main(void){

  int i;
  int A[100],n;

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

  selectionSort(A, n);

  return 0;
}

void selectionSort(int *A, int N){

  int i,j;
  int minj,tmp,hit;
  int cnt=0;

  for(i=0;i<N;i++){
    minj=i;
    hit=0;
    for(j=i;j<N;j++){
      if(A[j]<A[minj]){
	minj=j;
	hit=1;
      }
    }
  
    tmp=A[i];
    A[i]=A[minj];
    A[minj]=tmp;
    if(hit==1)cnt++;
  }
  for(i=0;i<N-1;i++)
    printf("%d ",A[i]);

  printf("%d\n",A[N-1]);
  printf("%d\n",cnt);
}



Measured memory_bytes: 2064
import math
n = int(input())
k = int(math.log10(n))

a = n // (10 ** k)
b = n % (10 ** k)

if k == 0:
  ans = n
elif n % 10 == 9:
  ans = k * 9 + a
else:
  ans = k * 9 + a -1

print(ans)

Measured memory_bytes: 9228
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
all_temp = []
gap = 100000
for h in H:
    temp = T - h*0.006
    all_temp.append(temp)
All_temp = []
for t in all_temp:
    if t >= A:
        All_temp.append(abs(t-A))
    else:
        All_temp.append(abs(A-t))
near = ['', '']
for i, t in enumerate(All_temp):
    if i == 0:
        near[0] = i
        near[1] = t
    else:
        if abs(t) <= near[1]:
            near[0] = i
            near[1] = t

print(near[0]+1)

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

const int MOD =1000000007;
//

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

    if(n%2){
        cout<<0;
        return 0;

    }
    int ans=0;
    n/=2;
    while(n){
        ans+=n/5;
        n/=5;
    }
    cout<<ans;
    return 0;
}


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

int main(){
    int r,c;
    cin>>r>>c;
    int Hyou[101][101];
    int SumA[101],SumB[101];
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            cin>>Hyou[i][j];
            SumA[i]+=Hyou[i][j];
        }
    }
    for(int j=1;j<=c;j++){
        for(int i=1;i<=r;i++){
        SumB[j]+=Hyou[i][j];
    }
    }
    
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            cout<<Hyou[i][j]<<" ";
            if(j==c)cout<<SumA[i]<<endl;
        }
    }int Sum=0;
    for(int m=1;m<=c;m++){
        cout<<SumB[m]<<" ";
        Sum+=SumB[m];
    }
    cout<<Sum<<endl;
    return 0;
}



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

int main() {
	int n, y;
	bool ans = false;
	cin >> n >> y;
	y/=1000;
  	int a = y;
	if (y > n*10) { ans = false; } else {
		for (int i = 0; a >= 0; i++) {
          	if (i!=0){a = y - 10*i;}
			for (int j = 0; a >= 0; j++) {
				if (n == a+i+j){cout << i << " " << j << " " << a << endl;ans=true;goto exit;}
              	{a -= 5;}
			}
			a = y - 10*i;
		}
	}
  	exit:if (ans) {return 0;}
  	{cout << -1 << " " << -1 << " " << -1 << endl;}
}


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i,n) for(ll i=0; i<(n); i++)
#define forn for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))
#define pb push_back
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}
template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

ll pow5(ll x){
	return x*x*x*x*x;
}

void solve(){
	int x; cin>> x;
	for(int i=-118; i<= 119; i++){
		for(int j=-119; j<=118; j++){
			if(pow5(i)-pow5(j) == x){
				cout << i << " " << j << en; 
				return ;
			}
		}
	}
}

int main(){
	fast;
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
solve();
    return 0;
}

Measured memory_bytes: 3632
import itertools
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


def read_is(n=1):
    return [read_i() for _ in range(n)]


n = int(input())
ls = read_i()
res = 0
for x, y in itertools.combinations(ls, 2):
    res += x * y
print(res)

Measured memory_bytes: 3060
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//ここまで毎回include
//以下プログラム

using namespace std;

int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int result = 0;
	if (a + b > 2 * c) {
		result += min(x, y) * 2 * c;
		if (x > y) {
			x -= y;
			if (a > 2 * c) {
				result += x * 2 * c;
			}
			else {
				result += x * a;
			}
		}
		else if (x < y) {
			y -= x;
			if (b > 2 * c) {
				result += y * 2 * c;
			}
			else {
				result += y * b;
			}
		}
	}
	else {
		result += a * x + b * y;
	}
	cout << result << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    vector<vector<int>> bingo(3, vector<int>(3)); 
    vector<vector<bool>> open(3, vector<bool>(3));
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            int temp = 0;
            cin >> temp;
            bingo[i][j] = temp;
            open[i][j] = false;
        }
    }
    
    int N = 0;
    cin >> N;
    
    for (int n = 0; n < N; ++n) {
        int input = 0;
        cin >> input;
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (bingo[i][j] == input) {
                    open[i][j] = true;
                }
            }
        }
    }
    
    bool isBingo = false;
    if ((open[0][0] && open[0][1] && open[0][2])
        || (open[1][0] && open[1][1] && open[1][2])
        || (open[2][0] && open[2][1] && open[2][2])
        || (open[0][0] && open[1][0] && open[2][0])
        || (open[0][1] && open[1][1] && open[2][1])
        || (open[0][2] && open[1][2] && open[2][2])        
        || (open[0][0] && open[1][1] && open[2][2])
        || (open[2][0] && open[1][1] && open[0][2])) {
        isBingo = true;
    }
    
    if (isBingo) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	char s[101];
	int i,scoreA,scoreB;

	while (1) {
		scanf("%s",s);
		if (s[0] == '0')break;
		scoreA = 0;
		scoreB = 0;
		for (i = 1; s[i] != '\0'; i++) {
			if (s[i] == 'A') scoreA++;
			else scoreB++;
		}
			if (scoreA > scoreB)
				printf("%d %d\n",scoreA+1, scoreB);
			else 
				printf("%d %d\n", scoreA , scoreB+1);
	}
	return 0;
}

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

int main() 
{ 
    int n,k;
    cin>>n>>k;
    vector<int> arr(n);
    vector<int> dp(n);
    for(int i = 0;i<n;i++){
        cin>>arr[i];
    }
    dp[0] = 0;
    for(int i = 1;i<n;i++){
        int curr = INT_MAX;
        for(int j = 1;j<=min(i,k);j++){
            curr = min(curr,dp[i-j] + abs(arr[i] - arr[i-j]));
        }
        dp[i] = curr;
    }
    cout<<dp[n-1];
    return 0; 
} 

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args){
	Scanner scn = new Scanner(System.in);
	int a = scn.nextInt();
      int b = scn.nextInt();
      int c = scn.nextInt();
      int check = 0;
      long x = (long)(5*Math.pow(10,7));
      for(long i=0; i<x; ++i){
        if((a*i) % b == c){
          check =1;
        }
      }
      if(check==0){
        System.out.println("NO");
      }
      if(check==1){
        System.out.println("YES");
      }
	}
}


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

#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

vector<int> vc;
int main()
{
    int n;
    cin >> n;
    vc.resize(n);

    vector<int> p(n);
    vector<int> q(n);
    rep(i, n)
    {
        cin >> p[i];
    }

    rep(i, n)
    {
        cin >> q[i];
    }

    rep(i, n)
    {
        if (i == 0)
        {
            vc[i] = 0;
        }
        else if (i == 1)
        {
            vc[i] = 1;
        }
        else
        {
            vc[i] = vc[i - 1] * i;
        }
    }

    int a, b;
    a = 0;
    b = 0;
    for (int i = 0; i < n; i++)
    {
        int count = 0;
        for (int j = 0; j < i; j++)
        {
            if (p[j] < p[i])
            {
                count++;
            }
        }
        int temp;
        temp = p[i] - 1 - count;
        a += temp * vc[n - i - 1];
    }
    for (int i = 0; i < n; i++)
    {
        int count = 0;
        for (int j = 0; j < i; j++)
        {
            if (q[j] < q[i])
            {
                count++;
            }
        }
        int temp;
        temp = q[i] - 1 - count;
        b += temp * vc[n - i - 1];
    }

    //cout << a << " " << b << endl;

    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
 
int main() {
  int d;
  while (scanf("%d", &d) != EOF) {
    int sum = 0;
    for (int i = 0; i*d < 600; ++i) {
      sum += i*i;
    }
    printf("%d\n", sum*d*d*d);
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

#define rep(i, n) for(int i = 0; i < n; i++)
#define in_arr(type, a, n) for(int i = 0; i < n; i++) scanf(type, &((a)[i]));
#define ll long long int

void merge_sort(int *a, int n){
    if(n < 2) return;
    int mid = n / 2;
    int *left = malloc(sizeof(int) * mid);
    int *right = malloc(sizeof(int) * (n - mid));
    for(int i = 0; i < mid; ++i){
        left[i] = a[i];
    }
    
    for(int i = 0; i < n - mid; ++i){
        right[i] = a[i + mid];
    }
    merge_sort(left, mid);
    merge_sort(right, n - mid);
    for(int i = 0; i < n; ++i){
        printf("%d\t", a[i]);
    }
    printf("\n");
    int li = 0, ri = 0;
    for(int i = 0; i < n; ++i){
        if(li >= mid){
            for(; ri < n - mid; ++ri){
                a[i] = right[ri];
                ++i;
            }
            break;
        }
        
        if(ri >= n - mid){
            for(; li < mid; ++li){
                a[i] = left[li];
                ++i;
            }
            break;
        }
        
        if(left[li] < right[ri]){
            a[i] = left[li];
            li++;
        }else{
            a[i] = right[ri];
            ri++;
        }
    }
    free(left);
    free(right);
}

int main(){
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a * c < b){
        printf("%d\n", c);
    }else {
        printf("%d\n", b / a);
    }
    return 0;
}


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

bool is_kai(string S) {
    int N = S.size();
    bool is_kai = true;
    rep(i, N/2) if (S[i] != S[N-1-i]) is_kai = false;
    return is_kai;
}

int main() {
    string S, ans="Yes";
    cin >> S;

    int N = S.size();
    if (not is_kai(S)) ans = "No";
    if (not is_kai(S.substr(0, (N-1)/2))) ans = "No";
    if (not is_kai(S.substr((N+3)/2-1, N - (N+3)/2+1))) ans = "No";

    cout << ans << endl;    

    return 0;
}

 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)

#define pause cout << " press ansy key to continue...",  cin >> chh
#define file_r(x) freopen(x,  "r",  stdin)
#define file_w(x) freopen(x,  "w",  stdout)
#define lowbit(x) ((x) & (-x))
#define repit(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, u) for (int i = head[u]; i != -1; i = nxt[i])
#define repd(i, n) for (int i = (n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define FORD(i, n, m) for (int i = (n); i >= (m); i--)
#define pb push_back
#define X first
#define Y second
#define ins insert
#define rb rbegin
#define be begin
#define er erase
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define sqr(r) ((LL) (r) * (r))
#define dis(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define FASTIO ios::sync_with_stdio(false);cin.tie(0)

#define sc(x) cout << #x" = " << x << endl, system("pause")
#define sc2(x, y) cout << #x" = " << x << " " << #y" = " << y << endl, system("pause")
#define sc3(x, y, z) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << endl, system("pause")
#define sc4(x, y, z, w) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << " " << #w" = " << w << endl, system("pause")

#define in(n) scanf("%d", &n)
#define in2(n, m) scanf("%d %d", &n, &m)
#define in3(x, y, z) scanf("%d %d %d", &x, &y, &z)

using namespace std;
int chh;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<int, pii> pi3;
typedef vector< pair<int, int> > vpii;
typedef long long LL;

const int N = 100005;

int n, m;
int a[N];
map<int, int> q;

bool gao() {
    if (m == 1) return a[0] == 0;
    if (m == 2) return a[0] == 0 && q[0] * 3 == n;
    if (m == 3) return q[a[0]] == q[a[1]] && q[a[1]] == q[a[2]] && ((a[0] ^ a[1]) == a[2]);
    return 0;
}

bool ok() {
    if (a[n - 1] == 0) return 1;
    if (n % 3) return 0;
    int m = n / 3;
    if (a[0] == a[m - 1] && a[m] == a[2 * m - 1] && a[2 * m] == a[3 * m - 1] && ((a[0] ^ a[m]) == a[2 * m])) return 1;
    return 0;
}

int main() {
    while (~in(n)) {
        q.clear();
        rep (i, n) in(a[i]), q[a[i]]++;
        sort(a, a + n);
        m = unique(a, a + n) - a;
        puts(gao() ? "Yes" : "No");
    }
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
using namespace std;
int main() {
    int a,b,c,d,start,end,time = 0;
    cin >> a >> b >> c >> d;
    if (a > c){
        start = a;
    } else {
        start = c;
    }
    if (b > d){
        end = d;
    } else {
        end = b;
    }
    time = end - start;
    if (time < 0){
        time = 0;
    }
    cout << time;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)
using namespace std;
using namespace __gnu_pbds;
void OJ();

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;

const int N = 2e5 + 9;
int a[N];

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

    int n; cin >> n;
    for ( int i = 1; i < n; ++i ){
        int x; cin >> x; a[x]++;
    }

    for ( int i = 1; i <= n; ++i )
        cout << a[i] << "\n";
    return 0;
}

void OJ(){
#ifndef ONLINE_JUDGE
    freopen( "C:\\Users\\ehab\\Desktop\\Code Forces\\CF\\in.txt" , "r" , stdin  );
   // freopen( "C:\\Users\\ehab\\Desktop\\Code Forces\\CF\\out.txt", "w" , stdout );
#endif // ONLINE_JUDGE
}
ll binEXP( ll x , ll pw , ll MOD )
{ ll res=1; while(pw>0){ pw%2 ? res *= x : 0; x *= x; x%=MOD; pw /= 2; res%= MOD; } return res%=MOD; }


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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

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

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long N, std::vector<long long> h) {
    vi dp(N, inf);
    dp[0] = 0;
    rep(i, N) {
        int n1 = i + 1;
        int n2 = i + 2;
        if (n1 < N) chmin(dp[n1], dp[i] + abs(h[i] - h[n1]));
        if (n2 < N) chmin(dp[n2], dp[i] + abs(h[i] - h[n2]));
    }

    cout << dp.back() << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    std::vector<long long> h(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &h[i]);
    }
    solve(N, std::move(h));
    return 0;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    ll d, t, s ;
    cin >> d >> t >> s ;

    if ((t * s) >= d) {
        cout << "Yes\n" ;
    }
    else {
        cout << "No\n" ;
    }

    return 0 ;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(A * B, C * D) << endl;
    return 0;
}


Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           node(a,b,c)                 mp(mp(a,b),c)
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=200005;
int a[M],b[M],n;
 main()

{
    fast
    cin>>n;
    f(i,1,n)cin>>a[i];
    f(i,1,n)cin>>b[i];
    reverse(b+1,b+n+1);
    int mil=-1;
    f(i,1,n)
    {
        if(a[i]==b[i])
        {
            mil=a[i];
            break;
        }
    }
    int lft=0,rgt=-1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==mil && b[i]==mil)
        {
            lft=i;
            break;
        }
    }
    for(int i=n;i>=1;i--)
    {
        if(a[i]==mil && b[i]==mil)
        {
            rgt=i;
            break;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]!=mil && b[i]!=mil && lft<=rgt)
        {
            swap(b[i],b[lft]);
            lft++;
        }
    }
    if(lft<=rgt)
    {
        cout<<"No\n";return 0;
    }
    cout<<"Yes\n";
    f(i,1,n)
    {
        cout<<b[i]<<" ";
    }
    cout<<"\n";
    return 0;

}





































Measured memory_bytes: 6744
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
using namespace std;
int main()
{
	int n;
	int x,sum=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		sum+=x;
	}
	if(sum%2==0)cout<<"YES";
	else cout<<"NO";
	return 0;
}

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

vector<int> shi;
int constexpr X = 1e8;

void go(int num, int s, int f, int t) {
    if(!s && !f && !t) shi.push_back(num);
    if(num % X != num) return ;
    go(10 * num + 7, max(0, s - 1), f, t);
    go(10 * num + 5, s, max(0, f - 1), t);
    go(10 * num + 3, s, f, max(0, t - 1));
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    go(0, 1, 1, 1);
    sort(begin(shi), end(shi));
    cout << upper_bound(begin(shi), end(shi), n) - begin(shi) << endl;
}

Measured memory_bytes: 512
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):  # リストに重複した要素があるか判定（要素にリストがある場合）
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


#a, b, c, d = map(int, input().split())
#print(a, b, c, d)
#x = ((a-c)**2+(b-d)**2)**0.5
# print(x)
n = int(input())
# print(divisor(n))

cnt = 0
for i in range(1, n+1):
    # print(divisor(i))
    # print(len(divisor(i)))
    if i % 2 != 0 and len(divisor(i)) == 8:
        cnt += 1
print(cnt)


Measured memory_bytes: 3832
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <cstdlib>
typedef long long int ll;
using namespace std;

static long gcd(long a, long b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

long long int facctorialMethod(int k){//階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

long long int tousasum(long long int n){//等差数列
    return n*(n+1)/2;
}

unsigned GetDigit(unsigned num){//桁数
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

bool IsPrime(int num)//素数判定
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

map< ll, ll > prime_factor(ll n) {//素因数分解
    map< ll, ll > ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

ll calcNumOfCombination(ll n, ll r){
    ll num = 1;
    for(ll i = 1; i <= r; i++){
        num = num * (n - i + 1) / i;
    }
    return num;
}



int main() {
    ll X;
    cin >> X;
    for(ll i=1;i<=X;i++){
        if(i*(i+1)/2>=X){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;
ll dp[111][111111];
vector<ll> v(111);
ll mod=1e9+7;


int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
   ll n,k;cin>>n>>k;
   for(int i=1;i<=n;i++)cin>>v[i];
   dp[0][0]=1;
   for(int i=1;i<=n;i++){
       vector<ll> sum(k+1);
       sum[0]=dp[i-1][0];
       for(int j=1;j<=k;j++)sum[j]=sum[j-1]+dp[i-1][j],sum[j]%=mod;
       for(int j=0;j<=k;j++){
           ll mi=j-v[i];
           if(mi-1>=0)dp[i][j]=sum[j]-sum[mi-1];
           else dp[i][j]=sum[j];
           dp[i][j]%=mod;
           if(dp[i][j]<0)dp[i][j]+=mod;
       }
   }
   
    cout<<dp[n][k];
}

Measured memory_bytes: 88188
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  vector<string> st = {"AC", "WA", "TLE", "RE"};
  map<string, int> mp;
  rep(i, 4) {
    mp[st[i]] = 0;
  }
  int n;
  cin >> n;
  rep(i,n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  rep(i, 4) {
    cout << st[i] << " x " << mp[st[i]] << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
def main():
    N = int(input())
    SP_list = [list(list(input().split())) for i in range(N)]

    # N = 6
    # SP_list = [['khabarovsk', '20'], ['moscow', '10'], ['kazan', '50'], ['kazan', '35'], ['moscow', '60'], ['khabarovsk', '40']]

    for i, line in enumerate(SP_list):
        line[1] = -int(line[1])
        line.append(str(i + 1))
    SP_list.sort(key=lambda x: (x[1], x[2]))
    SP_list.reverse()
    SP_list.sort()

    for line in SP_list:
        print(line[2])
    pass


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

template <typename T>
struct BellmanFord {
  struct edge {
    int u, v;
    T w;
    edge() {}
    edge(int u, int v, T w) : u(u), v(v), w(w) {}
  };

  int n;
  vector<vector<int> > G;
  vector<int> used, reach;
  BellmanFord(int n) : n(n), G(n), used(n, 0), reach(n, 0) {}

  vector<edge> es;
  void add_edge(int u, int v, T c) {
    es.emplace_back(u, v, c);
    G[u].emplace_back(v);
  }

  void dfs(int v) {
    if (used[v]) return;
    used[v] = 1;
    for (int u : G[v]) dfs(u);
  }

  T build(int from, int to, int &neg_loop) {
    for (int i = 0; i < n; i++) {
      fill(used.begin(), used.end(), 0);
      dfs(i);
      reach[i] = used[to];
    }
    const T INF = numeric_limits<T>::max();
    vector<T> ds(n, INF);
    ds[from] = 0;
    for (int j = 0; j < n; j++) {
      bool update = 0;
      for (auto e : es) {
        if (!reach[e.u] || !reach[e.v] || ds[e.u] == INF) continue;
        if (ds[e.v] > ds[e.u] + e.w) {
          ds[e.v] = ds[e.u] + e.w;
          update = 1;
        }
      }
      if (!update) break;
      if (j == n - 1) {
        neg_loop = 1;
        return INF;
      }
    }
    neg_loop = 0;
    return ds[to];
  }
};

int main() {
  //
  ll n, m, p;
  cin >> n >> m >> p;
  vl a(m), b(m), c(m);
  BellmanFord<ll> bf(n);
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    bf.add_edge(a[i], b[i], p - c[i]);
  }
  int neg;
  ll res = bf.build(0, n - 1, neg);

  if (neg) {
    cout << -1 << endl;
    return 0;
  }
  cout << max(0LL, -res) << endl;

  return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)

#include <string>
#include <vector>
#include <algorithm>
int main(){
    int n,k,q; cin >> n >> k >> q;
    if(k>q) {
        rep(i,n) cout << "Yes" << endl;
        return 0;
    }
    vector<int> succes(n+1);
    int num;
    rep(i,q){
        cin >> num;
        succes[num]++;
    }
    int ans = 0;
    rep(i,n){
        if(k-q+succes[i+1]<=0){
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
}

Measured memory_bytes: 3656
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let v = read_vec::<usize>();
    let flip = v[0] > v[1];
    let (a,b) = if flip { (v[1],v[0]) } else { (v[0],v[1]) };
    let grid = solve(a,b);
    print_ans(grid,flip);
}

fn solve(a: usize, b: usize) -> Vec<Vec<i32>> {
    let mut grid = vec![vec![0;100];100];
    let mut x = a-1;
    let mut y = b;
    let mut h = 3;
    while x > 0 && y > 0 && h < 97 {
        for i in h..h+3 {
            for j in 0..100 {
                grid[i][j] = 1;
            }
        }
        h += 6;
        x -= 1;
        y -= 1;
    }

    'forx: for i in 0..10 {
        for j in 0..50 {
            if x == 0 {break 'forx;}
            grid[6*i+4][2*j] = 0;
            x -= 1;
        }
    }

    'fory: for i in 0..10 {
        for j in 0..50 {
            if y == 0 {break 'fory;}
            grid[6*i+1][2*j] = 1;
            y -= 1;
        }
    }
    grid
}

fn print_ans(grid: Vec<Vec<i32>>, flip: bool) {
    println!("{} {}",100,100);
    for l in grid {
        for c in l {
            print!("{}",if (c==0) ^ flip { '.' } else { '#' });
        }
        println!("")
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
bool prime[10001];

void make_prime()
{
  memset(prime,true,sizeof(prime));
  prime[0]=false;
  prime[1]=false;
  for(int i=2;i<10001;i++)
    {
      if(prime[i])
	for(int j=i+i;j<10001;j+=i)
	  prime[j]=false;
    }
}

int main()
{
  int n;
  make_prime();
  for(;cin>>n;)
    {
      int cnt=0;
      //      cout<<"ceil "<<(int)((n/2.0)+0.5)<<endl;
      for(int i=2;i<=(int)((n/2.0)+0.5);i++)
	{
	  //	  cout<<i<<" "<<n-i+1<<endl;
	  if(prime[i]&&prime[n-i+1])
	    {
	      cnt+=2;
	      if(i==n-i+1)
		cnt--;
	    }
	}
      cout<<cnt<<endl;

    }
}

Measured memory_bytes: 1176
#include<stdio.h>
#include<stdbool.h>
#define N 8
#define FREE -1
#define NOTFREE 1
 
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
void initialize(void);
int printBoard(void);
int recursive(int);
 
bool X[N][N];
 
int main(){
  int i,j,k,r,c;
  
  initialize();
 
  for(i = 0; i < N; i++)
    for(j = 0; j < N; j++)
      X[i][j] = false;
 
  scanf("%d",&k);
  for(i = 0; i < k; i++){
    scanf("%d%d",&r,&c);
    X[r][c] = true;
  }
 
  recursive(0);
 
  return 0;
   
}
 
void initialize(){
  int i;
  for(i = 0; i < N; i++){
    row[i] = FREE;
    col[i] = FREE;
  }
 
  for(i = 0; i < 2*N-1; i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}
 
int printBoard(){
  int i,j;
 
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(X[i][j]){
    if(row[i] != j) return 0;
      }
    }
  }
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
 
int recursive(int i){
  int j;
  if(i == N){
    printBoard();
    return 0;
  }
  for(j = 0; j < N; j++){
 
    if(NOTFREE == col[j] || NOTFREE == dpos[i+j] || NOTFREE == dneg[i-j+N-1]) continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOTFREE;
 
    recursive(i+1);
 
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

Measured memory_bytes: 572
# -*- coding: utf-8 -*-
def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    h_dict = {}
    for i in range(len(h)):
        h_dict[i+1] = h[i]
    out = []
    for k in range(m):
        a, b = map(int, input().split())
        ha = h_dict[a]
        hb = h_dict[b]
        if ha > hb:
            out.append(b)
        elif ha < hb:
            out.append(a)
        else:
            out.append(a)
            out.append(b)
    out = set(out)
    print(n - len(out))
if __name__ == '__main__':
    main()

Measured memory_bytes: 27724
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll int,ll int>
#define PI 2*acos(0)
//#define mx 100005
#define INF 1e16
using namespace std;
const ll int p=1000000007;
//vector<ll > prime;
//bool mark[mx];
ll int mod(ll int a,ll int b)
{
    ll int m=a%b;
    if(m<0) m=(b<0)?(m-b):(m+b);
    return m;
}
ll maxpow(ll n)
{
    return (n & (~(n-1)));
}
bool isPrime(ll n)
{
    if(n<2) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(ll i=3;i*i<=n;i+=2){
        if(n%i==0) return false;
    }
    return true;
}
/*void init()
{
    mark[1]=1;
    int i,j,limit=sqrt(mx*1.0)+2;
    prime.push_back(2);
    for(i=4;i<mx;i+=2) mark[i]=1;
    mark[2]=0;
    for(i=3;i<mx;i+=2){
        if(!mark[i]){
            prime.push_back(i);
            if(i<=limit){
                for(j=i*i;j<mx;j+=2*i){
                    mark[j]=1;
                }
            }
        }
    }
}*/
/*
ll maxdiv(ll n)
{
    ll i,ans=1;
    for(i=0;i<prime.size();i++){
        if(n%prime[i]==0){
            ans=n/prime[i];break;
            //return ans;
        }
    }
    return ans;
}*/
ll lcm(ll a,ll b)
{
    ll ans=a*b;
    return (ans/__gcd(a,b));
}
// ax+by and a>b
ll gcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll d=gcd(b,mod(a,b),x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return d;
}
ll abso(ll a)
{
    if(a>=0) return a;
    return -a;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //ll mx=100005;
    //cout<<mx<<"\n";
    ll i,j,n,x;
    cin>>n>>x;
    ll w[n+1],v[n+1];
    ll V=0;
    for(i=1;i<=n;i++){ cin>>w[i]>>v[i]; V+=v[i]; }
    // dp[i] denotes the minimum total weight of items with total value exactly i;considering each item only once
    ll dp[V+1];
    for(i=1;i<=V;i++) dp[i]=INF;
    dp[0]=0;
    for(i=1;i<=n;i++){
        // considering the i th item ,as we are going from left to right ,we are considering each item only once
        for(j=V;j>=v[i];j--){
            // if this was an increasing loop then this program will make the mistake of using one item more than once
            // every element can be used only once ,therefore the loop is a decreasing loop
            // now we will see if taking the current item will effect any value
            // any value that can be updated can range from v[i] to V , so we will consider all the possibilities
            // before updating dp[j],let's think for a while , we have already updated the list upto (i-1) th item
            // either the j th value will change or it won't
            // we have two options , either we can take the i'th element (1) or not (2)
            // (1) the j th state will remain unchanged
            // (2) or it will be changed by dp[j-v[i]]+w[i]
            dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
            //cout<<"i="<<i<<" j="<<j<<" "<<dp[j]<<"\n";
        }
    }
    for(i=V;i>=0;i--){
        if(dp[i]<=x){
            cout<<i;
            return 0;
        }
    }
    return 0;
}
//1028C


Measured memory_bytes: 4420