akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
long long dp[2001][2001];
int main(void)
{
	int n,k,i,j,kk,a[2000],w,x;
	long long mx;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	scanf("%d",&a[i]);
	for(i=1;i<=n;i++)	dp[1][i]=a[i];
	for(i=2;i<=n;i++)	{
		for(j=0;j<n;j++)	dp[i][j]=-1;
	}
	for(i=1;i<n;i++)	{
		for(j=1;j<=n;j++)	{
			if(dp[i][j]!=-1)	{
				if(i%2==0)	{
					w=j-1;
					if(w<=0)	w=n;
					if(dp[i+1][w]<dp[i][j]+a[w])	dp[i+1][w]=dp[i][j]+a[w];
					x=i+j;
					if(x>n)	x=x-n;
					if(dp[i+1][j]<dp[i][j]+a[x])	dp[i+1][j]=dp[i][j]+a[x];
	//				printf("j=%d i=%d w=%d x=%d\n",j,i,w,x);
				}
				else {
					w=j-1;
					if(w<=0)	w=n;
					x=i+j;
					if(x>n)	x=x-n;
					if(a[w]>a[x])	{
						if(dp[i+1][w]<dp[i][j])	dp[i+1][w]=dp[i][j];
					}
					else {
						if(dp[i+1][j]<dp[i][j]) dp[i+1][j]=dp[i][j];
					}
	//				printf("j=%d i=%d w=%d x=%d\n",j,i,w,x);				
				}
			}
		}
	}

	mx=-1;
	for(i=1;i<=n;i++)	{
		if(mx<dp[n][i])	mx=dp[n][i];
	}
	printf("%lld\n",mx);
	return 0;
}


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

struct Node
{
    int key;
    Node *right, *left, *parent;
};
Node *root, *NIL;
void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL)
    {
        y = x;
        if(z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }
    z->parent = y;
    if(y == NIL)
    {
        root = z;
    }
    else
    {
        if(z->key < y->key)
            y->left = z;
        else
            y->right = z;
    }
}
void inorder(Node *u)
{
    if(u == NIL)   return;
    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
}
void preorder(Node *u)
{
    if(u == NIL)    return;
    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
}
Node *find(Node *x, int k)
{
    while(x != NIL && k != x->key)
    {
        if(k<x->key)
            x = x->left;
        else
            x = x->right;
    }
    return x;
}
Node *getMinimum(Node *x)
{
    while(x->left != NIL)
        x = x->left;
    return x;
}
Node *getSuccessor(Node *x)
{
    if(x->right != NIL)
        return getMinimum(x->right);
    Node *y = x->parent;
    while(y != NIL && x == y->right)
    {
        x = y;
        y = y->parent;
    }
    return y;
}
void treeDelete(Node *z)
{
    Node *x, *y;
    if(z->left == NIL || z->right == NIL)
        y = z;
    else     y = getSuccessor(z);
    if(y->right != NIL)
        x = y->right;
    else
        x = y->left;
    if(x != NIL)
        x->parent = y->parent;
    if(y->parent == NIL)
        root = x;
    else
    {
        if(y == y->parent->left)
            y->parent->left = x;
        else
            y->parent->right = x;
    }
    if(y != z)
        z->key = y->key;
    free(y);
}
int main()
{
    int n, m;
    string s;
    cin >> n;

    while(cin >> s)
    {
        if(s[0] == 'i')
        {
            cin >> m;
            insert(m);
        }
        else if(s[0] == 'p')
        {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
        else if(s[0] == 'f')
        {
            cin >> m;
            if(find(root, m) != NIL)
                cout << "yes" << endl;
            else
                cout << "no" << endl;

        }
        else if(s[0] == 'd')
        {
            cin >> m;
            treeDelete(find(root,m));
        }
    }
    return 0;
}

Measured memory_bytes: 21852
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int H = sc.nextInt();
        final int W = sc.nextInt();
        final int K = sc.nextInt();
        
        final boolean[][] field = new boolean[H][W];
        final int[] hBlacks = new int[H];
        final int[] wBlacks = new int[W];
        
        int blacks = 0;
        for (int i = 0; i < H; i++) {
            String s = sc.next();
            
            for (int j = 0; j < W; j++) {
                if (s.charAt(j) == '#') {
                    field[i][j] = true;
                    hBlacks[i]++;
                    wBlacks[j]++;
                    blacks++;
                }
            }
        }
        
        // 総当たり
        int count = 0;
        for (int h = 0; h < (1 << H); h++) {
            final int hh = h;
            int[] is = IntStream.range(0, H).filter(i -> 0 < (1 << i & hh)).toArray();
            int hPaint = IntStream.of(is).map(i -> hBlacks[i]).sum();
            
            for (int w = 0; w < (1 << W); w++) {
                final int ww = w;
                int[] js = IntStream.range(0, W).filter(j -> 0 < (1 << j & ww)).toArray();
                int wPaint = IntStream.of(js).map(j -> wBlacks[j]).sum();
                
                int hwPaint = 0;
                for (int i : is) {
                    for (int j : js) {
                        if (field[i][j]) {
                            hwPaint++;
                        }
                    }
                }
                if (blacks - hPaint - wPaint + hwPaint == K) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 40244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i < (n); ++i)
#define repD(i, a, n) for(ll i = a; i > (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
// #define mp make_pair
#define pb push_back
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
long long Ceil(long long a, long long b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}
ll p=1000000007;
float E = 0.00000000000001;
ll power(ll x, ll y){
    if(y==0){
        return 1;
    }
    if(y%2==0){
        ll q=power(x,y/2);
        q=q%p;
        return (q*q)%p;
    }
    ll q=power(x,y/2);
    q=q%p;
    return ((x%p)*((q*q)%p))%p; 
}
bool isPowerOfTwo (long long x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}  

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a); 
}
long long int mod(long long int a, long long int b) {
    long long int ret = a%b; return ret>=0? ret: ret+b; 
}
int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        int l,r,d;
        cin>>l>>r>>d;
        int count = 0;
        for(int i = l ; i <= r ; i++)
            if(i%d == 0)
                count++;
        cout<<count<<endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    int a, b, k;
    cin >> a >> b >> k;

    int c[101];
    int count = 0;

    for(int i = 1; i <= min(a, b); i++) {
        if(a % i == 0 && b % i == 0){
            c[count] = i;
            count++;
        }
    }
    int d = count - k;

    cout << c[d] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  ll h, w;
  cin >> h >> w;

  ll ans = (h * w + 1) / 2;
  if (h == 1 || w == 1) ans = 1;

  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<list>
#include<vector>

using namespace std;

list<int> l[31];


int main(){
  int ord,v,i;
  while(1){
    scanf("%d,%d",&ord,&v);
    if(ord==0&&v==0) break;
    l[v].push_back(ord);
  }
  v=1;
  while(scanf("%d",&ord)!=EOF){
    for(i=30,v=1;i>-1;i--){
      list<int>::iterator it=l[i].begin();
      while(it!=l[i].end()){
	if(*it==ord){
	  printf("%d\n",v);
	  goto find;
	}
	it++;
      }
      if(!l[i].empty()) v++;
    }
  find:;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N ,M;
  cin >> N >> M;
  cout << N*M << endl;
  return 0;
}


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

using namespace std;

int a;
int b;
int k;
int jsq;
int res[2005];

int main() {
    scanf("%d%d%d", &a, &b, &k);
    for(int i = 0; i < k && a + i <= b; i++)
        res[++jsq] = a + i, res[++jsq] = b - i;
    sort(res + 1, res + 1 + jsq);
    for(int i = 1; i <= jsq; i++)
        if(res[i] != res[i - 1]) printf("%d\n", res[i]);
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
typedef struct{
    int h,w,d;
}rec;
int cmp_d(const void *a,const void *b){
    rec *c=(rec*)a;
    rec *d=(rec*)b;
    if(c->d==d->d)
        return c->h-d->h;
    return c->d-d->d;
}
int main(void){
    int h,w,i,j,n;
    rec r[300000];
    n=0;
    for(i=1;i<150;i++){
        for(j=i+1;j<150;j++){
            r[n].h=i;
            r[n].w=j;
            r[n].d=sq(i)+sq(j);
            n++;
        }
    }
    qsort(r,n,sizeof(rec),cmp_d);
    while(1){
        h=in();
        w=in();
        if(!h)break;
        rep(i,n){
            if(r[i].h==h&&r[i].w==w){
                print2(r[i+1].h,r[i+1].w);
                break;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2028
S = input()
E = ''
O = ''
for i in range(len(S)):
  if i % 2 == 0:
    E += '1'
    O += '0'
  else:
    E += '0'
    O += '1'
p, q = 0, 0
for i in range(len(S)):
  if E[i] != S[i]:
    p += 1
  if O[i] != S[i]:
    q += 1
print(min(p, q))

Measured memory_bytes: 3316
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << endl;
using LL=long long;
using VI=vector<int>;
using VL=vector<long long>;
using VS=vector<string>;
using VVI=vector<vector<int>>;
using PII=pair<int, int>;
const int inf = (int)1e9;
const LL mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template <class T>void Sort(T & a) { sort(a.begin(), a.end()); }
template <class T>void ReSort(T& a) { sort(a.rbegin(), a.rend()); }
template <class T>void Reverse(T& a) { reverse(a.begin(), a.end()); }
template <class T>void Unique(T& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T>auto Max(T a) { return *max_element(a.begin(), a.end()); }
template <class T>auto Min(T a) { return *min_element(a.begin(), a.end()); }
template <class T, class U>int Count(T a, U c) { return count(a.begin(), a.end(), c); }
template <class T, class U>U Sum(T a, U init = 0) { return accumulate(a.begin(), a.end(), init); }

//INPUT//
void CINPUT() {}
template <class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define Cin(T,...) T __VA_ARGS__; CINPUT(__VA_ARGS__);
#define VecIn(T,name,n) vector<T> name(n); for(auto &i:name)cin>>name[i];

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
template <class T>void out(T n) { cout << n << endl; }
template <class T>void out(vector<T> a, string sep = " ", string end = "\n") { for (int i = 0; i < (int)a.size(); ++i)cout << a[i] << (i == (int)a.size() - 1 ? end : sep); }
template <> void out(double a) { printf("%.20f\n", a); }
void yes(bool f) { puts(f ? "yes" : "no"); }
void Yes(bool f) { puts(f ? "Yes" : "No"); }
void YES(bool f) { puts(f ? "YES" : "NO"); }
void Yay(bool f) { puts(f ? "Yay!" : ":("); }
void poss(bool f) { puts(f ? "possible" : "impossible"); }
void Poss(bool f) { puts(f ? "Possible" : "Impossible"); }
void POSS(bool f) { puts(f ? "POSSIBLE" : "IMPOSSIBLE"); }

int main() {
	Cin(string, s);
	out(700 + Count(s, 'o') * 100);
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	char board[5][5];
	
	for(int i=0;i<2;i++){
		for(int j=0;j<3;j++){
			scanf("%c",&board[i][j]);
		}
		getchar();
	}
	
	if(board[0][0] == board[1][2] && board[1][0] == board[0][2] && board[0][1] == board[1][1]){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	
}

Measured memory_bytes: 888
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws IOException{
      MyReader r = new MyReader();
      int MOD = 1000000007;
      String s = r.s();
      long[][] dp = new long[100005][13];
      int n = s.length();
      dp[0][0] = 1;

      for(int i = 0; i < n; i++){
        int c;
        if(s.charAt(i) == '?')
          c = -1;
        else
          c = s.charAt(i) - '0';

        for(int j = 0; j < 10; j++){
          if(c != -1 && c != j)
            continue;
          for(int ki = 0; ki < 13; ki++)
            dp[i+1][(ki*10+j)%13] += dp[i][ki];
        }
        for(int j = 0; j < 13; j++)
          dp[i+1][j] %= MOD;
      }
      println(dp[n][5]);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


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

int n,l;
int a[209];
int bef;
int sum,ans,lasted=2147483646;
int main() {
	scanf("%d %d",&n,&l);
	for(int i=1; i<=n; i++) {
		a[i]=l+i-1;
		bef+=a[i];
	}
	for(int i=1; i<=n; i++) {
		sum=0;
		for(int j=1; j<=n; j++) {
			if(j==i) continue;
			sum+=a[j];
		}
		if(abs(sum-bef)<lasted) {
			lasted=abs(sum-bef);
			ans=sum;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define INF 0x3f3f3f3f
#define CLR(a) memset(a, 0, sizeof(a))
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	int a[3];
	while(scanf("%d%d%d",&a[0],&a[1],&a[2])!=EOF){
		sort(a,a+3);
		printf("%d\n",a[2]*10+a[1]+a[0]);
	} 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, x, N) for (int i = x; i < (N); i++)
using namespace std;
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB")
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}



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

int main(){

  int n;
  cin>>n;
  int a[n], count=1;
  for(int i=0; i<n; i++) cin>>a[i];

  sort(a, a+n);

  for(int i=0; i<n-1; i++){
    if(a[i]!=a[i+1]) count++;
  }

  cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 3632
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007
#define PI acos(-1)

void Solve()
{
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    int x, y;
    x = max(a*d, b*c);
    y = max(a*c, b*d);
    cout<<max(x, y)<<endl;
    
}
int32_t main()
{
    // int t;
    // cin >> t;
    // while (t--)
    // {
    Solve();
}
//     }
//     return 0;
// }

Measured memory_bytes: 3624
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<string,string> pss;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

int main(){
  itn n; cin >> n;
  string s; cin >> s;
  string t=s.substr(n);
  string u=s.substr(0,n);
  reverse(all(u));
  map<pss,itn> mp;
  rep(bit,(1ll<<n)){
    string red;
    string blue;
    rep(i,n){
      if(bit&(1ll<<i)) red+=t[i];
      else blue+=t[i];
    }
    mp[pss(red,blue)]++;
  }
  ll ans=0;
  rep(bit,(1ll<<n)){
    string red;
    string blue;
    rep(i,n){
      if(bit&(1ll<<i)) red+=u[i];
      else blue+=u[i];
    }
    ans+=mp[pss(blue,red)];
  }
  cout << ans << endl;
}

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

int main()
{
    int N,X; 
    cin >> X >> N;
    vector<int> p(N);
    for(int i=0; i<N; ++i) cin >> p[i];

    bool chk=true;
    for(auto q: p){
        if(q == X) {
            chk = false;
            break;
        }
    }
    if(chk){
        cout<<X<<endl;
        return 0;
    }

    sort(p.begin(),p.end());
    int itr = N;
    for(int i=0; i<N; ++i){
        if(p[i] > X){
            itr = i; break;
        }
    }
    // cout<<p[itr-1]<<" "<<p[itr]<<endl;

    int ans_mi=X-1, dist_mi=1;
    int itr_mi=itr;
    while(itr_mi > 0){
        if(p[itr_mi-1] == ans_mi+1){
            itr_mi--; continue;
        }
        if(p[itr_mi-1] != ans_mi) break;
        ans_mi--; itr_mi--; dist_mi++;
    }
    int ans_pl=X+1, dist_pl=1;
    int itr_pl=itr;
    while(itr_pl < N){
        if(p[itr_pl] == ans_pl-1){
            itr_pl++; continue;
        }
        if(p[itr_pl] != ans_pl) break;
        ans_pl++; itr_pl++; dist_pl++;
    }
    // cout<<dist_mi<<" "<<dist_pl<<endl;
    if(dist_mi <= dist_pl) cout<<ans_mi<<endl;
    else if(dist_mi > dist_pl) cout<<ans_pl<<endl;

    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main() {
    int a[6][20] = {};
    int n, b, d, e;
    char c;
    cin >> n;
    for (b = 1; b <= n; b++) {
        cin >> c >> d;
        if (c == 'S') {
            a[1][d] = 1;
        }
        if (c == 'H') {
            a[2][d] = 1;
        }
        if (c == 'C') {
            a[3][d] = 1;
        }
        if (c == 'D') {
            a[4][d] = 1;
        }
    }
    for (b = 1; b <= 13; b++) {
        if (a[1][b] == 0) {
            cout << "S " << b << endl;
        }
    }
    for (b = 1; b <= 13; b++) {
        if (a[2][b] == 0) {
            cout << "H " << b << endl;
        }
    }
    for (b = 1; b <= 13; b++) {
        if (a[3][b] == 0) {
            cout << "C " << b << endl;
        }
    }
    for (b = 1; b <= 13; b++) {
        if (a[4][b] == 0) {
            cout << "D " << b << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int a,b,c,d; cin >>a >>b >>c >>d;
  bool flag=false;
  if ((abs(b-a)<=d and abs(c-b)<=d) or (abs(c-a)<=d)) flag=true;
  cout <<(flag ? "Yes":"No") <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a, b, c, d;
    scanf("%d %d %d", &a, &b, &c);
    if(a >= b) d = a;
    else d =b;
    if(d <= c) d = c;

    int ans = d*10 + a + b + c -d;
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
long S[100000];
long T[50000];
bool flag[50000];
int n,q;
void binarySearch(long k){
	int lb = -1, ub = q;
	int mid = (ub + lb) / 2;
	while (ub - lb > 1){
		mid = (ub + lb) / 2;
		if (T[mid] > k) ub = mid;
		else lb = mid;
	}
	if (T[lb] == k) flag[lb] = true;
	else if (T[ub] == k) flag[ub] = true;
}

int main(){
	scanf("%d",&n);
	for (int i = 0; i < n; ++i) scanf("%d", &S[i]);
	scanf("%d",&q);
	for (int i = 0; i < q; ++i) scanf("%d",&T[i]);
	sort(T, T + q);
	int cnt = 0;
	for (int i = 0; i < n;++i) binarySearch(S[i]);
	for (int i = 0; i < q; ++i) if (flag[i]) ++cnt;
	cout << cnt << '\n';
}

Measured memory_bytes: 2440
import std.stdio,std.string,std.conv,std.algorithm;

int main()
{
	string s;
	int a[3] = [1,0,0];
	while((s = readln.chomp).length != 0)
	{
		int d = s[0] - 'A';
		int d2 = s[2] - 'A';
		swap(a[d],a[d2]);
	}

	foreach(i;0..3)
	{
		if(a[i] == 1)
		{
			writeln(cast(char)(i + 'A'));
		}
	}
	return 0;
}

Measured memory_bytes: 1044
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=['$']+list(map(int,input().split())) # 1-index
    ans=[0]*(n+1)
    for i in range(n,0,-1): # iを確定させたい
        parity=A[i]
        for j in range(2,n//i+1): # iの倍数のうち、i以外のものを全てみる
            parity+=ans[i*j]
        if(parity%2): ans[i]=1
    s=sum(1 for i in range(1,n+1) if ans[i])
    print(s)
    if(s):
        print(*(i for i in range(1,n+1) if ans[i]))
resolve()

Measured memory_bytes: 80744
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include<stdlib.h>
#include<ctype.h>
#include<limits.h>
#include<map>
#include<limits.h>
#include<ctype.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz size()
#define fast ios_base::sync_with_stdio(false);
#define pq priority_queue
#define mp make_pair
#define mod 1000000007
#define inf 1000000000000000000
using namespace std;
typedef long long ll;
int main()
{
	ll ar[300];
	ll n,i;
	cin>>n;
	n=2*n;
	for(i=0;i<n;i++)
	cin>>ar[i];
	sort(ar,ar+n);
	ll ans=0;
	for(i=0;i<n;i=i+2)
	ans=ans+min(ar[i],ar[i+1]);
	cout<<ans;
  return 0;
}

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

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;

  if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define psi std::pair<string,int>
#define pli std::pair<ll,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%I64d",&x)
#define prll(x) printf("%I64d ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vli std::vector<std::list<int>>
#define vlpi vector<list<pii>>
#define li std::list<int>
#define Endl printf("\n")
#define ma 1000000
#define mod 786433
#define FOR(i,a) for(int i=0; i<a; i++)

using namespace std;

int main() {

   int n , m ;
   cin >>  n >> m ;
   FOR(i,max(m,n)){
       cout<<min(m,n) ;
   }
}


Measured memory_bytes: 256
'use strict';
(function(input){
  input=input.trim().split(/\s+/);
  const N=input[0]-0;
  const K=input[1]-0;
  var ans=input[2].split('');
  if(ans[K-1]==='A')ans[K-1]='a';
  if(ans[K-1]==='B')ans[K-1]='b';
  if(ans[K-1]==='C')ans[K-1]='c';
  ans=ans.join('');
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 21064
#include <iostream>

int main() {
int H, W;
do{
std::cin >> H >> W;
if(!(H == 0 && W == 0)) {
for(int i = 0; i < H; i++) {
for(int j = 0; j < W; j++) {
if(i == 0 || i == H -1 || j == 0 || j == W - 1){
std::cout << '#';
}
else {
std::cout << '.';
}
}
std::cout << std::endl;
}
std::cout << std::endl;
}
} while(!(H == 0 && W == 0));
}

Measured memory_bytes: 2996
#include<iostream>
using namespace std;
int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  while(A >= B) {
    B *= 2;
    K--;
  }
  while(B >= C) {
    C *= 2;
    K--;
  }
  if(K < 0)cout << "No" << endl;
  else cout << "Yes" << endl;
}

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

using namespace std;

int a, b, c, k;
int main() {
    scanf("%d%d%d%d", &a, &b, &c, &k);
    printf("%d", a + b + c - max({a, b, c}) + max({a, b, c}) * (1 << k));
    return 0;
}


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

int main() {
  long N, C;
  cin >> N >> C;
  long X[N], V[N];
  for (int i = 0; i < N; i++) cin >> X[i] >> V[i];
  long v_sum_cw = 0, v_sum_ccw = 0, cw[N], ccw[N], max_cw[N], max_ccw[N];
  for (int i = 0; i < N; i++) {
    v_sum_cw += V[i]; v_sum_ccw += V[N - i - 1];
    cw[i] = v_sum_cw - X[i];
    ccw[N - 1 - i] = v_sum_ccw - (C - X[N - 1 - i]);
    if (i) {
      max_cw[i] = max(max_cw[i-1], cw[i]);
      max_ccw[N - 1 - i] = max(max_ccw[N - i], ccw[N - 1 - i]);
    } else {
      max_cw[i] = cw[i];
      max_ccw[N - 1 - i] = ccw[N - 1 - i];
    }
  }
  long max_nutrition = max(0L, max(max_cw[N - 1], max_ccw[0]));
  for (int i = 0; i < N - 1; i++) {
    max_nutrition = max(max_nutrition, cw[i] - X[i] + max_ccw[i + 1]);
    max_nutrition = max(max_nutrition,
                        ccw[N - 1 - i] - (C - X[N - 1 - i]) + max_cw[N - i - 2]);
  }
  cout << max_nutrition << endl;
}

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

using namespace std;

const int N = 100100;

int a[N];
int Dp[N];

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

    for(int i = 0; i < n; i++)  scanf("%d", a + i);

    for(int i = n - 1; ~i; --i)
    {
        Dp[i] = 0;

        if(i + 1 < n && a[i] >= a[i + 1])   Dp[i] = 1 + Dp[i + 1];
    }

    int Ans = 0;

    for(int i = 0 ; i < n; i++) Ans = max( Ans, Dp[i]);

    cout << Ans << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            WriteLine(Math.Pow(n, 3));
        }
    

    private static string Read() { return ReadLine(); }
    private static string[] Reads() { return (Read().Split()); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }


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

    //最大公約数
    public static int Gcd(int a, int b)
    {
        if (a < b)
        {
            return Gcd(b, a);
        }
        while (b != 0)
        {
            var reminder = a % b;
            a = b;
            b = reminder;
        }
        return a;
    }

    //最小公倍数
    public static int Lcm(int a, int b)
    {
        return a * b / Gcd(a, b);
    }

    //文字数を数える
    public static int CountChar(string s, char c)
    {
        return s.Length - s.Replace(c.ToString(), "").Length;
    }
    public static void debuglist(List<int> x)
    {
        foreach (var item in x)
        {
            WriteLine(item);
        }
    }
    public static void debuglist(List<string> x)
    {
        foreach (var item in x)
        {
            WriteLine(item);
        }
    }
    public static void debugarray(int[] x)
    {
        foreach (var item in x)
        {
            WriteLine(item);
        }
    }
    public static void debugarray(string[] x)
    {
        foreach (var item in x)
        {
            WriteLine(item);
        }
    }
}
}


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

using namespace std;

struct vw_pair {
    int v, w;
    vw_pair(int v,int w) : v(v), w(w) {};
};

typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<int> vi;
typedef vector <string> vs;
typedef vector <vi> vvi;
typedef vector <vector<vw_pair>> adj_list;
typedef vector <bool> vb;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef priority_queue<int> max_heap_int;
typedef priority_queue<int, vi, greater<>> min_heap_int;

#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)
#define modulo(S, N) ((S) & (N-1))   // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S-1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
#define turnOffLastConsecutiveBits(S) ((S) & (S+1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S-1))
#define in_range(lo, hi, x) ((x >= lo && x <= hi))

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

    int n;
    cin >> n;
    cout << n*n*n << "\n";
    
    return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

const ll mod = 1000000007;

struct UnionFind {
public:
	vector <ll> par; // 
	vector <ll> siz; // 

	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}

	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}

	ll size(ll x) {
		return siz[root(x)];
	}
};


int h, w;

int id(int i, int j) {
	return i * w + j;
}

int main(void)
{
	int n, m;
	cin >> n >> m;
	int sum = n * (n - 1) / 2 + m * (m - 1) / 2;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 2e5+5;
vector<ll>v(mx);
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll  n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>v[i];
    ll lb =1,rb =  1e9+7;
    while(lb<rb)
    {
        ll mid = (lb+rb)/2;
        ll ans =0;
        for(int i=0;i<n;i++)
            ans= ans+ (v[i]+mid-1)/mid-1;
        if(ans<=k)
            rb = mid;
        else
        lb= mid+1;

    }
    cout<<rb<<endl;
    return 0;
}



Measured memory_bytes: 4668
#include <stdio.h>

int main( void ){
  int N, ans, l, n, i, v;

  scanf("%d", &N);

  for(l = 0, n = N; n > 0; l++, n/=10);
 
  ans = 0;

  if(l % 2){
    for(i = l - 1, v = 1; i > 0; i--) v *= 10;
    ans += N - v + 1;
  }
  l--;

  for(; l > 0; l--){
    if(l % 2){
      for(i = l - 1, v = 1; i > 0; i--) v *= 10;
      ans += v*10 - v;
    }
  }

  printf("%d\n", ans);

  return 0;
}



Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var a, b string
	fmt.Scan(&a)
	fmt.Scan(&b)

	var cnt int
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			cnt++
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 4496
import numpy as np
dict = {}
N = int(input())
def search(n):
    if n == 1:
        return
    else:
        s = int(np.sqrt(n)//1)
        for i in range(2, s+1):
            if n % i == 0:
                global dict
                dict[i] = dict.get(i, 0) + 1
                search(int(n/i))
                break
        else:
            dict[n] = dict.get(n, 0) + 1
search(N)
ans = 0
for i in dict.keys():
    n = dict[i]
    j = 1
    while n > 0:
        n -= j
        j += 1
        if n >= 0:
            ans += 1
print(ans)


Measured memory_bytes: 27204
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

vector<int> to[200010];
vector<int> ans;

void dfs(int v, int p=-1) {
  for(int u: to[v]) {
    if(u == p) continue;
    ans[u] += ans[v];
    dfs(u, v);
  }
}

int main() {
  int n, q; cin >> n >> q;
  rep(i, n-1) {
    int a, b; cin >> a >> b;
    --a, --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i, q) {
    int p, x; cin >> p >> x;
    p--;
    ans[p] += x;
  }

  dfs(0);

  rep(i, n) {
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 23424
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include<set>


#define rep(i,p,q) for(ll i = p;i < q;++i)
#define ll long long

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll npk(ll n, ll k) {
	ll ret = 1;
	if (n < k || n < 0)return 0;
	rep(i, 0, k) {
		ret *= (n - i);
		ret %= MOD;
	}
	if (ret < 0) ret = 0;
	return ret;
}

//136 E
ll d[2500];

int main(void) {
	ll n, m, p;
	cin >> n >> m >> p;
	vector<vector<pair<ll,ll>>> graph = vector<vector<pair<ll,ll>>>(n, vector<pair<ll,ll>>());
	rep(i, 0, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		graph[a - 1].push_back(make_pair(b - 1, c-p));
	}

	//ここからnまでいける
	vector<ll> reachable_from = vector<ll>(n,0);
	//1からここまでいける
	vector<ll> reachable_to = vector<ll>(n, 0);
	queue<ll> q = queue<ll>();
	q.push(n-1);
	while (q.size() > 0) {
		ll v = q.front();
		q.pop();
		if (reachable_from[v])continue;	
		reachable_from[v] = 1;
		rep(i, 0, n) {
			rep(j, 0, graph[i].size()) {
				ll from = i;
				ll to = graph[i][j].first;
				if (v == to) {
					q.push(from);
				}
			}
		}
	}

	q.push(0);
	while (q.size() > 0) {
		ll v = q.front();
		q.pop();
		if (reachable_to[v])continue;
		reachable_to[v] = 1;
		rep(i, 0, n) {
			rep(j, 0, graph[i].size()) {
				ll from = i;
				ll to = graph[i][j].first;
				if (v == from) {
					q.push(to);
				}
			}
		}
	}

	vector<vector<pair<ll,ll>>> newGraph = vector<vector<pair<ll,ll>>>(n, vector<pair<ll, ll>>());
	rep(i, 0, n) {
		rep(j, 0, graph[i].size()) {
			ll from = i;
			ll to = graph[i][j].first;
			if (reachable_to[from] && reachable_from[to]) {
				newGraph[from].push_back(graph[i][j]);
			}
		}
	}



	const ll INF = 1e12;
	rep(i, 0, 2500)d[i] = -INF;
	d[0] = 0;
	ll loopCount = 0;
	bool isInf = false;
	while (true) {
		loopCount++;
		bool update = false;
		bool vnUpdate = false;
		rep(i, 0, n) {
			for(const auto& pr : newGraph[i]) {
				ll from = i;
				ll to = pr.first;
				ll cost = pr.second;
				if (d[from] != -INF && d[to] < d[from] + cost) {
					d[to] = d[from] + cost;
					update = true;
				}
			}
		}
		if (!update) break;
		else if (loopCount >= 2*n) {
			isInf = true;
			break;
		}
	}
	if (isInf) cout << -1 << endl;
	else if (d[n - 1] < 0) cout << 0 << endl;
	else cout << d[n - 1] << endl;
}

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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int l,r;
        cin >> l >> r;
        int num = r - l + 1;
        ans += num;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque

INF = 10 ** 9

H, W = map(int, input().split())
Ch, Cw = map(lambda x:int(x)-1, input().split())
Dh, Dw = map(lambda x:int(x)-1, input().split())
S = [list(map(lambda x: INF if x == "." else -1, [c for c in input()])) for _ in range(H)]


"""h = []
heapq.heappush(h, (0, Ch, Cw))"""

q = deque()
q.append((0, Ch, Cw))
S[Ch][Cw] = 0

while len(q) != 0:
    d, nh, nw = q.popleft()
    if nh == Dh and nw == Dw:
        print(d)
        exit()

    for dh in [-2, -1, 0, 1, 2]:
        for dw in [-2, -1, 0, 1, 2]:
            flag = False
            if dh == 0 and dw == 0:
                continue
            newd = d + 1
            if abs(dh) + abs(dw) == 1:
                newd = d
                flag = True
            newh = nh + dh
            neww = nw + dw
            if 0 <= newh < H and 0 <= neww < W:
                if S[newh][neww] > newd:
                        S[newh][neww] = newd
                        if flag:
                            q.appendleft((newd, newh, neww))
                        else:
                            q.append((newd, newh, neww))   
print(-1)


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

bool primeOrNot(int x){
  for(int i = 2; i * i <= x; i++){
    if(x % i == 0){
      return false;
    }
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int Q; cin >> Q;
  vector<pair<int, int>> query;
  vector<int> like2017(100001);
  like2017[1] == 0;
  for(int i = 0; i < Q; i++){
    int a, b; cin >> a >> b;
    query.emplace_back(a, b);
  }
  unordered_set<int> primeset;
  primeset.insert(2);
  for(int i = 3; i <= 100000; i+=2){
    like2017[i] = like2017[i-2];
    if(primeOrNot(i)){
      primeset.insert(i);
    }
    if(primeset.count(i) && primeset.count((i + 1) / 2)){
      like2017[i] ++;
    }
 }
  for(int i = 0; i < Q; i++){
    cout << like2017[query[i].second] - like2017[max(query[i].first-2, 0)] <<endl;
  }
}


Measured memory_bytes: 4944
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

l,r,d = map(int,input().split())
for i in range(l,r+1):
  if i%d == 0:
    count += 1
print(count)

Measured memory_bytes: 65232
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a,b;
  char s;
  cin >> a >> s >> b;
  if (s=='+') cout << a+b << endl;
  else cout << a-b << endl;
}


Measured memory_bytes: 256
N=int(input())
Wls=list(map(int,input().split()))

accum_Wls=[0]
for W in Wls:
    accum_Wls.append(accum_Wls[-1]+W)

# print(accum_Wls)

ans=10**9+13

for i in range (1,N):
    temp=abs((accum_Wls[-1]-accum_Wls[i])-accum_Wls[i])
    if temp<ans:
        ans=temp

print(ans)

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<ld> Point;
typedef vector<vector<int>> Graph;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

long modpow(long m, long p) {
    if (p == 0) return 1;
    if (p % 2)
        return m * modpow(m, p - 1) % MOD;
    else {
        long res = modpow(m, p / 2);
        return res * res % MOD;
    }
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    mint ans = 0;
    rep(i, n) cin >> a[i];
    rep(i, 60) {
        ll cnt_zero = 0;
        ll cnt_one = 0;
        rep(j, n) {
            if ((a[j] >> i) & 1)
                cnt_one++;
            else
                cnt_zero++;
        }
        ll temp = (cnt_one * cnt_zero) % MOD;
        temp = temp * ((ll)pow(2, i) % MOD);
        ans += temp;
        // ans += (cnt_one * cnt_zero) * modpow(2, i);
    }
    out(ans.value);
    return 0;
}


Measured memory_bytes: 2560