akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <utility>
#include <valarray>

using namespace std;

int main()
{
    int N, C, K;
    scanf("%d %d %d\n", &N, &C, &K);
    vector<int> T(N);
    for (int i = 0; i < N; ++i){
        int Ti;
        scanf("%d\n", &Ti);
        T[i] = Ti;
    }
    sort(T.begin(), T.end());
    int result = 0;
    for (int i = 0; i < N;){
        int time = T[i] + K;
        int j = 0;
        while (j < C && i + j < N && T[i + j] <= time) ++j;
        i += min(j, C);
        ++result;
    }
    printf("%d\n", result);
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <string.h>
using namespace std;

int main()
{
  int n = 0;
  long long base = 1e9+7;
  scanf("%d", &n);
  vector<long long> a(n, 0);
  for(int i=0; i<n; i++){
    scanf("%lld", &a[i]);
  }
  long long cumsum = 0;
  long long result = 0;
  for(int j=1; j<n; j++){
    cumsum = (cumsum + a[j-1]) % base;
    result = (result + cumsum * a[j]) % base;
  }
  printf("%lld\n", result);
}


Measured memory_bytes: 4828
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
    int n; cin >> n;
    map<int,int> freq;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        freq[a]++;
    }
    long ans = 0;
    for (auto it = freq.begin();
         it != freq.end();
         it++)
    {
        if (it->second < it->first)
            ans += it->second;
        else if (it->second > it->first)
            ans += it->second - it->first;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

int a[maxn];

int main(){
    int n,m,T;
    double x;
    double ans=0;
    string s;
    cin>>n;
    rep(i,0,n){
        cin>>x>>s;
        if(s[0]=='J') ans+=x;
        else ans+=x*380000.0;
    }
    printf("%.5f\n",ans);


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,k,n) for(int i = (k); i < (n); i++)

inline void readInt2(int *a, int *b) {
  int c, p = 0; char s[20] = "";
  for(int i = 0; (c = getchar_unlocked()) != '\n'; i++) {
    if (c == ' ') { *a = atoi(s); strcpy(s, ""); p = i+1; continue; }
    else s[i] = c;
  }
  *b = atoi(s+p);
}

inline void readInt3(int *a, int *b, int *c) {
  int d, p = 0; char s[20] = "";
  for(int i = 0; (d = getchar_unlocked()) != '\n'; i++) {
    if(d == ' ') {
      if(p == 0) { *a = atoi(s); strcpy(s, ""); p = i+1; }
      else {*b = atoi(s+p); strcpy(s, ""); p = i+1; }
    } else s[i] = d;
  }
  *c = atoi(s+p);
}

int parent[105], rank[105];
void uf_init(int n);
void unite(int x, int y);
bool same(int x, int y);
int find(int x);

// kruskal
struct edge {
  int u, v, cost;
};

bool comp(const edge& e1, const edge& e2) {
  return e1.cost < e2.cost;
}

edge es[5000];
int N, M; // ????????°??¨????????°

int kruskal() {
  int res = -1, max_edge, min_edge, ecount;
  sort(es, es + M, comp);
  rep(i,M) {
    uf_init(N);
    min_edge = es[i].cost;
    ecount = 0;
    rep2(j,i,M) {
      edge e = es[j];
      if (!same(e.u, e.v)) {
        unite(e.u, e.v);
        max_edge = e.cost;
        ecount++;
      }
    }
    if (ecount == N-1 && (res == -1 || res > (max_edge - min_edge))) res = max_edge - min_edge;
  }
  return res;
}

// Union Find
void uf_init(int n) {
  rep(i,n+1) { parent[i] = i; rank[i] = 0; }
}
int find(int x) {
  if (parent[x] == x) return x;
  else return parent[x] = find(parent[x]);
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if(x == y) return;
  if (rank[x] < rank[y]) parent[x] = y;
  else {
    parent[y] = x;
    if(rank[x] == rank[y]) rank[x]++;
  }
}
bool same(int x, int y) {
  return find(x) == find(y);
}

signed main(void) {
  int a, b, w, ans = 0;

  while(readInt2(&N, &M), N | M) {
    rep(i,M) {
      readInt3(&a, &b, &w);
      es[i].u = a; es[i].v = b; es[i].cost = w;
    }
    ans = kruskal();
    printf("%Ld\n", ans);
  }
  return 0;
}

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

using namespace std;

int n, m;
pair<int, int> jobs[100000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> jobs[i].second >> jobs[i].first;
  }
  sort(jobs, jobs + n);
  reverse(jobs, jobs + n);
  set<int> freedays;
  for (int i = 0; i < m; i++) {
    freedays.insert(i);
  }
  int ans = 0;
  for (int i = 0; i < n && !freedays.empty(); i++) {
    int maxtime = m - jobs[i].second;
    auto time = freedays.upper_bound(maxtime);
    if (time == freedays.begin()) {
      continue;
    }
    time--;
    ans += jobs[i].first;
    freedays.erase(time);
  }
  printf("%d\n", ans);
}

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

int w;
int h;
char field[1145][1419];
bool used[1145][1419];

void dfs(int y, int x) {
  if (y < 0 || h <= y) return;
  if (x < 0 || w <= x) return;
  if (field[y][x] == '0') return;
  if (used[y][x]) return;
  used[y][x] = true;

  for (int dy=-1; dy<=1; dy++) {
    for (int dx=-1; dx<=1; dx++) {
      if (dy == 0 && dx == 0) continue;
      int newy = y + dy;
      int newx = x + dx;
      dfs(newy, newx);
    }
  }
}

int main() {
  while (1) {
    if (scanf("%d%d", &w, &h) != 2) return 0;
    if (w == 0 && h == 0) return 0;

    for (int i=0; i<h; i++) {
      for (int j=0; j<w; j++) {
        scanf(" %c", &field[i][j]);
        used[i][j] = false;
      }
    }

    int ans = 0;
    for (int i=0; i<h; i++) {
      for (int j=0; j<w; j++) {
        if (!used[i][j] && field[i][j] == '1') {
          dfs(i, j);
          ans++;
        }
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 3364
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

int judge_square(long long int x){
  long long int i;
  for(i = 0; i*i<x; i++);
  if(x == i*i){
    return 1;
  }
  else{
    return 0;
  }
}

int main(){
  
  // read problem
  long long int N, D, tmp;
  scanf("%lld%lld", &N, &D);
  
  std::vector<std::vector<long long int> > X(N);
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j < D; j++){
      scanf("%lld", &tmp);
      X[i].push_back(tmp);
    }
  }
  
  // solve problem
  long long int ans = 0;
  for(long long int i = 0; i < N; i++){
    for(long long int j = i+1; j < N; j++){
      tmp = 0;
      for(long long int k = 0; k < D; k++){
        tmp += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
      }
      if(judge_square(tmp)){
        ans++;
      }
    }
  }
  
  std::cerr << "Answer:" << std::endl;
  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
from collections import deque
N = int(input())
es = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)
pre = [None] * (N+1)
pre[1] = 0
dq = deque()
dq.append((0, 1))
while dq:
    d, v = dq.popleft()
    if v == N:
        break
    for u in es[v]:
        if pre[u] == None:
            pre[u] = v
            dq.append((d+1, u))
col = [None] * (N+1)
v = N
sv = [N]
for i in range(d+1):
    if i < d/2:
        col[v] = 0
    else:
        col[v] = 1
    v = pre[v]
    sv.append(v)
# print(col)
# print(pre)
# print(sv)
bc, wc = 0, 0
for s in sv:
    if s == 0:
        continue
    dq = deque()
    dq.append(s)
    c = 0
    while dq:
        v = dq.popleft()
        c += 1
        for u in es[v]:
            if col[u] == None:
                col[u] = col[s]
                dq.append(u)
    if col[s] == 1:
        bc += c
    else:
        wc += c
if bc > wc:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 24152
#include <bits/stdc++.h>
/* S.size() s.substr(l,r=s.size()-l) -> l文字目からr文字分
__gcd()　lower_bound(a+l,a+r,x)-a でindex
// 配列  -> min/max({}) 
// vector-> *min_element(a+l,a+r)  *忘れず lとrで[l,r) 
//reverse(a+l,a+r)   配列aの[l,r)を逆順に strはreverse(all(s))
//sort(a+l,a+r,greater <int>()) 配列aの[l,r)昇順sort,大きい順はgreater<type>()
//vectorならall(v)
clock()/CLOCKS_PER_SEC で秒数
vector v.push_back(x),v.pop_back()
q.push(x),front()で先頭を返す,pop()で削除, size(),empty()
<deque>(push/pop)_(front/back)/fornt/back/insert/
priority_queue 宣言は priority_queue< Type, vector<Type>, greater<Type>> Q1; 
// pq.push(x),top()で参照 pop()で削除   greaterで最小 lessで最大がtopに*/
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n)-1;(i)!=-1;(i)--)
#define vep(i,v) for(auto (i)=v.begin();(i)<(v.end());(i)++)
#define print(i) std::cout << (i) << '\n'
inline long long ceildiv(long long a, long long  b) { return (a+b-1)/b; }
typedef pair<long long,long long> P;
const long long inf = 10e7;
const long long mod = 1000000007;
//int |x|<=2*10**9     long |x|<= 9*10**18
//printf(".(小数点以下の桁数)lf(double時、float ならf)")
#define ll long long

int main(){
int n;string s;cin>>n>>s;
map<char,int> m;m['R']=0;m['G']=1;m['B']=2;
vector<vector<int>> v(n);
int r=0,g=0,b=0;
long ans=0ll;
rep(i,n){if (s.at(i)=='R')r++;else{if (s.at(i)=='G')g++;else{b++;}}
vector<int> y={r,g,b};
         v.at(i)=y;}

rep(i,n){
    rep(j,n){
        if (i>=j)continue;
if (s.at(i)!=s.at(j)){ans+=v.at(j)[3-m[s.at(i)]-m[s.at(j)]]-v.at(i)[3-m[s.at(i)]-m[s.at(j)]];
if ((i+j)%2==0 && s[(i+j)/2]=="RGB"[3-m[s.at(i)]-m[s.at(j)]])ans--;}
}}
print(ans);}

Measured memory_bytes: 3868
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num = Integer.parseInt(in.nextLine());
		String[] tokens = in.nextLine().split(" ");
		int[] values = new int[num];
		int[] sortedValues = new int[num];
		for (int i = 0; i < num; ++i) {
			values[i] = Integer.parseInt(tokens[i]);
			sortedValues[i] = values[i];
		}
		Arrays.sort(sortedValues);
		for (int i = 0; i < num; ++i) {
			System.out.println(getMedium(i, values, sortedValues));
		}
		in.close();
	}

	public static int getMedium(int skipIndex, int[] values, int[] sortedValues) {
		int lowerMedium = sortedValues[sortedValues.length / 2 - 1];
		int largerMedium = sortedValues[sortedValues.length / 2];
		if (values[skipIndex] < lowerMedium) {
			return largerMedium;
		} else if (values[skipIndex] > largerMedium) {
			return lowerMedium;
		} else if (values[skipIndex] == lowerMedium) {
			return largerMedium;
		} else {
			return lowerMedium;
		}
	}
}


Measured memory_bytes: 82912
#include<iostream>
#include<map>
#include<vector>
#include<queue>
using namespace std;

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      map<string,int> hash;
      vector<string> team[n];



      for(int i=0;i<n;i++)
	{
	  string s;
	  cin>>s;
	  //teamname
	  int j=0;
	  for(;s[j]!=':';j++);
	  string name=s.substr(0,j);
	  hash[name]=i;
	  name="";
	  j++;
	  for(;j<s.size();j++)
	    {
	      if(s[j]==',' ||s[j]=='.')
		{
		  team[i].push_back(name);
		  //  cout<<"in "<<name<<endl;
		  name="";
		}
	      else
		name+=s[j];
	    }

	}
      int cnt=0;
      queue<int> qu;
      map<string,bool> mem;
      qu.push(0);
      while(!qu.empty())
	{
	  int num=qu.front();
	  qu.pop();
	  for(int j=0;j<team[num].size();j++)
	    {
	      if(mem.count(team[num][j])==0)
		{
		  if(hash.count(team[num][j])!=0)
		    qu.push(hash[team[num][j]]);
		  else
		    cnt++;
		  mem[team[num][j]]=true;
		}

	    }
	}


      cout<<cnt<<endl;
    }

}

Measured memory_bytes: 1368
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
int main()
{
	int D, N = 0;
	cin >> D >> N;

	int Ans = 0;

	if (N == 100) {
		if (D == 0) { Ans = 101; }
		else {
			if (D == 1) { Ans = 10100; }
			else { Ans = 1010000; }
		}
	}
	else {
		if (D == 0) { Ans = N; }
		else {
			if (D == 1) { Ans = 100 * N; }
			else { Ans = 10000 * N; }
		}

	}

	
	
	cout << Ans;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  string s, t; cin >> s >> t;
  cout << t << s << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	static final int MOD = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		//入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[m];
		int[] d = new int[m];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for(int i = 0; i < m; i++){
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}
		sc.close();

		//処理
		int[] ans = new int[n];
		for(int i = 0; i < n; i++){
			int least = 1000000000;
			int temp = -1;
			for(int j = 0; j < m; j++){
				int len = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
				if(len < least){
					temp = j;
					least = len;
				}
			}
			ans[i] = temp;
		}

		//出力	
		for(int i = 0; i < n; i++){
			out.println(ans[i] + 1);
		}
		out.flush();
	}
}

Measured memory_bytes: 24020
N,K=map(int,input().split())
class SegTreeMax:
    def __init__(self,N):
        self.N0=2**(N-1).bit_length()
        self.INF=2**63-1
        self.data=[0]*(2*self.N0)
        self.orig=[0]*N
    def update(self,i,x):
        self.orig[i]=x
        i+=self.N0-1
        self.data[i]=x
        while i>0:
            i=(i-1)//2
            self.data[i]=max(self.data[i*2+1],self.data[i*2+2])
    def max(self,l,r):
        L = self.N0 + l; R = self.N0 + r
        s = -self.INF
        while L < R:
            if R & 1:
                R -= 1
                s = max(s, self.data[R-1])
            if L & 1:
                s = max(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s
X=300000
s=SegTreeMax(X+1)
A=[int(input()) for i in range(N)]
for a in A:
    s.update(a,max(s.max(max(0,a-K),min(X,a+K)+1)+1,s.orig[a]))
print(s.max(0,X+1))

Measured memory_bytes: 123416
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> k(M);
    vector< vector<int> > s(M, vector<int>(N));
    REP(i, M) {
        cin >> k[i];
        REP(j, k[i]) {
            int tmp;
            cin >> tmp;
            s[i][tmp-1] = 1;
        }
    }
    vector<int> p(M);
    REP(i, M) cin >> p[i];

    int ans = 0;
    for(int bit=0; bit < (1<<N); ++bit) {
        vector<int> mod(M);
        for(int i=0; i<N; i++) {
            if(bit & (1<<i)) {
                for(int j=0; j<M; j++)
                    (mod[j] += s[j][i]) %= 2;
            }
        }
        bool flag = true;
        for(int i=0; i<M; i++) if(mod[i] != p[i]) flag = false;
        if(flag) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque

S = input()
Q = int(input())

Sq = deque(S)


flg = True
for i in range(Q):
    que = input()
    if que == "1":
        if flg:
            flg = False
        else:
            flg = True
    else:
        j, F, C = que.split()
        if int(F) == 1:
            if flg:
                Sq.appendleft(C)
            else:
                Sq.append(C)
        else:
            if flg:
                Sq.append(C)
            else:
                Sq.appendleft(C)

if flg:
    for i in Sq:
        print(i, end="")
else:
    Sq.reverse()
    for i in Sq:
        print(i, end="")

Measured memory_bytes: 7664
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;

  int f1,f2;
  f2=c - b; //A 攻击B
  f1=a - d; //B攻击A 
  while(f1>0&&f2>0){
    f2-=b;  //A 攻击B
    if(f2<=0) break;
    f1-=d;  //B 攻击A 
    if(f1<=0) break;
   
  }
  if(f2<=0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3540
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
bitset<12801>dp[80][80];
const int M=6400;
int a[80][80];
int main(){
    int n,m;
    R(n,m);
    REP(i,n)REP(j,m){
        R(a[i][j]);
    }
    REP(i,n)REP(j,m){
        int x;
        R(x);
        a[i][j]-=x;
        a[i][j]=abs(a[i][j]);
    }
    dp[0][0][M+a[0][0]]=1;
    REP(i,n)REP(j,m){
        if(i){
            dp[i][j] |= dp[i-1][j]<<a[i][j];
            dp[i][j] |= dp[i-1][j]>>a[i][j];
        }
        if(j){
            dp[i][j] |= dp[i][j-1]<<a[i][j];
            dp[i][j] |= dp[i][j-1] >>a[i][j];
        }
    }
    int an=0;
    while(1){
        if(dp[n-1][m-1][M+an]||dp[n-1][m-1][M-an])break;
        an++;
    }
    W(an);
    return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int ans =0;
  cin >> n;
  if(n<=104){cout << 0 << endl;return 0;}
  else{
    for(int i=105; i<=n; i+=2){
      int num = 0;
      for(int j=1; j<=i; j++){
        if(i%j==0){num++;}
        //cout << j << endl;}
      }
      if(num==8){ans++;}
    }
  }
  cout << ans << endl;
}
     

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

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

    sort(p.begin(), p.end());
    cout << accumulate(p.begin(), p.begin() + k, 0) << endl;
}

Measured memory_bytes: 3628
import java.util.*;
public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int input = sc.nextInt();
		//ArrayList<Integer> n= new ArrayList<Integer>();
		int n[] = new int [input];
		for (int i=0 ; i<input ; i++ ){
			int v = sc.nextInt();
			n[i]=v;
			}
		
		int L[] = new int [input+2];
		int R[] = new int [input+2];
		
		L[0]=0;
		R[input+1]=0;
		
		for (int i=0 ; i<input ; i++){
				L[i+1]=gcd(L[i],n[i]);
				R[input-i-1]=gcd(R[input-i],n[input-1-i]);
		}
		
		int max = 0;
		for (int i=0 ; i<input ; i++){
			int mi = gcd(L[i],R[i+1]); 
			if(mi>max){
				max = mi;
			}	
		}
		System.out.println(max);
	}



	public static int gcd(int a,int b){
		if(b==0) return a;
		else {
			int c = a%b;
			return gcd(b,c);
		}
	}

}

Measured memory_bytes: 50100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

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

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

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int k = sc.nextInt();
    String[][] cell = new String[h][w];
    for (int i = 0; i < h; i++) {
      cell[i] = sc.next().split("");
    }
    int result = 0;
    for (int r = 0; r < (1 << h); r++) {
      for (int c = 0; c < (1 << w); c++) {
        int count = 0;
        for (int i = 0; i < h; i++) {
          for (int j = 0; j < w; j++) {
            if (((r >> i) & 1) == 1 || ((c >> j) & 1) == 1) continue;
            if (cell[i][j].equals("#")) count++;
          }
        }
        if (k == count) result++;
      }
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 33500
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;

int main() {
    int n, x; cin >> n >> x;
    vector<int> m(n);
    int sum = 0;
    rep(i,n) {
        cin >> m[i];
        sum += m[i];
    }
    sort(m.begin(),m.end());

    cout << (x - sum) / m[0] + n << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define int long long

using namespace std;

int32_t main ()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	int n;
	cin>>n;
	int r=n%1000;
	int ans=(1000-r)%1000;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3604
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const llint mod=100000007;
const llint big=1e9;
const llint red=0xE869120;
const llint pro=1002001;
int main(void){
	int gen=0,ans=0,i,j,n;
	string str;
	cin>>n;
	cin>>str;
	n=str.size();
	for(i=0;i<n;i++){
		if(str[i]=='('){gen++;}
		else{gen--;}
		ans=max(ans,-gen);
	}
	for(i=0;i<max(-gen,ans);i++){cout<<'(';}
	cout<<str;
	for(i=0;i<max(ans+gen,0);i++){cout<<')';}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
N,M,Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
    
def dfs(n_list, o, l, L):
    if o+l==0:
        num = 1
        pos = 0
        
        L_child = [0]*N
        for i in range(N+M-1):
            if n_list[i]==1:
                num += 1
            else:
                L_child[pos] = num
                pos += 1
        L.append(L_child)
    
    if o>=1:
        n_list[N+M-o-l-1] = 0
        dfs(n_list, o-1,l, L)
    if l>=1:
        n_list[N+M-o-l-1] = 1
        dfs(n_list, o, l-1, L)
    
A = [0]*(N+M-1)
L =[]
dfs(A,N,M-1,L)

ans = 0
for i in L:
    score = 0
    for j in range(Q):
        if i[b[j]-1]-i[a[j]-1]==c[j]:
            score += d[j]

    if score > ans:
        ans = score

print(ans)

Measured memory_bytes: 22956
import math

#n = int(input())
n, m = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = input()
#list = list(s)


if (n < m) :
    print(0)
else :
    print(10)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  string S;
  cin >> S;

  vector <bool> app(26, false);
  int N = S.length();
  rep(i,N){
    if (app[S[i] - 'a']){
      cout << "no" << endl;
      return 0;
    }
    app[S[i] - 'a'] = true;
  }
  cout << "yes" << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 100100;
int n;
ll a,b,c,d;
int main(){
    cin >> n >> a >> b >> c >> d;
    --n;
    ll len = (n + 1) * c - (n - 1) * d;
    bool flag = false;
    if(len <= 0){
        if(b <= a + n * d && b >= a - n * d)
            flag = true;
    }else{
        ll hi = a + n * d, L = n * (d - c);
        for(int i = 0; i <= n; ++i){
            if(b <= hi && b >= hi - L)
                flag = true;
            hi -= L + len;
        }
    }
    if(flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=[int(x) for x in input().rstrip().split()]
B=[int(x) for x in input().rstrip().split()]
ans=0
now=A[0]
for i in range(N):
  if B[i]<=A[i]:
    ans+=B[i]
  else:
    if A[i]+A[i+1]<=B[i]:
      ans+=A[i]+A[i+1]
      A[i+1]=0
    else:
      ans+=B[i]
      A[i+1]=A[i+1]-(B[i]-A[i])
print(ans)



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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Vertex
{
    vector<int> n;
};

Vertex V[200005];
ll L[200005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        V[a].n.push_back(b);
        V[b].n.push_back(a);
    }

    //! 結局、葉を取るか、それ以外を取るか？
    ll m = -1;
    REP(i, N)
    {
        if (V[i].n.size() == 1)
        {
            m = i;
            break;
        }
    }
    {
        queue<pll> q;
        q.push(pll(m, 0));
        L[m] = 0;
        REP(i, N)
        {
            L[i] = INF;
        }
        while (!q.empty())
        {
            pll t = q.front();
            q.pop();
            REP(i, V[t.first].n.size())
            {
                int n = V[t.first].n[i];
                if (L[n] <= t.second + 1)
                    continue;
                L[n] = t.second + 1;
                q.push(pll(n, t.second + 1));
            }
        }
    }
    int mi = 0;
    REP(i, N)
    {
        if (L[mi] < L[i])
            mi = i;
    }
    {
        queue<pll> q;
        q.push(pll(mi, 0));
        REP(i, N)
        {
            L[i] = INF;
        }
        L[mi] = 0;
        while (!q.empty())
        {
            pll t = q.front();
            q.pop();
            REP(i, V[t.first].n.size())
            {
                int n = V[t.first].n[i];
                if (L[n] <= t.second + 1)
                    continue;
                L[n] = t.second + 1;
                q.push(pll(n, t.second + 1));
            }
        }
    }

    mi = 0;
    REP(i, N)
    {
        //cout << L[i] << endl;
        if (L[mi] < L[i])
            mi = i;
    }

    ll len = L[mi];
    //cout << len << endl;
    if (N == 1)
    {
        cout << "First" << endl;
    }
    else
    {
        if ((len - 1) % 3 == 0)
            cout << "Second" << endl;
        else
            cout << "First" << endl;
    }
    return 0;
}

Measured memory_bytes: 16804
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef pair<int, int> PII;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n,m;
    string s;
    cin>>n>>m;
    if(n==m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>> N;
  string S[N];
  int ac=0;
  int wa=0;
  int tle=0;
  int re=0;
  for(int i=0;i<N ;i++){
    cin >> S[i];
  }
  for(int i=0;i<N;i++){
  	if(S[i]=="AC"){
      ac +=1;
    }
    else if(S[i]=="WA"){
      wa +=1;
    }
    else if(S[i]=="TLE"){
      tle +=1;
    }
    else if(S[i]=="RE"){
      re +=1;
    }
  }
  cout<< "AC x "<< ac << endl;
  cout<< "WA x "<< wa << endl;
  cout<< "TLE x "<< tle << endl;
  cout<< "RE x "<< re << endl;
}

Measured memory_bytes: 6700
import sys
readline = sys.stdin.readline

N,Q = map(int,readline().split())

G = [[] for i in range(N)]

for i in range(N - 1):
  a,b = map(int,readline().split())
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)
  
point = [0] * N
for i in range(Q):
  p,x = map(int,readline().split())
  point[p - 1] += x

stack = [(0, -1, 0)]
while stack:
  v,parent,p = stack.pop()
  point[v] += p
  p = point[v]
  for child in G[v]:
    if child == parent:
      continue
    stack.append([child, v, p])
  
print(*point)

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

int main(){
	int n, m ;
	while( cin >> n >> m && n){
		set<int> tot;
		tot.insert(0);
		tot.insert(m);
		int sum = 0;
		int answer = 0;
		for(int i = 0 ; i < n ; i++){
			int k; cin >> k;
			sum = sum + k % m;
			sum %= m;
			answer = max( (sum-*tot.upper_bound(sum)+2*m)%m , answer );
			tot.insert(sum);
		}
		cout << answer << endl;
	}
}

Measured memory_bytes: 2408
//GRID-H_dp
#include<bits/stdc++.h>
#define  modulu 1000000007
using namespace std;
char grid[1001][1001];
int dp[1001][1001];

int NoOFPaths(char grid[1001][1001],int r,int c)
{

    if(dp[r][c]!=0)
    return (dp[r][c] % modulu);

    for(int i=1;i<=c;i++){ //for 1st row
       
      if(grid[1][i]!='#')
      {
          dp[1][i]=1;
      }
      else
       break;
      
      
      }


      for(int i=1;i<=r;i++) { //for 1st column
      if(grid[i][1]!='#')
      {
          dp[i][1]=1;
      }
      else
      break;
      
      }

    for(int i=2;i<=r;i++)
    {
        for(int j=2;j<=c;j++)
        {
            if(grid[i][j]!='#')
            {
            dp[i][j]=((dp[i-1][j] % modulu) +(dp[i][j-1] % modulu))%modulu;
            }
            else
            dp[i][j]=0;
        }


}

     return (dp[r][c] % modulu) ;


} 
int main()
{
    int r,c;
    cin>>r>>c;
    memset(dp,0,sizeof dp);
    for(int i=1;i<=r;i++)
    {
        for(int j=1;j<=c;j++)
        {
            cin>>grid[i][j];
        }
        cout<<endl;
        
    }
    cout<<NoOFPaths(grid,r,c);
    return 0;

}



Measured memory_bytes: 5120
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 21) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 510;
const int MOD = 1000000007;
const int INF = 1000000000;

int n, m, q;
int f[MAXN][MAXN];

int main()
{
	
	n = inp();
	m = inp();
	q = inp();
	while (m --)
	{
		int x = inp();
		int y = inp();
		f[x][y] ++;
	}
	for (int k = 2; k <= n; ++ k)
		for (int i = 1; i <= n; ++ i)
		{
			int j = i+k-1;
			if (j > n) continue;
			f[i][j] += f[i+1][j]+f[i][j-1]-f[i+1][j-1];
		}
	while (q --)
	{
		int x = inp();
		int y = inp();
		print(f[x][y], '\n');
	}
	
	return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    string S,T;
    cin >>S>>T;
    ll ans=INF;
    rep(i,S.size()-T.size()+1){
        ll now=0;
        rep(j,T.size()){
            if(S[i+j]!=T[j]){
                now++;
            }
        }
        chmin(ans,now);
    }
    
    cout << ans << endl;


    return 0;
    

}

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



using namespace std;

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

string s,t;
int n;

int main(){
    cin >> n;
    cin >> s;
    t = s.substr(0,s.size()/2);
    if(s == t+t){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

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

   ll a[n];
   for(ll i=0;i<n;i++)
   	cin>>a[i];

   ll dp[n];
   dp[0]=0;
   dp[1]=abs(a[1]-a[0]);

   for(ll i=2;i<n;i++)
     dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));

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


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#define N 305
using namespace std;

int n, s;
char a[N][N];
int f() {
	int i, j;
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			if (a[i][j] != a[j][i]) return 0;
		}
	}
	return 1;
}
int main()
{
	int i, j, k;
	cin >> n;
	for (i = 0; i <n; i++) {
		scanf ("%s", a[i]);
	}
	for (i = 0; i < n; i++) {
		s += f() * n;
		for (j = 0; j < n; j++) {
			for (k = n; k >= 1; k--) {
				a[j][k] = a[j][k - 1];
			}
			a[j][0] = a[j][n];
		}
	}
    cout << s;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int n1 = mid -left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i=0, j=0;
  for(int k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

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

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i)cout << " ";
    cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 6964
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n ;
string s[2] ;
signed main(){
    fastio
    cin >> n ;
    cin >> s[0] >> s[1] ;
    string a , b ;
    a.push_back(s[0][0]);
    b.push_back(s[1][0]) ;
    for(int i = 1; i < n; i++){
        if ( s[0][i] == s[0][i - 1] ) continue ;
        a.push_back(s[0][i]) ;
        b.push_back(s[1][i]) ;
    }
    debug() << imie(a) ;
    debug() << imie(b) ;
    int ans = 1 ; 
    if ( a[0] == b[0] ) ans = 3;
    else ans = 6 ;
    for(int i = 1; i < (int)a.size(); i++){
        if ( a[i] != b[i] && a[i - 1] != b[i - 1] ) {
            ans *= 3 ;
            ans %= MOD ;
        }
        else if ( a[i] != b[i] ) {
            ans *= 2 ;
            ans %= MOD ;
        }
        else if ( a[i - 1] == b[i - 1] ){
            ans *= 2 ;
            ans %= MOD; 
        }
    }
    debug() << imie(ans) ;
    cout << ans << endl;
    return 0; 
}
// 10
// RvvXYaaccdu
// RllXYbbeedu

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef long long int64;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(n);
    VL vi(n), total(n+1);
    rep(i, n){
        cill(a);
        vi[i] = a;
        total[a]++;
    }
    LL base = 0;
    rep(i, n+1){
        base += total[i] * (total[i] - 1) / 2;
    }
    rep(i, n){
        LL ans = base - total[vi[i]] + 1;
        co(ans);
    }
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>

using namespace std;

struct D {
    int x;
    int y;
    int h;
};

int main() {
    int n;
    cin >> n;
    
    int first_non_zero = -1;
    vector<D> ds(n);
    for (int i = 0; i < n; ++i) {
        auto& d = ds[i];
        cin >> d.x >> d.y >> d.h;

        if (d.h > 0 && first_non_zero < 0) {
            first_non_zero = i;
        }
    }

    if (first_non_zero < 0) {
        return 1;
    }

    for (int c_x = 0; c_x <= 100; ++c_x) {
        for (int c_y = 0; c_y <= 100; ++c_y) {
            int xx = abs(ds[first_non_zero].x - c_x);
            int yy = abs(ds[first_non_zero].y - c_y);
            int h = ds[first_non_zero].h;
            int H = h + xx + yy;

            bool ok = true;
            for (const auto& d : ds) {
                int h = max(H - abs(d.x - c_x) - abs(d.y - c_y), 0);
                if (h != d.h) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                cout << c_x << " " << c_y << " " << H;
                return 0;
            }
        }
    }

    return 1;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
	int cardcnt;
	char taro_card[100] = { 0 };
	char hana_card[100] = { 0 };
	int taro_score = 0;
	int hana_score = 0;
	int i;


	scanf("%d", &cardcnt);

	for (i = 0; i < cardcnt; i++) {
		scanf("%s %s",&taro_card ,hana_card);

		if (strcmp(taro_card, hana_card) > 0) {
			taro_score += 3;
		} else if (strcmp(taro_card, hana_card) < 0) {
			hana_score += 3;
		} else if (strcmp(taro_card, hana_card) == 0) {
			taro_score++;
			hana_score++;
		}
	}

	printf("%d %d\n" ,taro_score ,hana_score);

	return 0;
}


Measured memory_bytes: 2104