akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    int B[N-1];REP(i,N-1) cin >> B[i];
    if(N == 2){
        cout << B[0]*2 << endl;
    }
    else{
        int sum = 0;
        REP(i,N-2){
            sum += min(B[i],B[i+1]);
        }
        cout << sum + B[0] + B[N-2] << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		
		// 入力受取
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		// 積を求める
		int by = a * b;
		
		// 偶奇判定
		if(by % 2 == 0) {
			System.out.println("Even");
		} else {
			System.out.println("Odd");
		}
		
	}
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node Node;
Node* NIL;

Node *root;

/*Node* treeSearch(Node *u, int k){
  if((u->left== NIL)&&(u->right==NIL)){
    return NIL;
  }
  else{
    if(k < u->key){
      treeSearch(u->left,k);
    }
    else if (k > u->key){
      treeSearch(u->right,k);
    }
    else {
      return u;
    }
  }
}
*/

Node* treeSearch(Node *u, int k){
  Node *T;
  T=root;
  while((T!=NIL)&&(T->key!=k)){
    if(k<T->key) T=T->left;
    else T=T->right;
  }
  return T;
}

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);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

Node * getminimum(Node *n){
  while(n->left!=NULL)n=n->left;
  return n;
}

Node * getsuccessor(Node *z){
  Node* y;

  if(z->right!=NULL)return getminimum(z->right);
  y=z->parent;
  while(z!=NULL&&z==y->right){
    z=y;
    y=y->parent;
  }
  return y;
}

void delete(Node* z){
  Node *x,*y;
  if((z->left!=NULL)&&(z->right!=NULL))y=getsuccessor(z);
  else y=z;

  if(y->left!=NULL)x=y->left;
  else x=y->right;

  if(x!=NULL)x->parent=y->parent;

  if(y->parent==NULL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;

  if(y!=z)z->key=y->key;

}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node* t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }

    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }

    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }

    else if(com[0]=='d'){
      scanf("%d",&x);
      delete(treeSearch(root,x));
    }

  }

  return 0;
}



Measured memory_bytes: 20488
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,count=0,r;
    cin>>n;
    if(n>=100&&n<=999)
    {
    	stat:
    	if(n>0)
        {
        	r=n%10;
        	{
    	    	if(r==7)
    		    cout<<"Yes";
    		    else
    		    {
    	         n=n/10;
     		     goto stat;
	    	    }
	    	}
    	}
    	else
    	cout<<"No";
    }
}

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

int n;
ll *a, **dp;

ll recur(int i, int j) {
	if(i == j) return a[i];
	if(dp[i][j]) return dp[i][j];
	return dp[i][j] =  max(a[i] - recur(i+1, j), a[j] - recur(i, j-1));
}

int main() {
	cin >> n;
	
	a = new ll[n];
	dp = new ll*[n];
	for(int i = 0; i < n; i++) dp[i] = new ll[n]; 
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) dp[i][j] = 0;
	
	for(int i = 0; i < n; i++) cin >> a[i];
	
	cout << recur(0, n-1);
	
	return 0;
}

Measured memory_bytes: 72704
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A,B,K;
  cin>>A>>B>>K;
  FOR(i,A,min(A+K, B+1))cout<<i<<endl;
  FOR(i,max(B-K+1,A+K),B+1)cout<<i<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>


using namespace std;
#define INF 100100100100

#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;
typedef pair<ll, ll> PI;

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

    if((1 <= a) && (a <= 9) && (1 <= b) && (b <= 9)) {
        cout << a*b << endl; 
    } else {
        cout << -1 << endl;
    }
    return 0;
}



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

int prime[50001];

int main(){
  int n;
  int cnt;
  for(int i=2;i<=STA/2;i++){
    for(int j=2;i*j<=STA;j++){
      prime[i*j] = 1;
    }
  }
  while(1){
    cnt = 0;
    cin >> n;
    if(n == 0) break;
    for(int i=2;i<=n/2;i++){
	if(prime[i] == 0 && prime[n-i] == 0) cnt++;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1356
#include <random>    //ランダム
#include <algorithm> //アルゴリズム
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <fstream>
#include <cmath>
#include <cstring>
#include <string>
#include <sstream>
#include <cassert>
#include <cfloat>
#include <numeric>
#include <climits>
#include <stdint.h>
using namespace std;
// vector<int> temple(7,0);
    // for(int i=0; i<temple.size(); i++){
    
    // }
    // int maxtemp=*max_element(temple.begin(), temple.end());;
    // int mintemp=*min_element(temple.begin(), temple.end());;
    // int answer=0;
    // for(int i=0; i<temple.size(); i++){
    //     if(temple[i]==maxtemp||temple[i]==mintemp){
            
    //     }else{
    //         answer+=temple[i];
    //     }
    // }
    // answer/=5;
    // cout << answer << std::endl;
int main()
{
    string N;
    cin >> N;
    int answer=0;
    int counter=0;
    char bef='a';
    for(unsigned int i=0; i<N.size(); i++){
        if(N[i]=='R'&&counter==0){
            counter++;
        }
        if(N[i]=='R'&&bef=='R'){
            counter++;
        }
        if(N[i]=='S'){
            if(answer<counter){
            answer=counter;
            }
            counter=0;
        }
        bef=N[i];
    }
    if(answer<counter){
        answer=counter;
    }
    cout<<answer<<endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <list>
#include <set>
#include <map>
#include <thread>
#include <mutex>

#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std;

using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

bool exor(bool a, bool b) {
    if ((a && b) or (!a && !b)) {
        return false;
    } else {
        return true;
    }
}

int main() {
    string tmp;
    int Q;
    cin >> tmp >> Q;

    list<char> S;
    rep(i, 0, tmp.size()) { S.push_back(tmp[i]); }

    bool forward = true;
    rep(i, 0, Q) {
        int t;
        cin >> t;

        if (t == 1) {
            forward = !forward;
        } else {
            int f;
            char c;
            cin >> f >> c;

            if (exor(f == 1, forward)) {
                S.push_back(c);
            } else {
                S.push_front(c);
            }
        }
    }

    if (forward) {
        for(auto itr = S.begin(); itr != S.end(); ++itr) {
            cout << *itr;
        }
    } else {
        for(auto itr = S.rbegin(); itr != S.rend(); ++itr) {
            cout << *itr;
        }
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 9984
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		System.out.println(Main.calc(s.nextInt())?"Yes":"No");
	}

	public static boolean calc(int x) {
		return x%Main.calcKeta(x)==0;
	}

	public static int calcKeta(int n) {
		return (n == 0) ? 0 : n % 10 + Main.calcKeta(n / 10);
	}
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
using namespace std;
#define NMAX 100000

// 入力
int N, M;
int dp[NMAX];        // メモ化再帰
vector<int> G[NMAX]; // グラフ
// vector<vector<int>> G; // グラフ

inline int rec(int v) {
    if (dp[v] != 0)
        return dp[v]; // 既に更新済み

    int res = 0;
    for (auto nv : G[v]) {
        res = max(res, rec(nv) + 1);
    }
    return dp[v] = res; // メモしながらリターン
}

int main() {
    // 入力受け取り
    cin >> N >> M;
    // G.assign(N, vector<int>());
    for (int i = 0; i < M; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y; // 0-indexed にする
        G[x].push_back(y);
    }

    // 全ノードを一通り更新しながら答えを求める
    int res = 0;
    for (int v = 0; v < N; ++v) {
        res = max(res, rec(v));
    }
    cout << res << endl;
}

Measured memory_bytes: 7552
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>

using namespace std;
typedef long long ll;

ll n = 0, x = 0, num = 0;
ll counter[100000000] = {};

int main() {
	for (int i = 1;; i++) {
		cin >> n >> x;
		if (n == 0 && x == 0) {
			num = i - 1;
			break;
		}
		else {
			for (int j = 1; j <= n - 2; j++) {
				for (int k = j + 1; k <= n - 1; k++) {
					for (int l = k + 1; l <= n; l++) {
						if (j + k + l == x)counter[i]++;
					}
				}
			}
		}
	}
	for (int i = 1; i <= num; i++) {
		cout << counter[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  ll l,r,ans=2020;cin>>l>>r;

  if(r-l>=2018){
    cout<<0<<endl;
  }else{
    for(int i=l;i < r;i++)
    {
      for(int j=i+1;j <= r;j++)
      {
        if(ans > (i%2019)* (j%2019)%2019) ans=(i%2019)*(j%2019)%2019;
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
n = int(input())

a = list(map(int,input().split()))
a.sort()
if n % 2 == 0:
    b = 0
    for i in range(0,n,2):
        if a[i] != a[i+1] and a[i] != i+1:
            b = 1
    if b == 1:
        print(0)
    else:
        print((2**(n//2))%1000000007)
else:
    b = 0
    if a[0] != 0:
        b = 1
    else:
        for i in range(1,n,2):
            if a[i] != a[i+1] and a[i] != i+1:
                b = 1
    if b == 1:
        print(0)
    else:
        print((2**(n//2))%1000000007)

Measured memory_bytes: 14008
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         int N=gi();
         int[] a=new int[N];
         boolean[] b=new boolean[1000001];
         Map<Integer,Integer> m=new HashMap<Integer,Integer>();

         for(int i=0; i<N;i++) {
        	 a[i]=gi();
        	 if(m.containsKey(a[i])) {
        		 m.put(a[i], m.get(a[i])+1);
        	 } else {
        		 m.put(a[i], 1);
        	 }
         }

         Arrays.parallelSort(a);

         int ans=0;
         for(int i=0; i<N;i++) {
             int v=a[i];
             if(m.get(v)==1 && b[v]==false) ans++;
             for(int j=v*2; j<=1000000; j+=v) {
            	 b[j]=true;
             }
             i+=m.get(v)-1;
         }

         System.out.println(ans);
     }

  // 素因数分解
 	public static List<Long> insuB(long n) {
 		List<Long> l=new ArrayList<Long>();
 		long tmp=n;
 		for(long i=2; i<=Math.sqrt(n); i++) {
 			while(tmp%i==0) {
 				tmp=tmp/i;
 				l.add(i);
 			}
 		}
 		if(tmp!=1) l.add(tmp);

 		return l;
 	}

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 75688
#include <bits/stdc++.h>
using namespace std;
const char same = 'o';
const char diff = 'x';

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    // 1 : 羊, -1 : 狼, 0 : 未定
    auto judge = [&](int a, int b, int c)->bool {
        vector<int> v(n, 0);
        v[0] = a; v[1] = b; v[2] = c;
        for (int i = 2; i < n-1; i++) {
            if (v[i] == 1) {
                if (s[i] == same) v[i+1] = v[i-1];
                else v[i+1] = -v[i-1];
            } else {
                if (s[i] == same) v[i+1] = -v[i-1];
                else v[i+1] = v[i-1];
            }
        }
        for (int i = 0; i < n; i++) {
            int l = i-1, r = i+1;
            if (l < 0) l = n-1;
            if (n <= r) r = 0;
            if (v[i] == 1) {
                if (s[i] == same && v[l] != v[r]) return false;
                else if (s[i] == diff && v[l] == v[r]) return false;
            } else {
                if (s[i] == same && v[l] == v[r]) return false;
                else if (s[i] == diff && v[l] != v[r]) return false;
            }
        }
        return true;
    };
    
    string ans = "-1";
    auto make_ans = [&](int a, int b, int c)->string {
        vector<int> v(n, 0);
        v[0] = a; v[1] = b; v[2] = c;
        for (int i = 2; i < n-1; i++) {
            if (v[i] == 1) {
                if (s[i] == same) v[i+1] = v[i-1];
                else v[i+1] = -v[i-1];
            } else {
                if (s[i] == same) v[i+1] = -v[i-1];
                else v[i+1] = v[i-1];
            }
        }
        string ret = "";
        for (int i = 0; i < n; i++) {
            if (v[i] == 1) ret = ret + "S";
            else ret = ret + "W";
        }
        return ret;
    };
    
    for (int bit = 0; bit < (1<<3); bit++) {
        int m[3];
        for (int i = 0; i < 3; i++) {
            if (bit&(1<<i)) m[i] = 1;
            else m[i] = -1;
        }
        if (judge(m[0], m[1], m[2])) {
            ans = make_ans(m[0], m[1], m[2]);
            break;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1144
#include <iostream>
using namespace std;
int n, K, A[300005];
int main() {
	cin >> K >> n;
	if (!(K & 1)) {
		cout << (K >> 1);
		for (int i = 1; i < n; ++i) cout << ' ' << K;
	} else {
		for (int i = 1; i <= n; ++i) A[i] = K + 1 >> 1;
		int len = n;
		for (int i = 0; i < (n >> 1); ++i) {
			if (A[len] == 1) --len;
			else {
				--A[len];
				for (int j = len + 1; j <= n; ++j) A[j] = K;
				len = n;
			}
		}
		for (int i = 1; i <= len; ++i) cout << A[i] << ' ';
	}
	return 0;
}

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

int n, k, h[100000], ta = 1000000000;

int main(){
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	sort(h, h + n);
	for (int i = 0; i <= n - k; i++) {
		if (ta > h[i + k - 1] - h[i]) {
			ta = h[i + k - 1] - h[i];
		}
	}
	cout << ta << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
using ll = long long;

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


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

const int INF = 9999999;
const int MAXN = 112345;

int n;
int h[MAXN];
int pd[MAXN];


int rec(int cur)
{
	if(cur==(n-1))
		return 0;

	if(cur>=n)
		return INF;

	if(pd[cur]!=-1)
		return pd[cur];

	return pd[cur] = min(abs(h[cur+1]-h[cur])+rec(cur+1),abs(h[cur+2]-h[cur])+rec(cur+2));
}

int main(){
	memset(pd, -1 , sizeof(pd));

	cin >> n;

	for(int i=0; i<n; i++)
		cin >> h[i];

	cout << rec(0) << endl;

	return 0;
}

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

using namespace std;

int next_strawberry_row(vector<string> & s, int h_prev=-1){
  for(int h = h_prev + 1; h < s.size(); h++){
    for(int w = 0; w < s[h].size(); w++){
      if(s[h][w] == '#'){
	return h;
      }
    }
  }
  return s.size();
}

int main(){
  int H, W, K;
  cin >> H >> W >> K;

  vector<string> s(H);
  for(int h = 0; h < H; h++){
    cin >> s[h];
  }

  int first_strawberry_row = next_strawberry_row(s, -1);
  // cout << first_strawberry_row <<endl;
  int idx = 1;
  vector<vector<int>> ans(H, vector<int>(W));
  for(int h = first_strawberry_row, next_h = next_strawberry_row(s, h);
      h < H;
      h = next_h, next_h = next_strawberry_row(s, next_h), idx++){
    int strawberry_cnt = 0;
    for(int w = 0; w < W; w++){
      if(s[h][w] == '#'){
	strawberry_cnt++;
	if(strawberry_cnt > 1){
	  idx++;
	}
      }
      for(int h_ = h; h_ < next_h; h_++){
	ans[h_][w] = idx;
      }
    }
  }
  for(int w = 0; w < W; w++){
    for(int h = 0; h < first_strawberry_row; h++){
      ans[h][w] = ans[first_strawberry_row][w];
    }
  }

  for(int h = 0; h < H; h++){
    for(int w = 0; w < W; w++){
      if(w){
	cout << ' ';
      }
      cout << ans[h][w];
    }
    cout << endl;
  }
}



Measured memory_bytes: 1280
#include <stdio.h>

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

     scanf("%d %d %d %d %d\n",&W,&H,&x,&y,&r);
if(x - r < 0 || x + r > W || y - r < 0 || y + r > H)
    puts("No");
else
    puts("Yes");

   return 0;
}


Measured memory_bytes: 1976
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    ll k; 
    cin >> k;
    int one = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '1') 
            one++;
        else break;
    }
    if (k <= one) cout << 1 << '\n';
    else cout << s[one] << '\n';
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    int sum = 0;
    rep(i, N) {
        if((i+1)%3 && (i+1)%5) sum += i+1;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    long a,b,c,k;
    std::cin >> a >> b >> c >> k;
    long result;
    if(k % 2 == 0){
        result = a - b;
    } else {
        result = b - a;
    }
    std::cout << result << std::endl;
}


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

using namespace std;

typedef long long ll;
const int mod = 1000000007;

ll num[100100];
ll dp[110][100100];
ll sdp[100100];

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

    int iter = 0;
    for (int i = 1; i <= n;) {
        int j = n / i;
        if (i <= j) num[iter++] = 1, i++;
        else num[iter++] = n/j - i + 1, i = n/j + 1;
    }

    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;

    for (int i = 0; i < k; i++) {
        memset(sdp, 0, sizeof(sdp));
        for (int j = 1; j <= iter; j++) {
            sdp[j] = sdp[j-1] + dp[i][j-1];
            sdp[j] %= mod;
        }
        for (int j = 0; j < iter; j++) {
            dp[i+1][j] = sdp[iter-j] * num[j];
            dp[i+1][j] %= mod;
        }
    }

    ll ans = 0;
    for (int j = 0; j < iter; j++) {
        ans += dp[k][j];
        ans %= mod;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 87552
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int factrial(int n) {
	if (n == 1)
		return 1;
	else
		return factrial(n - 1);
}

int main(int argc, char *argv[])
{
    int n, i, pattern_num;
	cin >> n;
	vector< pair<int, int> > town(n);
	vector<int> perm(n);
    int count = 0;
	double sum = 0;
	
	for (i = 0; i < n; i++) {
		cin >> town[i].first >> town[i].second;
		perm[i] = i;
	}

	do {
		for (i = 0; i < n - 1; i++) {
			sum += sqrt( (town[perm[i]].first - town[perm[i + 1]].first) *
						 (town[perm[i]].first - town[perm[i + 1]].first) +
						 (town[perm[i]].second - town[perm[i + 1]].second) *
						 (town[perm[i]].second - town[perm[i + 1]].second) );
		}
			
		count++;
	} while (next_permutation(perm.begin(), perm.end()));

	cout << fixed << setprecision(12) << sum / count << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const ll MAX = 510000;
const ll MOD = 1000000007;


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


int main(){
  ll N,M;cin>>N>>M;
  string s,t;cin>>s>>t;

  ll c = gcd(N,M);
  ll ans = N*M/c;
  ll tmp = ans/c;

  for(ll i = 0; i < ans; i += tmp){
    if(s[i/(M/c)] != t[i/(N/c)]){
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 512
def ABC073D():
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    ABC = [list(map(int, input().split())) for i in range(M)]
    root = [[1000000000 for i in range(N)] for j in range(N)]
    for i, j, k in ABC:
        root[i - 1][j - 1] = k
        root[j - 1][i - 1] = k

    import itertools
    def kumiawase(list_name):  # list_name(リスト)のすべての並び替え
        return itertools.permutations(list_name)


    from scipy.sparse import csgraph
    root = csgraph.floyd_warshall(root)

    a = kumiawase(r)
    ans = float("inf")
    for i in a:
        key = 0
        for j in range(len(i) - 1):
            key += root[i[j] - 1][i[j + 1] - 1]
        if ans > key:
            ans = int(key)
    #print(root)
    print(ans)
ABC073D()

Measured memory_bytes: 32264
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll const MOD=1000000007;

string s;

int main(){
    cin>>s;

    string t,u;
    rep(i,s.size()){
        if(s[i]!='x'){
            t+=s[i];
            u+=s[i];
        }
    }
    reverse(u.begin(),u.end());
    if(t!=u){
        cout<<-1<<endl;
        return 0;
    }

    int l=0, r=s.size()-1;
    int ans=0;
    while(l<r){
        if(s[l]==s[r]){
            l++;
            r--;
        }else{
            if(s[l]=='x'){
                while(s[l++]=='x') ans++;
                r--;
            }else if(s[r]=='x'){
                while(s[r--]=='x') ans++;
                l++;
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3972
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * @Author: Tard1grad3                                                         *
 * @Last modified time: Sunday, September 20th 2020, 08:17:31 pm (UTC+06:00)   *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include <bits/stdc++.h>
using namespace std;
#define IC ios_base::sync_with_stdio(false); cin.tie(NULL);
#define f(i, a, b) for(int i=a; i<b; i++)
#define ff(i, a, b) for(int i=a-1; i>=b; i--)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mp make_pair
#define sz 25
#define mod 998244353
#define line "\n"
#define ALL(x) x.begin(), x.end()
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef map<char, int> mci;
const double PI = acos(-1);

// int a[sz];
string s;
// si st;
// vector<string> vs;
// vector<char> vc;
// mci mm;

void solve()
{
    ll k, n, m=0, cnt=0, flg=0, ans=0, pos=0, sum=0, mx=INT_MIN, mn=INT_MAX;
    cin >> s;
    f(i, 0, s.size()) sum+=(s[i]-'0');
    int val= stoi(s, nullptr);
    val%sum? cout << "No": cout << "Yes";
}

int main()
{
    int T=1, k=1;
    // cin >> T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 3572
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！

def main():
    n,m,*a=map(int,open(0).read().split())
    dp=[0]*(n+1)
    a=set(a)
    dp[0]=1
    mod=10**9+7
#    dp[1]=dp[0]%mod
    for i in range(1,n+1):
        if i in a:
            continue
        else:
            dp[i]=(dp[i-1]+dp[i-2])%mod
    print(dp[n]%mod)
#    print(dp)
if __name__ == '__main__':
    main()

Measured memory_bytes: 85548
#include <iostream>
#include <algorithm>
#include <functional>
 
using namespace std;
typedef pair<int, int> P;
const int MAXN = 1e5+10;
const int INF = 1e5+10;
 
int n, m;
P a[MAXN];
 
void solve() {
  sort(a, a + m, greater<P>());
  int cnt = 0;
  int cur = INF;
  for (int i=0;i<m;i++) {
    if (a[i].second <= cur) {
      cnt++;
      cur = a[i].first;
    }
  }
  cout << cnt << endl;
}
 
int main() {
  cin >> n >> m;
  for (int i=0;i<m;i++) {
    cin >> a[i].first >> a[i].second;
  }
  solve();
}
    

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

using namespace std;

int main() {
    int n; cin >> n;
    int a[n], b[n], c[n - 1];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n - 1; i++) cin >> c[i];
    int res = 0;
    for (int i = 0; i < n; i++) {
        res += b[a[i] - 1];
        if (i > 0) {
            if (a[i] == a[i - 1] + 1) {
                res += c[a[i - 1] - 1];
            }
        }
    }
    cout << res;
}

Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
      n: usize,
      ss: [chars; n],
    }
    let mut c = vec![0; 5];
    for i in 0..n {
        match ss[i][0] {
            'M' => c[0] += 1,
            'A' => c[1] += 1,
            'R' => c[2] += 1,
            'C' => c[3] += 1,
            'H' => c[4] += 1,
            _ => continue,
        }
    }

    let uc = c.iter().filter(|&&v| v >= 1).count() as u64;
    if uc < 3 {
        println!("{}", 0);
        return
    }
    let mut ans: u64 = 0;
    for i in 0..5 {
        for j in i+1..5 {
            for k in j+1..5 {
                ans += c[i] * c[j] * c[k];
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 12540
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <algorithm>

constexpr size_t NMAX = 1000;


using Cell = int64_t[8][3];

Cell table[NMAX + 1][NMAX + 1];

int64_t eval_mode(int mode, int64_t xs[3])
{
    int64_t sum = 0;
    for (int64_t i = 0; i < 3; i++) {
        if (mode & (1 << i)) {
            sum += xs[i];
        } else {
            sum -= xs[i];
        }
    }
    return sum;
}

int main()
{
    int n, m;
    std::cin >> n >> m;

    for (int i = 1; i <= n; i++) {
        int64_t ev[3];
        std::cin >> ev[0] >> ev[1] >> ev[2];

        for (int j = 0; j <= i; j++) {
            auto &cell = table[i][j];
            if (j == 0) {
                for (int mode = 0; mode < 8; mode++)  {
                    for (int k = 0; k < 3; k++) {
                        cell[mode][k] = 0;
                    }
                }
            } else if (j == i) {
                for (int mode = 0; mode < 8; mode++) {
                    for (int k = 0; k < 3; k++) {
                        cell[mode][k] = table[i-1][j-1][mode][k] + ev[k];
                    }
                }
            } else {
                for (int mode = 0; mode < 8; mode++) {
                    int64_t use[3], no_use[3];
                    for (int k = 0; k < 3; k++) {
                        no_use[k] = table[i-1][j][mode][k];
                        use[k] = table[i-1][j-1][mode][k] + ev[k];
                    }
                    int64_t use_eval = eval_mode(mode, use);
                    int64_t no_use_eval = eval_mode(mode, no_use);
                    int64_t *larger = (use_eval < no_use_eval) ? no_use : use;
                    for (int k = 0; k < 3; k++) {
                        cell[mode][k] = larger[k];
                    }
                }

            }
        }
    }

    const auto &cell = table[n][m];
    int64_t max_ev =0;
    for (int mode = 0; mode < 8; mode++) {
        int64_t ev = 0;
        ev += std::abs(cell[mode][0]);
        ev += std::abs(cell[mode][1]);
        ev += std::abs(cell[mode][2]);
        max_ev = std::max(max_ev, ev);
    }

    std::cout << max_ev << std::endl;
    return 0;
}


Measured memory_bytes: 186112
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int dp[101][8];

int main(){
	int h, w, z; cin >> h >> w >> z; --z;
	if( w == 1 ){
		cout << 1 << endl;
		return 0;
	}
	dp[0][0] = 1;
	vector<int> weise;
	for( int k = 0; k < (1<<(w-1)); ++k ){
		bool ok = true;
		for( int i = 0; i < w-2; ++i ){
			if( ( k & (1<<i) ) && ( k & (1<<(i+1)) ) ){
				ok = false;
				break;
			}
		}
		if( ok ) weise.push_back(k);
	}
	for( int r = 0; r < h; ++r ){
		for( auto scaffold : weise ){
			for( int c = 0; c < w; ++c ){
				if( c <= w-2 && scaffold & (1<<c) ){
					dp[r+1][c] += dp[r][c+1];
					dp[r+1][c] %= MOD;
					dp[r+1][c+1] += dp[r][c];
					dp[r+1][c+1] %= MOD;
					++c;
				} else {
					dp[r+1][c] += dp[r][c];
					dp[r+1][c] %= MOD;
				}
			}
		}
	}
	cout << dp[h][z] % MOD << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<sstream>

struct person{
	int num;
	struct person *prev;
	struct person *next;
};

struct person *head,*p,*now;
int m,n;
char s[128];

void set(){
	for(int i=0; i<m; i++){
		p[i].num = i+1;
		p[i].prev = p+i-1;
		p[i].next = p+i+1;
	}
	p[0].prev = p+m-1;
	p[m-1].next = p;
}

void del(struct person *a){
		(a->prev)->next = a->next;
		(a->next)->prev = a->prev;
		if(a == head)
			head = a->next;
}

void show(struct person *a){
	std::cout << a->num;
	if(a->next == head)
		return;
	else{
		std::cout << ' ';
		show(a->next);
	}
}

int main(){
	while(true){
		std::cin >> m >> n;
		if(!m && !n)
			return 0;
		p = new struct person[m];
		head = p;
		now = head;
		set();
		for(int i=0; i<n; i++){
			std::cin >> s;
			if(now == now->next){
				continue;
			}else if((i+1)%15 == 0){
				if(strcmp(s,"FizzBuzz") != 0)
					del(now);
			}else if((i+1)%3 == 0){
				if(strcmp(s,"Fizz") != 0)
					del(now);
			}else if((i+1)%5 == 0){
				if(strcmp(s,"Buzz") != 0)
					del(now);
			}else{
				std::string str(s);
				std::istringstream ss(str);
				int a = 0;
				ss >> a;
				if(a != i+1)
					del(now);
			}
			now = now->next;
		}
		show(head);
		std::cout << std::endl;
		delete[] p;
	}
}

Measured memory_bytes: 936
n=int(input())
hoge=list(map(int,input().split()))
huga=[0]*(10**5+1)
for i in hoge:
  if(i==10**5):
    huga[i-1]+=1
    huga[i]+=1
  elif(i==0):
    huga[i]+=1
    huga[i+1]+=1
  else:
    huga[i-1]+=1
    huga[i]+=1
    huga[i+1]+=1
print(max(huga))

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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int a,b,c;
	cin>>a>>b>>c;
	if(b/a<=c){
		cout<<b/a;
	}
	else{
		cout<<c;
	}
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 1e6 + 5;
const int mod = 998244353;

int n , a[maxn] , b[maxn];
int f[maxn];
void add(int & x , int y){
    x += y;
    if(x >= mod)x -= mod;
    if(x < 0)x += mod;
}
int Pow(int x , int y){
    if(y == 0)return 1;
    int r = Pow(x,y/2);
    if(y & 1)return (ll)r * r % mod * x % mod;
    return (ll)r * r % mod;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        int x;cin >> x;
        add(a[x],x);
        add(b[x],(ll)x * x % mod);
    }
    int res = 0;
    for(int i = (int)1e6 ; i >= 1 ; --i){
        int sum = 0 , sum1 = 0;
        for(int j = i ; j <= (int)1e6 ; j += i){
            add(f[i] , -f[j]);
            add(sum , a[j]);
            add(sum1 , b[j]);
        }
        add(f[i] , (ll)sum*sum%mod);
        add(f[i],-sum1);
        if(f[i]){
            add(res,(ll)f[i]*Pow(2*i,mod-2)%mod);
//            cout << i << " " << f[i] << endl;
//            cout << (ll)sum * sum << " " << -sum1 << endl;
        }
    }
    cout << res;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   if(pow < 0) return 0;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(2e6 + 7)] , inv_fac[(int)(2e6 + 7)];
void precomp_factorial(){fac[0] = 1;for(ll i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(ll i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};

int main(void)
{
   int n,k;
   cin >> n >> k;
   if(k > (n-1)*(n-2)/2){
       cout << -1;
       return 0;
   }
   vector <pair<int,int> > vec;
   for(int i = 2; i <= n; i++){
       vec.push_back({1,i});
   }
   int val = (n-1)*(n-2)/2;
   int cur = 2;
   while(val > k){
         for(int i = cur+1; i <= n; i++){
             if(k+(i-cur) > val){
                 val = k; break;
             }
            vec.push_back({cur, i});
         }
         val -= (n-cur);
         cur++;
   }
   cout << vec.size() << endl;
   for(auto x:vec) cout << x.first << " " << x.second << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 2e5 + 7;
const int Inf = 1 << 30;
const LL INF = 1LL << 60;
int n, ans;
string s[maxx];
map <string, bool> vis;

int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> s[i];
		if(!vis[s[i]]) {
			vis[s[i]] = 1;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 25300
from statistics import mean, median,variance,stdev
import sys
import math

x = input().split()
#y = input().split()
a = []
for i in range(len(x)):
   a.append(int(x[i]))
if a[0]+a[1]==a[2] or a[1]+a[2]==a[0] or a[0]+a[2]==a[1]:print("Yes")
else:print("No")

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

int main(){
    int W, H, x, y, r;
    scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
    
    if ( r <= x && x <= (W - r)) {
        if ( r <= y && y <= (H - r) )
            printf("Yes\n");
        else
            printf("No\n");    
    }else 
        printf("No\n");
    return 0;
}



Measured memory_bytes: 2104
#include<stdio.h>
#include<string.h>
int main (void){
  int a,i,j,dice[6],ans,box;
  char muki[6];
  for(;;){
    scanf("%d",&a);
    if(a==0)break;
    int dice[6]={1,2,6,5,3,4};
    ans=1;
    for(i=0;i<a;i++){
        scanf("%s",muki);
        if(!strcmp(muki,"North")){
            box=dice[0];
            for(j=0;j<3;j++){
                dice[j]=dice[j+1];
            }
            dice[3]=box;
            ans+=dice[0];
        }
        else if(!strcmp(muki,"East")){
            box=dice[0];
            dice[0]=dice[5];
            dice[5]=dice[2];
            dice[2]=dice[4];
            dice[4]=box;
            ans+=dice[0];
        }
        else if(!strcmp(muki,"West")){
            box=dice[0];
            dice[0]=dice[4];
            dice[4]=dice[2];
            dice[2]=dice[5];
            dice[5]=box;
            ans+=dice[0];
        }
        else if(!strcmp(muki,"South")){
            box=dice[3];
            for(j=3;j>0;j--){
                dice[j]=dice[j-1];
            }
            dice[0]=box;
            ans+=dice[0];
        }
        else if(!strcmp(muki,"Right")){
            box=dice[1];
            dice[1]=dice[4];
            dice[4]=dice[3];
            dice[3]=dice[5];
            dice[5]=box;
            ans+=dice[0];
        }
        else if(!strcmp(muki,"Left")){
            box=dice[1];
            dice[1]=dice[5];
            dice[5]=dice[3];
            dice[3]=dice[4];
            dice[4]=box;
            ans+=dice[0];
        }
    }
    printf("%d\n",ans);
  }
return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath> 
#include <queue>
#include <functional>

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};


int main() {

    int n;
    cin >> n;

    vector<ll> x(n), y(n);

    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) cin >> y[i];

    
    ll x_sum = accumulate(x.begin(), x.end(), 0LL);
    ll y_sum = accumulate(y.begin(), y.end(), 0LL);

    ll cnt = y_sum - x_sum;

    bool can = true;
    if (cnt < 0) can = false;
    
    ll cnt_y = cnt, cnt_x = cnt * 2;
    ll temp;
    for (int i = 0; i < n; i++) {
        if (x[i] == y[i]) continue;
        else if (x[i] < y[i]) {
            temp = y[i] - x[i];
            if (temp % 2 != 0) {
                cnt_y--;
                y[i]++; // XXX
                temp++;
            }
            cnt_x -= temp;
            x[i] += temp; // XXX
        }
        else {
            temp = x[i] - y[i];
            cnt_y -= temp;
            y[i] += temp; // XXX
        }
        //cout << temp << '\n';
    }
    //cout << cnt_x << ' ' << cnt_y << '\n';
/*
    for (int i = 0; i < n; i++) cout << x[i] << ' ' ;
    cout << "\n";
    for (int i = 0; i < n; i++) cout << y[i] << ' ' ;
    cout << "\n";
*/
    if (cnt_x != cnt_y or cnt_x < 0 or cnt_y < 0) {
        can = false;
    }

    if (can) cout << "Yes\n";
    else cout << "No\n";
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    ll minnute = (h2 * 60 + m2) - (h1 * 60 + m1);
    cout << minnute - k << endl;
    return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
int main()
{
    double pi = 3.14159265359;
    double r, cir;
    cin >> r;
    cir = 2 * pi * r;
    cout <<setprecision(20) << cir << endl;

    return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> bool amax(T &x, S y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T, typename S> bool amin(T &x, S y) { if (y < x) { x = y; return 1; } return 0; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  list<int> l;
  int Q; cin >> Q;
  auto cur = l.end();
  rep(_, Q) {
    int q; cin >> q;
    if (q == 0) {
      int x; cin >> x;
      cur = l.insert(cur, x);
    } else if (q == 1) {
      int d; cin >> d;
      rep(i, d) cur++;
      rep(i, -d) cur--;
    } else {
      cur = l.erase(cur);
    }
  }
  for (auto e: l) {
    cout << e << endl;
  }
  return 0;
}


Measured memory_bytes: 18664
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;

ll n, m, s;
vector<ll> vi[55], va[55], vb[55];
ll c[55], d[55];
bool e[55][2505];
ll ans[55];
bool g[55][2505];

struct st
{
    ll i, t, m, x;
};

bool operator <(st p, st q)
{
    return p.t > q.t;
}

priority_queue<st> pq;

int main()
{
    scanf("%lld%lld%lld", &n, &m, &s);
    s = min(s, 2500LL);
    for(ll i = 0; i < m; i++)
    {
        ll t1, t2, t3, t4;
        scanf("%lld%lld%lld%lld", &t1, &t2, &t3, &t4);
        vi[t1].push_back(t2);
        vi[t2].push_back(t1);
        va[t1].push_back(t3);
        va[t2].push_back(t3);
        vb[t1].push_back(t4);
        vb[t2].push_back(t4);
    }
    for(ll i = 1; i <= n; i++)
    {
        scanf("%lld%lld", &c[i], &d[i]);
    }
    pq.push({1, 0, s, 0});
    while(!pq.empty())
    {
        st t = pq.top();
        pq.pop();
        if(t.i > 1 && ans[t.i] == 0) ans[t.i] = t.t;
        if(e[t.i][t.m]) continue;
        e[t.i][t.m] = true;
        if(!g[t.i][t.m])
        {
            g[t.i][t.m] = true;
            for(ll i = t.m + c[t.i]; i <= 2500; i += c[t.i])
            {
                if(g[t.i][i]) break;
                g[t.i][i] = true;
                pq.push({t.i, t.t + (i - t.m) / c[t.i] * d[t.i], i, 0});
            }
        }
        for(ll i = 0; i < vi[t.i].size(); i++)
        {
            if(t.m >= va[t.i][i]) pq.push({vi[t.i][i], t.t + vb[t.i][i], t.m - va[t.i][i], 0});
        }
    }
    for(ll i = 2; i <= n; i++)
    {
        printf("%lld\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 19964