akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int n, middle = 0, staminaP[3], aux1, aux2, aux3;

    memset(staminaP, 0, sizeof(staminaP));

    scanf("%d", &n);

    int locale[n];

    for(int i = 0; i < n; i++)
    {
        scanf("%d", &locale[i]);
        middle += locale[i];
    }

    middle = middle/n;

    for(int i = 0; i < n; i++)
    {
        aux1 = locale[i]-middle;
        aux2 = locale[i]-(middle+1);
        aux3 = locale[i]-(middle-1);
        staminaP[0] += pow(aux1, 2);
        staminaP[1] += pow(aux2, 2);
        staminaP[2] += pow(aux3, 2);
    }

    if(staminaP[0] <= staminaP[1] && staminaP[0] <= staminaP[2])
    {
        printf("%d\n", staminaP[0]);    
    }
    else if(staminaP[1] <= staminaP[0] && staminaP[1] <= staminaP[2])
    {
        printf("%d\n", staminaP[1]);  
    }
    else
    {
        printf("%d\n", staminaP[2]);
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

void solve(){
  ll n;
  cin >> n;
  string ans="";
  while(n>0){
   n--;
   ans+=char(n%26+'a'); 
   n/=26; 
  }
  reverse(all(ans));
  cout << ans << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

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

a = [0] * n

first = 0
second = 0

for i in range(n):
    a[i] = int(input())
    if i == 0:
        first = a[i]
    else:
        if a[i] >= first:
            second = first
            first = a[i]
        elif a[i] >= second:
            second = a[i]
            
for i in a:
    if i == first:
        print(second)
    else:
        print(first)



Measured memory_bytes: 12508
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>


#define MOD 1000000007
#define INTMAX 0x7fffffff
#define INTMIN 0x80000000
#define LLMAX 0x7fffffffffffffffLL
#define LLMIN 0x8000000000000000LL

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

using namespace std;
using ll = long long;


#define INF 1000000000

int e[201][201];

int main(){
    int N, M, R;
    cin >> N >> M >> R;

    vector<int> vr;

    for (int i = 0; i < R; ++i) {
        int ri;
        cin >> ri;
        ri--;
        // cout << ri << endl;
        vr.push_back(ri);
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            e[i][j] = INF;
        }
    }
    for (int i = 0; i < N; ++i) {
        e[i][i] = 0;
    }
    for (int i = 0; i < M; ++i) {
        int ai, bi, ci;
        cin >> ai >> bi >> ci;
        ai--;
        bi--;

        e[ai][bi] = ci;
        e[bi][ai] = ci;
    }

    // for (int i = 0; i < N; ++i) {
    //     for (int j = 0; j < N; ++j) {
    //         cout << e[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            for (int k = 0; k < N; k++){
                e[j][k] = min(e[j][k], e[j][i] + e[i][k]);
                e[k][j] = e[j][k];
            }
    
    sort(vr.begin(), vr.end());
    int minsum = 1000000001;
    do {
        int sum = 0;
        for (int i = 0; i < R - 1; ++i) {
            //cout << vr[i] << " -> " << vr[i+1] << " ";
            sum += e[vr[i]][vr[i + 1]];
        }
        //cout << " sum = " << sum << endl;
        if (minsum > sum) {
            minsum = sum;
        }
    } while(next_permutation(vr.begin(), vr.end()));

    cout << minsum << endl;
}


Measured memory_bytes: 1016
import java.awt.*;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        double r=sc.nextInt();
        System.out.println(Math.PI*2*r);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

int main() {
  string a,b,c;
  cin>>a>>b>>c;
  
  int x=a.size();
  int y=b.size();
  int z=c.size();
  
  int s=1;
  int t=0;
  int u=0;
  
  char k=a[0];
  
  for(;;){
    if(k=='a'){
      if(s==x) {
        cout << 'A' << endl;
        break;
      }
      else{
        k=a[s];
        s++;
      }
    }
    
    else if(k=='b'){
      if(t==y){
        cout << 'B' << endl;
        break;
      }
      else{
        k=b[t];
        t++;
      }
    }
    
    
    else{
      if(u==z){
        cout << 'C' << endl;
        break;
      }
      else{
        k=c[u];
        u++;
      }
    }
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
long long int a,b,c,d;
  b=0;
  scanf("%lld",&a);
for(long long int j=1;j<a+1;j++)
   {
   c=j%3;
   d=j%5;
   if(c!=0 && d!=0) b=b+j;
   }
  printf("%lld",b);
return 0;
}

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

#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 3005;

int dp[N][N],n,m;
pii par[N][N];
string s,t;

void solve()
{
  cin >> s >> t;
    
  n=s.length();
  m=t.length();  
    
    for(int i=0;i<N;i++) par[0][i] = par[i][0] = {-1,-1};  
    
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=m;j++)   
      if(s[i-1] == t[j-1]) 
      {
        dp[i][j] = dp[i-1][j-1] + 1;
        par[i][j] = {i-1,j-1};
      }
      else 
      {
          if(dp[i][j-1] > dp[i-1][j])
          {
          dp[i][j] = dp[i][j-1];       
          par[i][j] = par[i][j-1];    
          }
          else
          {
           dp[i][j] = dp[i-1][j];
           par[i][j] = par[i-1][j];
          }     
      }
  }
 
    pii take = par[n][m];
 
    vector<char> v;
    
    while(take.F != -1)
    {
      v.pb(s[take.F]);
      take = par[take.F][take.S];
    }
    
    reverse(v.begin(),v.end());
    
    for(auto z : v) cout <<z;
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 211840
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int A, B, M;
    cin >> A >> B >> M;

    vector<int> a(A);
    REP(i, A) cin >> a[i];

    vector<int> b(B);
    REP(i, B) cin >> b[i];

    vector<int> x(M), y(M), c(M);
    REP(i, M) cin >> x[i] >> y[i] >> c[i];

    REP(i, M) {
        x[i]--;
        y[i]--;
    }

    int minA = *min_element(a.begin(), a.end());
    int minB = *min_element(b.begin(), b.end());

    int ans = minA + minB;
    REP(i, M) {
        ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 2176
N, M = map(int, input().split())
num = [input().split() for y in range(M)]


def check(target):
    if not len(target) == N:
        return False
    for x, y in num:
        if not target[int(x)-1] == y:
            return False
    return True


for i in range(1000):
    if check(str(i)):
        print(i)
        exit()

print(-1)


Measured memory_bytes: 3060
#include <stdio.h>

#define N_MAX 50
#define M_MAX 50

int main()
{
    int n, m;
    int roads[M_MAX][2];
    int numberOfRoadsCityHave[N_MAX + 1] = {};

    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++)
    {
	scanf("%d", &roads[i][0]);
	scanf("%d", &roads[i][1]);
    }

    for (int i = 0; i < m; i++)
    {
	numberOfRoadsCityHave[roads[i][0]] =
	    numberOfRoadsCityHave[roads[i][0]] + 1;
	numberOfRoadsCityHave[roads[i][1]] =
	    numberOfRoadsCityHave[roads[i][1]] + 1;
    }

    for (int i = 1; i <= n; i++)
    {
	printf("%d\n", numberOfRoadsCityHave[i]);
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;


using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define foi(i,k,n) for(int i=(k); i<(int)(n); i+=1)
#define fod(i,n,k) for(int i=k; i>=(int)n; i-=1)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define endl "\n"

#define int long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long llint;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<llint> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
llint toint(string s) {stringstream ss(s); llint x; ss >> x; return x;}
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//gp_hash_table<string, llint> table;


//int mpow(llint base, llint exp) {
  //base %= MOD;
  //llint result = 1;
  //while (exp > 0) {
    //if (exp & 1) result = ((llint)result * base) % MOD;
    //base = ((llint)base * base) % MOD;
    //exp >>= 1;
  //}
  //return result;
//}


//void makegraph(int n, int m){
	//int i, u, v;
	//while(m--){
		//cin>>u>>v;
		//u--, v--;
		//g[u].pb(v);
		//g[v].pb(u);
	//}
//}

//void dfs(int u, int par){
	//for(int v:g[u]){
		//if (v == par) continue;
		//dfs(v, u);
	//}
//}


// ------------------------------------------------------------------ILB----------------------------------------------------------------  //

const int MX = 3e3 + 100;

int r, c, k;
int dp[MX][MX][5];
int mat[MX][MX];


int rec(int i, int j, int pick){
	if(i > r || j > c) return -INF;
	if(i == r && j == c){
		return (pick < 3 ? mat[i][j] : 0);
	}
	
	if(dp[i][j][pick] != -1) return dp[i][j][pick];
	
	int ans = -INF;
	
	if(mat[i][j] && pick < 3){
		ans = max(ans, mat[i][j] + rec(i + 1, j, 0));
		ans = max(ans, mat[i][j] + rec(i, j + 1, pick + 1));
	}
	
	ans = max(ans, rec(i + 1, j, 0));
	ans = max(ans, rec(i, j + 1, pick));
	
	return dp[i][j][pick] = ans;
}


void solve(){
	cin >> r >> c >> k;
	
	loop(i, k){
		int x, y, z;
		cin >> x >> y >> z;
		mat[x][y] = z;
	}
	
	
	memset(dp, -1, sizeof(dp));
	
	cout << rec(1, 1, 0);
}




int32_t main() {
	fast_io;
    int t = 1;
    //cin >> t;
    //int xx = 0
    while(t--) {
		//xx++;
		//cout << "Case ";
      solve();
    }
    return 0;
}



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


int main() {
    int H,W,h,w;
    cin>>H>>W>>h>>w;

    cout<<(H-h)*(W-w)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = 1000000007;

int N, M, ans = 0;
int g[111][111];
vector<int> adj[111];
vector<int> homura;

void update()
{
	if (homura.size()==1) return;
	int res = 0;
	for (int i = 0; i < homura.size(); ++i)
	{
		int madoka = INF;
		for (int j = 0; j < homura.size(); ++j)
		{
			if (i == j) continue;
			madoka = min(madoka, g[homura[i]][homura[j]]);
		}
		res += madoka;
	}
	ans = max(ans, res);
}

inline bool check(int v)
{
	for (int i = 0; i < homura.size(); ++i)
		if (!g[homura[i]][v]) return 0;
	return 1;
}

void dfs(int u)
{
	homura.push_back(u);
	update();
	int v;
	for (int i = 0; i < adj[u].size(); ++i)
	{
		v = adj[u][i];
		if (v < u) continue;
		if (check(v)) dfs(v);
	}
	homura.pop_back();
}

int main()
{
	int u, v, d;
	scanf("%d%d", &N, &M);
	while (M--)
	{
		scanf("%d%d%d", &u, &v, &d);
		g[u][v] = g[v][u] = d;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for (u = 1; u <= N; ++u)
		dfs(u);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
ll X[110];
ll ans = linf;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> X[i];
    for(int i = 1; i <= 100; i++){
        ll sum = 0;
        for(int j = 0; j < N; j++){
            ll a = abs(i - X[j]);
            sum += a * a;
        }
        chmin(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var inputArray = input.split(' ');
var a = inputArray[0];
var b = inputArray[1];
var c = inputArray[2];
var d = inputArray[3];

var result = (a * b > c * d) ? a * b : c * d;
console.log(result);

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

int main() {
  string a, b;
  cin >> a >> b;
  string c = a + b;
  int num = std::atoi(c.data());
  for (int i = 4; i * i <= num; ++i) {
    if (i * i == num) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}


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

using namespace std;

using ll = long long;
const int MAXN = 5050;
const int MAXM = 220;
const ll INF = 1e18;

int N, M;
int A[MAXN];
int B[MAXN][MAXM];

ll tr[MAXN << 2];
ll lazy[MAXN << 2];

void build(int v, int l, int r) {
   tr[v] = -INF;
   if (l < r) {
      int md = (l + r) >> 1;
      build(v << 1, l, md);
      build(v << 1 | 1, md + 1, r);
   }
}

void push(int v, int l, int r) {
   if (lazy[v]) {
      tr[v] += lazy[v];
      if (l < r) {
         lazy[v << 1] += lazy[v];
         lazy[v << 1 | 1] += lazy[v];
      }
      lazy[v] = 0;
   }
}

void add(int v, int l, int r, int L, int R, ll val) {
   push(v, l, r);
   if (L > r || R < l) return;
   if (L <= l && r <= R) {
      lazy[v] = val;
      push(v, l, r);
      return;
   }
   int md = (l + r) >> 1;
   add(v << 1, l, md, L, R, val);
   add(v << 1 | 1, md + 1, r, L, R, val);
   tr[v] = max(tr[v << 1], tr[v << 1 | 1]);
}

void print(int v, int l, int r) {
   push(v, l, r);
   if (l == r) {
      cerr << tr[v] << "\n";
   } else {
      int md = (l + r) >> 1;
      print(v << 1, l, md);
      print(v << 1 | 1, md + 1, r);
   }
   if (v == 1) cerr << "\n";
}
vector<int> st[MAXM];

int main() {
   ios_base::sync_with_stdio(false);
   cin >> N >> M;
   for (int i = 1; i < N; ++i) cin >> A[i];
   for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= M; ++j) {
         cin >> B[i][j];
      }
   }
   for (int i = 1; i <= M; ++i) {
      st[i].emplace_back(0);
   }
   build(1, 1, N);
   ll ans = -INF;
   for (int i = 1; i <= N; ++i) {
      add(1, 1, N, i, i, INF);
      if (i > 1) add(1, 1, N, 1, i - 1, -ll(A[i - 1]));
      for (int z = 1; z <= M; ++z) {
         while (st[z].size() > 1 && B[st[z].back()][z] < B[i][z]) {
            add(1, 1, N, st[z][st[z].size() - 2] + 1, st[z].back(), -ll(B[st[z].back()][z]));
            st[z].pop_back();
         }
         add(1, 1, N, st[z].back() + 1, i, ll(B[i][z]));
         st[z].emplace_back(i);
      }
      ans = max(ans, tr[1]);
   }
   cout << ans << "\n";
   return 0;
}

Measured memory_bytes: 4864
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	c := make([]int, N+1)
	for i := 1; i <= N; i++ {
		for j := 1; i*j <= N; j++ {
			c[i*j]++
		}
	}
	ans := 0
	for i := 1; i <= N; i++ {
		ans += i * c[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 82556
using System;
using System.Linq;
using System.Collections.Generic;

public class BinarySearch{
	public static void Main()
	{
		Console.ReadLine();
		List<int> sList = ReadLineAndToIntList();
		Console.ReadLine();
		List<int> tList = ReadLineAndToIntList();
	
		int count = 0;
	
		foreach (var t in tList)
		{
			if(sList.BinarySearch(t) > -1) count++;
		}
		
		Console.WriteLine(count);
	}
	
	//??????????????????????????????
	public static List<int> ReadLineAndToIntList()
	{
		return Console.ReadLine().Split().Select (c => int.Parse(c)).ToList();
	}
}

Measured memory_bytes: 15100
def is_prime(p):
    for i in range(2, int(p**(1/2))+ 1):
        if p % i == 0:
            return False
    
    return True


n = int(input())
count = 0
for _ in range(n):
    p = int(input())
    if is_prime(p):
        count += 1

print(count)




Measured memory_bytes: 5692
def solve():
    cnt1 = 0
    cnt2 = 0
    for i in range(1,N+1):
        if i % K == 0:
            cnt1 += 1
        elif i % K == K/2:
            cnt2 += 1
    if K%2==1:
        ans = cnt1**3
    else:
        ans = cnt1**3+cnt2**3
    print(ans)

if __name__=="__main__":
    N,K = list(map(int, input().split()))
    solve()


Measured memory_bytes: 9132
import copy

n = int(input())
data = list(map(int, input().split()))
s_data = copy.deepcopy(data)
s_data.sort()
c = 0
for i in range(n):
    if data[i] != s_data[i]:
        c += 1

if c == 2 or c == 0:
    # 入れ替えたときちゃんと合うか
    print("YES")
else:
    print("NO")



Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		Integer n = Integer.valueOf(scanner.nextInt());
		Integer oddNum = (n / 2) + (n % 2);
		System.out.println((float)oddNum / (float)n);
	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	int N;
	cin >> N;
	vector<double> p(N);
	for (int i = 0; i < N; i++)cin >> p[i];
	vector<vector<double> >dp(N+1, vector<double>(N+1, 0)); //i枚目までのコインを投げた時、表の枚数がj枚になる確率
	dp[0][0] = 1;
	for (int i = 0; i < N; i++)for (int j = 0; j <= i; j++) {
		dp[i + 1][j] += dp[i][j] * (1 - p[i]); //裏が出る
		dp[i + 1][j + 1] += dp[i][j] * p[i]; //表が出る
	}
	double ans = 0;
	for (int i = 0; i <= N; i++) {
		if (N - i < i)ans += dp[N][i];
	}
	cout << std::setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

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

  string ans = "No";
  if (a == b && a == c) {
    ans = "Yes";
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
a,b=map(int,input().split())
d={}
flag=1
for i in range(b):
  x,y=map(int,input().split())
  if [x,y]==[1,0]:
    if a>1:
      print(-1)
      flag=0
      break
  if x in d:
    if d[x]!=y:
      print(-1)
      flag=0
      break
  d[x]=y
if flag:
  if [a,b]==[1,0]:print(0)
  else:
    k=['1']+['0']*(a-1)
    for i in d:
      k[i-1]=str(d[i])
    print(''.join(k))

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

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("/Users/ishan/Desktop/fuzzy-chainsaw-algo/input.txt", "r", stdin);
    freopen("/Users/ishan/Desktop/fuzzy-chainsaw-algo/output.txt", "w", stdout);
#endif
}

int f(vector<int> arr, int n){
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(arr[0] - arr[1]);
    for(int i = 2; i <= n; i++){
        dp[i] = min(dp[i-1]+abs(arr[i] - arr[i-1]), dp[i-2]+abs(arr[i]- arr[i-2]));
    }
    return dp[n-1];
}

int main() {
    c_p_c();
    int n;  cin>>n;
    vector<int> arr(n);
    for(int i = 0; i < n; i++) cin>>arr[i];
    cout<<f(arr,n);
}


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

struct Edge {
    ll from;
    ll to;
    ll cost;
};

using Edges = vector<Edge>;
const ll INF = 1LL << 60;

void bellman_ford(const Edges &Es, int V, int s, vector<ll> &dist) {
    dist.resize(V,INF);
    dist[0] = 0;
    int cnt = 0;
    while(cnt < 3*V) {
        for(auto e : Es) {
            if(dist[e.from] == INF) continue;
            if(dist[e.to] > dist[e.from] + e.cost) {
                dist[e.to] = dist[e.from] + e.cost;
                //負の閉路に含まれる頂点の距離を-INFとしてさらにn回以上伝播させる
                if(cnt == V-1) dist[e.to] = -INF;
            };
        }
        cnt++;
    }
}


int main()
{
    int n,m;
    cin >> n >> m;
    Edges Es(m);
    rep(i,m) {
        cin >> Es[i].from >> Es[i].to >> Es[i].cost;
        Es[i].from--; Es[i].to--;
        Es[i].cost *= -1;
    }

    vector<ll> dist;
    bellman_ford(Es, n, 0, dist);
    if(dist[n-1] < -INF) cout << "inf" << endl;
    else cout << -dist[n-1] << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
int main(void)
{
  char s[4];
  int ans=0,max=0;
  scanf("%s", s);
  for(int i=0;i<3;i++){
    if(s[i] == 'S') ans=0;
    else ans++;
    if(max<ans) max=ans;
  }
  printf("%d", max);
    return 0;
  }


Measured memory_bytes: 1704
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;

vector<pair<int,int> >st;

/*bool comp(pair<int,int> A,pair<int,int> B){
    double aa=1.0*
}*/


int32_t main(){
	ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
   // st.resize(n);
    REP(i,0,n){
        int A,B;
        cin>>A>>B;
        st.PB({A,B});
    }
    sort(st.begin(),st.end());
    int cost=0;
    int bt=0;
    for(int i=0;i<n;i++){
        cost+=(min(m-bt,st[i].S))*st[i].F;
        bt+=min(m-bt,st[i].S);
        if(bt==m){
            break;
        }
    }
    cout<<cost<<"\n";




	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;

typedef long long ll;

void debug(ll B_C, ll C_D, ll D_E, vector<ll> A) {
    cout << "B_C:" << B_C << endl;
    cout << "C_D:" << C_D << endl;
    cout << "D_E:" << D_E << endl;
    cout << "B ";
    for (ll i = 0; i <= B_C; i++) {
        cout << A[i] << " ";
    }
    cout << endl;
    cout << "C ";
    for (ll i = B_C+1; i <= C_D; i++) {
        cout << A[i] << " ";
    }
    cout << endl;
    cout << "D ";
    for (ll i = C_D+1; i <= D_E; i++) {
        cout << A[i] << " ";
    }
    cout << endl;
    cout << "E ";
    for (ll i = D_E+1; i < A.size(); i++) {
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<ll> sum_A(N);
    sum_A[0] = A[0];
    for (ll i = 1; i < N; i++) {
        sum_A[i] = sum_A[i-1] + A[i];
    }
    ll B_C = 0;
    ll D_E = 2;
    ll ans = (ll)1 << 62;
    for (ll C_D = 1; C_D < N-2; C_D++) {
        for (; B_C+1 < C_D; B_C++) {
            if (llabs(sum_A[B_C] - (sum_A[C_D]-sum_A[B_C])) < llabs(sum_A[B_C+1] - (sum_A[C_D]-sum_A[B_C+1]))) {
                break;
            }
        }
        for (; D_E+1 < N-1; D_E++) {
            if (llabs(sum_A[D_E] - sum_A[C_D] - (sum_A[N-1] - sum_A[D_E])) < llabs(sum_A[D_E+1] - sum_A[C_D] - (sum_A[N-1] - sum_A[D_E+1]))) {
                break;
            }
        }
        // debug(B_C, C_D, D_E, A);
        vector<ll> PQRS = {sum_A[B_C], sum_A[C_D]-sum_A[B_C], sum_A[D_E]-sum_A[C_D], sum_A[N-1]-sum_A[D_E]};
        ans = min(ans, *max_element(PQRS.begin(), PQRS.end()) - *min_element(PQRS.begin(), PQRS.end()));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;

constexpr int max_v = 31;
constexpr int INF = 1e9;
constexpr double eps = 1e-8;


class state {
public:
    int u, prev;
    int v;
    double time;
    bool operator>(state const& other) const {
        return time > other.time;
    }
};

struct edge {
    int from, to;
    int dist;
    int limit;
};

using edges = vector<edge>;
using graph = vector<edges>;


double dijkstra(graph& g, int s, int G) {
    vector<vector<vector<double>>> d(g.size(), vector<vector<double>>(g.size(), vector<double>(max_v, INF)));
    priority_queue<state, vector<state>, greater<state>> que;
    d[s][0][0] = 0;
    que.push(state{s, 0, 0, 0});
    while(!que.empty()) {
        state S = que.top(); que.pop();
        int u = S.u, prev = S.prev, v = S.v;
        if(d[u][prev][v] + eps < S.time) {
            continue;
        }
        for(int i=0; i<g[u].size(); ++i) {
            edge e = g[u][i];
            if(e.to == prev) { // to
                continue;
            }
            for(int j=-1; j<=1; ++j) {
                int nv = v + j;
                if(nv <= 0 || max_v <= nv || e.limit < nv) {
                    continue;
                }
                if(d[e.to][u][nv] - (d[u][prev][v] + e.dist / (double)nv) > eps) {
                    d[e.to][u][nv] = d[u][prev][v] + e.dist / (double)nv;
                    que.push(state{e.to, u, nv, d[e.to][u][nv]});
                }
            }
        }
    }
    double res = INF;
    for(int i=0; i<g.size(); ++i) {
        res = min(res, d[G][i][1]);
    }
    return res;
}


int main() {
    int n, m;
    while(cin >> n >> m, n) {
        int s, g;
        cin >> s >> g;
        graph G(n+1);
        for(int i=0; i<m; ++i) {
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            G[x].push_back((edge){x, y, d, c});
            G[y].push_back((edge){y, x, d, c});
        }
        double res = dijkstra(G, s, g);
        if(fabs(res - INF) < eps) {
            cout << "unreachable" << endl;
        } else {
            cout << fixed << setprecision(10) << res << endl;
        }
    }
}


Measured memory_bytes: 3968
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
int p[110];
int main(){
	int a;scanf("%d",&a);
	int ret=0;
	for(int i=1;i<=a;i++){
		int tmp=i;
		int cnt=0;
		while(tmp){
			cnt++;
			tmp/=10;
		}
		if(cnt%2==1)ret++;
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 128
import Data.Text as T
import Data.Text.Encoding as E
import Data.ByteString (ByteString)

dummyInput :: String
dummyInput = "1819\n2003\n876\n2840\n"

rdrop :: Int -> [a] -> [a]
rdrop x y = Prelude.reverse (Prelude.drop x (Prelude.reverse y))

deleteReturnCode :: [Char] -> [Char]
deleteReturnCode x = rdrop 1 x

convertList :: Text -> [Int]
convertList x =
  let charcter = T.pack "\n"
  in Prelude.map convertInt (Prelude.map T.unpack (T.splitOn charcter x))

convertInt :: String -> Int
convertInt x = read x :: Int

sortHeight :: (Ord a) => [a] -> [a]
sortHeight [] = []
sortHeight [x] = [x]
sortHeight (x:xs) =
  let largeList = [a | a <- xs, a > x];
      smallList = [a | a <- xs, a <= x]
  in sortHeight smallList ++ [x] ++ sortHeight largeList

showTopThree :: (Ord a) => [a] -> [a]
showTopThree [] = []
showTopThree x = (Prelude.take 3 (Prelude.reverse x))

main :: IO ()
main = do
  inputData <- getContents
  mapM_ print (showTopThree (sortHeight (convertList (T.pack (deleteReturnCode inputData)))))



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

#define int long long

int32_t main()
{
    int n;
    cin >> n;
    int arr[n+1];
    int heros[n];
    for(int i=0;i<=n;++i)
    {
        cin >> arr[i];
    }
    for(int i=0;i<n;++i) cin >> heros[i];
    
    int ans =0;
    int tmp;
    for(int j=n-1;j>=0;--j)
    {
        tmp = arr[j+1];
        ans += min(heros[j],arr[j+1]);
        heros[j] -= min(arr[j+1],heros[j]);

        tmp = arr[j];
        arr[j] -= min(heros[j],tmp);
        ans += min(heros[j],tmp);

    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    for (int i = 0; i < M; i++)
    {
        cin >> B[i];
    }
    vector<vector<int>> A(N, vector<int>(M));
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < M; ++j)
        {
            cin >> A[i][j];
        }
    }
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        int sum = 0;
        for (int k = 0; k < M; k++)
        {
            sum += A[i][k] * B[k];
        }
        if (sum + C > 0)
        {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    for (int i = 0; i < (int) s.size(); ++i) {
        for (int j = i + 1; j < (int) s.size(); ++j) {
            if (s[i] == 'C' && s[j] == 'F') {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
arr = Array.new
while line = $stdin.gets
arr << line.chomp.split(" ").map(&:to_i)
end


sum=0
n.times{|t|
    k=n-t-1
    if ((arr[k][0]+sum)%arr[k][1])==0 then
        num = 0
    else
        num=(arr[k][1] -((arr[k][0]+sum)%arr[k][1]))
    end
    sum+=num
}
print sum

Measured memory_bytes: 11516
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
  char buf[101];
  bool sym;
  int l, c = 0;
  while (scanf("%101s", buf)==1) {
    l = strlen(buf);
    sym = true;
    for (int i=0; (i<<1)<l; i++) {
      if (buf[i] != buf[l-i-1]) {
        sym = false;
        break;
      }
    }
    if (sym) ++c;
  }
  printf("%d\n", c);
  return 0;
}

Measured memory_bytes: 968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b-1);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define lowbit(x) x&(-x)
const int N = 20000;
const int M = 1e9+7;

ll x[100010];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    __int128 sum=1;
    __int128 maxn=1e18;
    int n;
    cin>>n;
    for (int i=1; i<=n; i++) cin>>x[i];
	for (int i=1; i<=n; i++){
		if (x[i]==0){
			cout<<0;
			return 0;
		}
	}
    for (int i=1; i<=n; i++){
    	sum*=x[i];
    	if (sum>maxn){
    		cout<<-1;
    		return 0;
		}
	}
	cout<<ll(sum);
    return 0;
}


Measured memory_bytes: 4436
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    int mx = 55555;

    vector<vector<int>> G(10);

    vector<bool> isPrime(mx + 2, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i <= mx; ++i) {
        if (isPrime[i]) {
            G[i % 10].push_back(i);
            for (int j = i + i; j <= mx; j += i) {
                isPrime[j] = false;
            }
        }
    }

    for (auto x : G[1]) {
        cout << x;
        if (--n == 0) {
            cout << '\n';
            break;
        } else {
            cout << ' ';
        }
    }

    return 0;
}

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

int main()
{
    int N;
    int a[200005];
    cin >> N;
    REP(i, N)
        cin >> a[i];
    
    int now = 1;
    int brick = 0;
    REP(i, N){
        if(a[i] != now)
            brick++;
        else
            now++;
    }
    if(brick == N)
        cout << -1 << endl;
    else
        cout << brick << endl;
    
    return 0;
}



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

int main() {
	string sa,sb,sc;
  	cin >> sa >> sb >> sc;
 
  	int sizeA = sa.size(),sizeB = sb.size(),sizeC = sc.size();
  	char nextman = 'a';
  	bool stop = false;
  
  	while(1) {
  	switch(nextman) {
      case 'a':
        	if(sizeA == 0) {
            	cout << 'A' << endl;
              	stop = true;
              	break;
            }
        	nextman = sa.at(0);
        	sa.erase(sa.begin());
        	sizeA--;
        	break;
        
       case 'b':
        	if(sizeB == 0) {
            	cout << 'B' << endl;
              	stop = true;
              	break;
            }
        	nextman = sb.at(0);
        	sb.erase(sb.begin());
        	sizeB--;
        	break;
        
       case 'c':
        	if(sizeC == 0) {
            	cout << 'C' << endl;
              	stop = true;
              	break;
            }
        	nextman = sc.at(0);
        	sc.erase(sc.begin());
        	sizeC--;
        	break;
    	}
      	
      	if(stop) break;
    }
}

Measured memory_bytes: 256
import sys
from heapq import *
input = sys.stdin.readline

n,Q = [int(i) for i in input().split()]

stx=[[0]*3 for _ in range(n)]
for j in range(n):
    a = [int(i) for i in input().split()]
    stx[j]=[a[0]-a[2],a[1]-a[2],a[2]]
q = [int(input()) for i in range(Q)]
stx.sort()

xt=[]
pt=0
for d in q:
    while pt < n and stx[pt][0] <= d:
        heappush(xt,(stx[pt][2],stx[pt][1]))
        pt+=1
    while xt and xt[0][1] <= d:
        heappop(xt)
    if xt:
        print(xt[0][0])
    else:
        print(-1)

Measured memory_bytes: 127288
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string str;

    cin>>str;

    for(int i = 0; i < 3; i++){
        if(str[i] == str[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }

    cout<<"Good"<<endl;

    return  0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string sa,sb,sc;
  cin>>sa>>sb>>sc;
  char card='a';
  int a=1;
  while(a==1){
    if(card=='a'){
      card=sa[0];
      sa.erase(sa.begin());
    }
    else if(card=='b'){
      card=sb[0];
      sb.erase(sb.begin());
    }
    else if(card=='c'){
      card=sc[0];
      sc.erase(sc.begin());
    }
    if(card=='a'&&sa.size()==0){
      cout<<'A'<<endl;
      break;
    }
    if(card=='b'&&sb.size()==0){
      cout<<'B'<<endl;
      break;
    }
    if(card=='c'&&sc.size()==0){
      cout<<'C'<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod=1000000007ll;
void ad(long long &a,long long b){a+=b;a%=mod;}
void mn(long long &a,long long b){a+=mod-b;a%=mod;}
void ml(long long &a,long long b){a*=b;a%=mod;}
long long sq(long long a){return a*a%mod;}
long long pw(long long a,long long n)
{
  return n==0?1ll:sq(pw(a,n/2))*(n%2==1?a:1ll)%mod;
}
long long iv(long long a){return pw(a,mod-2);}

int main()
{
  int n;
  scanf("%d\n",&n);
  vector<long long> A(n);
  for(int i=0;i<n;i++){
    scanf("%lld",&A[i]);
  }
  static vector<long long> F(n+1),S(n+2);
  F[0]=1;
  for(int i=0;i<n;i++){
    F[i+1]=(i+1)*F[i]%mod;
  }
  S[0]=0;
  static vector<long long> inv(n+1);
  inv[0]=0;
  inv[1]=1;
  for(int i=2;i<=n;i++){
    inv[i]=(mod-mod/i)*inv[mod%i]%mod;
  }
  for(int i=0;i<n;i++){
    S[i+1]=(S[i]+F[n]*inv[i+1]%mod)%mod;
  }
  long long ans=0;
  for(int i=0;i<n;i++){
    long long B=(S[i+1]+S[n-i]+mod-F[n])%mod;
    ad(ans,A[i]*B%mod);
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int b[n];
    for(int i=1;i<n;++i){
        cin>>b[i];
    }
    long long ans=0;
    ans+=b[1];
    ans+=b[n-1];
    for(int i=2;i<n;++i){
        ans+=min(b[i-1],b[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
  char a[200010],b[200010];
  int ans=0;
  scanf("%s",a);
  scanf("%s",b);
  for(int i=0;i<strlen(a);i++)
   {
    if(a[i]!=b[i])
      ans++;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 2120
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
void Iswap(int *a,int *b){
  int t=*a;
  *a=*b;
  *b=t;
}
void Fswap(double *a,double *b){
  double t=*a;
  *a=*b;
  *b=t;
}
void Lswap(ll *a,ll *b){
  ll t=*a;
  *a=*b;
  *b=t;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;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;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}
ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}
int main(void){
  int k;
  INI(k);
  int a;
  INI(a);
  int b;
  INI(b);
  for(int i=a;i<b+1;i++){
    if(i%k<1){
      PRS("OK");
      return 0;
    }
  }
  PRS("NG");
  return 0;
}

Measured memory_bytes: 1636
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] val = new int[w];
		for(int i = 0; i < val.length; i++){
			val[i] = i + 1;
		}

		for(int i = 0; i < n; i++){
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			int c;
			c = val[a];
			val[a] = val[b];
			val[b] = c;
		}
		for (int i = 0; i < val.length; i++){
			System.out.println(val[i]);
		}
	}

}

Measured memory_bytes: 17200
#include<stdio.h>
#include<string.h>
int main(){

  char s[1000],p[1000];
  char ring[1000];
  gets(s);
  gets(p);

  sprintf(ring,"%s%s",s,s);

  if(strstr(ring,p)!=NULL){
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int N,X,Y,Z;
int S;
bool nx[1<<16][11];
LL dp[41][1<<16];


LL dfs(int now, int state){ //今nowまで見ていて，状態stateのとき何通りあるか
    if(dp[now][state] >= 0) return dp[now][state];
    if(now == N) return 1;

    LL ret = 0;
    for(int i = 1; i <= 10; i++){
        if(nx[state][i]){
            ret += dfs(now+1,((state<<i)+(1<<(i-1)))%(1<<S));
            ret %= MOD;
        }
    }
    return dp[now][state] = ret;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> X >> Y >> Z;
    S = X+Y+Z-1;

    REP(mask,1<<S){ //状態maskのとき，iが来てよいかチェック
        VI b;
        int st = 0;
        REP(i,S){
            if((mask >> i) & 1){
                b.eb(i-st+1);
                st = i+1;
            }
        }

        int B = b.size();
        for(int i = 1; i <= 10; i++){
            bool ok = true;
            int x = 0, y = 0, z = i;
            int bidx = 0;
            while(bidx < B && z < Z) z += b[bidx++];
            while(bidx < B && y < Y) y += b[bidx++];
            while(bidx < B && x < X) x += b[bidx++];
            if(x == X && y == Y && z == Z) ok = false;

            nx[mask][i] = ok;
        }
    }

    LL p10 = 1;
    REP(i,N) p10 = (p10*10)%MOD;

    memset(dp,-1,sizeof(dp));
    LL r = dfs(0,0);
    LL ans = (p10 - r + MOD) % MOD;
    cout << ans << endl;


}


Measured memory_bytes: 22016
#include "bits/stdc++.h"
using namespace std; 

#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define ll long long 

int main(){
        IOS;
        ll x,k,d;
        cin>>x>>k>>d;
        if(x<0)x=-x;
        ll a=x/d;
        if(a<=k) {
                if(a==k)cout<<x%d<<"\n";
                else{
                        ll pos=x%d;
                        ll neg=d-pos;
                        ll rem=(k-a);
                        if(rem&1) cout<<neg<<"\n";
                        else cout<<pos<<"\n";
                }
        }
        else cout<<abs(x-k*d)<<"\n";
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

LL n;
LL a[10000005];
int main(){ 
    cin>>n;
   for(int i=1;i<=n;i++){
       a[i] = 1;
   }
   for(int i=2;i<=n;i++){
       for(int j=i;j<=n;j+=i){
           a[j]++;
       }
   }
   LL sum = 0;
    for(int i=1;i<=n;i++){
        sum += (i*a[i]);
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 81696
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <cassert>
#include <queue>
//#include "optimization.h"

using namespace std;

const int mod = 1000000007;

bool used[100500][2];
vector<int> gr[100500];

void dfs(int v, bool col){
    used[v][col] = true;
    for (int x:gr[v])
        if (!used[x][!col])
            dfs(x, !col);
}

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // LOCAL
    string s;
    int n, a, m, b;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        cin >> a >> b;
        a--;
        b--;
        gr[a].push_back(b);
        gr[b].push_back(a);
    }
    dfs(0, 0);
    int num0 = 0;
    int num1 = 0;
    long long ans = 0;
    for (int i = 0; i < n; i++){
        if (used[i][1]){
            num1++;
        }
        if (used[i][0]){
            num0++;
        }
    }
    int num = 0;
    ans += num1 * 1ll * num0;
    for (int i = 0; i < n; i++)
        if (used[i][0] && used[i][1]){
            num++;
        }
    //cout << num1 << " " << num0 << " " << num << endl;
    ans -= num * 1ll * (num - 1) / 2 + num;
    cout << ans - m;
    #ifdef LOCAL
    cout.flush();
    _Exit(0); //GLIBCXX_DEBUG not working without it
    #endif // local
    return 0;
}



Measured memory_bytes: 7936