akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a,b;
    cin >> a >> b;
    if(a < 10 && b < 10) cout << a*b << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using  namespace std;
int main(){
    long long n, t, ans, check;
    cin >> n >> t;
    long long T[n];
    ans = t;
    for(int i=0;i<n;i++){
        cin >> T[i];
    }
    for(int i=1;i<n;i++){
        check = (T[i]-T[i-1]);
        if(check<t){
            ans += check; 
        }else{
            ans += t;
        }
    }
    
    cout << ans << endl;
    return 0;
 
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
typedef pair<int, P> PP;

signed main() {
	int a, b; cin >> a >> b;
	cout << abs(a - b) << endl;
}



Measured memory_bytes: 3100
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}



int main(void) {
    // FAST_IO;
    
    int n;
    int cnt = 0;
    cin >> n;
    for (int i = 1; i <= n; i+=2) {
        cnt++;
    }
    printf("%.10f\n", cnt/double(n));
    
    return 0;
}

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

int num[105] ;
int main()
{
    int n ;
    while(~scanf("%d",&n)){
        for(int i = 0;i<n;i++){
           scanf("%d",num+i) ;
        }
        int ans = 0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n-i-1;j++){
                if(num[j]>num[j+1]){
                    ans++;
                    swap(num[j],num[j+1]);
                }
            }
        }
        printf("%d",num[0]) ;
        for(int i = 1 ;i<n;i++){
            printf(" %d",num[i]) ;
        }
        printf("\n") ;
        printf("%d\n",ans) ;
    }
    return 0;
}

Measured memory_bytes: 1192
const main = (input) => {
  input = input.split(' ');
  const A = parseInt(input[0], 10);
  const B = parseInt(input[1], 10);
  const C = parseInt(input[2], 10);
  
  if (A==B&&A!==C){
    console.log(C);
  }else if(A==C&&A!=B) {
    console.log(B);
  }else{
    console.log(A);
  }
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, i) = in.readLine().split("\\s+").map(_.toInt)

    out.println(n - i + 1)
    out.flush()
  }
}


Measured memory_bytes: 25552
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };

signed main() {
	string s; cin >> s;
	int a[3] = { 0,0,0 };
	rep(i, s.size()) {
		a[s[i] - '0']++;
	}
	cout << min(a[0], a[1]) * 2 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

const int MAX_N=200000;

int par[MAX_N]; //　親
int rnk[MAX_N]; // 木の深さ

// ｎ要素で初期化
void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rnk[i]=0;
  }
}

// 木の根を求める
int find(int x){
  if (par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

// ｘとｙの属する集合を併合
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rnk[x] < rnk[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}

// ｘとｙが同じ集合に属するかどうか
bool same(int x, int y){
  return find(x) == find(y);
}

int main(){
  int n,m;
  cin>>n>>m;
  init(n+m);
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int x;
      cin>>x;
      x--;
      unite(i,x+n);
    }
  }
  for(int i=0;i<n-1;i++){
    if(!same(i,i+1)){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

vector<pair<int, int>> T[20];
int N;

int solve(vector<int> A){
    int cnt = 0;
    rep(i, A.size()) if(A[i] == 1) cnt++;
    rep(i, N){
        if(A[i] == 0) continue;
        rep(j, T[i].size()){
            int person = T[i][j].first;
            int expect = A[person];
            if(expect != T[i][j].second) return 0;
        }
    }
    return cnt;
}

int main(void){
    cin >> N;
    rep(i, N){
        int a; cin >> a;
        rep(j, a){
            int x, y; cin >> x >> y; x--;
            T[i].push_back(make_pair(x, y));
        }
    }

    int ans = 0;
    int loop = pow(2, N);
    rep(i, loop){
        int val = i;
        vector<int> work;
        rep(j, N){
            work.push_back(val % 2);
            val /= 2;
        }
        ans = max(ans, solve(work));
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll pow(ll x, ll y, ll mod) {
    if (y == 0) {
        return 1;
    }
    if (y % 2 == 0) {
        return pow(x * x % mod, y / 2, mod) % mod;
    } else {
        return x * pow(x, y - 1, mod) % mod;
    }
}

const int MAX = 510000;

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


void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

ll f(ll n, ll k) {
    ll res = 1;
    rep2(i, 1, k + 1) {
        res *= (n - i + 1);
        res %= MOD;
        res *= pow(i, MOD-2, MOD);
        res %= MOD;
    }

    return res;
}


void Main() {
    ll N, A, B;
    cin >> N >> A >> B;
    COMinit();
    ll ans = pow(2, N, MOD);
    ans %= MOD;
    ans -= 1;
    ans %= MOD;
    if (ans < 0) ans += MOD;
    ans -= f(N, A);
    ans %= MOD;
    if (ans < 0) ans += MOD;
    ans -= f(N, B);
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans % MOD << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main(){
    ll N; cin >> N;
    ll ans=1e15;
    for (ll i=1; i*i<=N; i++){
        if (N%i==0){
            ans=min(ans,(i-1)+(N/i-1));
        }
    } 
    cout << ans;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MN = 100010;

int N, M;
vi g[MN];
ll dp[MN];
int in[MN];
bool vis[MN];

int main() {
    cin >> N >> M;
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        g[x].pb(y);
        ++in[y];
    }

    queue<int> que;

    rep(i, N) {
        if (in[i] == 0) {
            que.push(i);
        }
    }

    while (!que.empty()) {
        int v = que.front(); que.pop();
        vis[v] = true;
        for (int to : g[v]) {
            dp[to] = max(dp[to], dp[v] + 1);
            if (--in[to] == 0) {
                que.push(to);
            }
        }
    }

    cout << *max_element(dp, dp + N) << endl;

    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#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>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


vector<int> vis(1002);

void solve()
{
   int n,k;
    cin >> n >> k;
    
   f(i,k)
   {
       int v;
       cin >> v;
       
       while(v--)
       {
           int x;
           cin >> x;
           vis[x] = 1;
       }
   }
    
    
   int res = 0;
    
    for(int i=1;i<=n;i++) res+=1-vis[i];
    
    cout <<res;
    
}

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

Measured memory_bytes: 3668
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
		var n = ReadLine();
		var a = new int[26];
		for(int i = 0; i < n.Length; i++)
		{
			a[n[i] - 'a']++;
		}
		for(int i = 0; i < 26; i++)
		{
			if(a[i] == 0)
			{
				WriteLine((char)(i + 'a'));
				return;
			}
		}
		WriteLine("None");
	}
}


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

int main(){
  int n,sa=0,sb=0,ans=100000;
  cin>>n;
  vector<int> w(n);
  for(int i=0; i<n; i++){
    cin>>w[i];
    sa+=w[i];
  }
  for(int i=0; i<n; i++){
    sb+=w[i];
    int c=abs(sa-2*sb);
    ans=min(ans,c);
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int hyo[11][11],n,i,j,k;
	
	while(0<=scanf("%d",&n)){
		if(n==0)
			break;
		
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&hyo[j][i]);
			}
			}
		
		for(i=0;i<n;i++){
			j=0;
			for(k=0;k<n;k++){
				j=j+hyo[k][i];
			}
			hyo[n][i]=j;
			}
		
		for(i=0;i<n;i++){
			j=0;
			for(k=0;k<n;k++){
				j=j+hyo[i][k];
			}
			hyo[i][n]=j;
			}
		j=0;
		for(i=0;i<n;i++){
			j=j+hyo[i][n];
		}
		hyo[n][n]=j;
		
		for(i=0;i<n+1;i++){
		for(j=0;j<n;j++){
			printf("%5d",hyo[j][i]);
		}
		printf("%5d\n",hyo[n][i]);
		}
		}
	return 0;
		}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> vec(3 * n);
  for (ll i = 0; i < 3 * n; ++i) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  ll ans = 0;
  for(long j=3* n-2;n-1<j;j-=2)
    ans += vec[j];
//  debug(ans);
  cout << ans << '\n';
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  vector<int> b(m),c(m);
  for(int j = 0; j < m; j++) {
    cin >> b.at(j) >> c.at(j);
  }
  int l=accumulate(b.begin(), b.end(), 0);
  vector<pair<int, int> > pairs(m);
  for (int j = 0; j < m; j++) {
    pairs[j] = make_pair(c.at(j), b.at(j));
  }
  // firstが小さい順、secondが小さい順にソート
  sort(pairs.begin(), pairs.end());
  reverse(pairs.begin(), pairs.end());
//  for(int j = 0; j < m; j++) {
//    cout << pairs[j].first << endl;
//  }
  int i=0;
  int flag = 0;
  for(int j = 0; j < m; j++) {
    for(int k = 0; k < pairs[j].second; k++){
      if(i==n){
        flag=1;
        break;
      }
      if(a.at(i) > pairs[j].first){
        flag=1;
        ++i;
        break;
      }else{
        a.at(i) = pairs[j].first;
        ++i;
      }
    }
    if(flag==1){
      break;
    }
  }
  long long s=accumulate(a.begin(), a.end(), 0LL);
  cout << s << endl;
}

Measured memory_bytes: 2176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        const long MOD = 1000000007;
        var sc = new Scanner();
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (Math.Abs(a - b) % 2 == 1) Console.WriteLine("IMPOSSIBLE");
        else Console.WriteLine(Math.Max(a, b) - Math.Abs(a - b) / 2);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11220
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class Main {

	static long mergeSort(int arr[], int array_size) {
		int temp[] = new int[array_size];
		return _mergeSort(arr, temp, 0, array_size - 1);
	}

	static long _mergeSort(int arr[], int temp[], int left, int right) {
		int mid;
		long inv_count = 0;
		if (right > left) {

			mid = (right + left) / 2;

			inv_count = _mergeSort(arr, temp, left, mid);
			inv_count += _mergeSort(arr, temp, mid + 1, right);

			inv_count += merge(arr, temp, left, mid + 1, right);
		}
		return inv_count;
	}

	static long merge(int arr[], int temp[], int left, int mid, int right) {
		int i, j, k;
		long inv_count = 0;

		i = left; 
		j = mid; 
		k = left; 
		while ((i <= mid - 1) && (j <= right)) {
			if (arr[i] <= arr[j]) {
				temp[k++] = arr[i++];
			} else {
				temp[k++] = arr[j++];
				inv_count = inv_count + (mid - i);
			}
		}

		while (i <= mid - 1)
			temp[k++] = arr[i++];

		while (j <= right)
			temp[k++] = arr[j++];

		for (i = left; i <= right; i++)
			arr[i] = temp[i];

		return inv_count;
	}
	
	

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i=0;i<n;i++)
			a[i] = sc.nextInt();
		
		int l = 1, r=1000000000;
		while (l<=r) {
			int mid = (l+r)/2;
			if (check(a,mid)) l=mid+1;
			else r=mid-1;
		}
		System.out.println(l);

	}

	private static boolean check(int[] a, int mid) {
		int b[] = new int[a.length+1];
		for (int i=0;i<b.length;i++) {
			if (i==0) {
				b[i] = 0;
				continue;
			}
			else b[i] = b[i-1];
			if (a[i-1]<=mid) b[i]--;
			else b[i]++;
		}
		long num = mergeSort(b,b.length);
		return (num<=(long)(a.length+1)*a.length/4);
	}
}


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

char s[16], t[16];

int main( int argc, char *argv[] )
{
    scanf( "%s %s", s, t );

    if( strlen( s ) +1 != strlen( t ) ) {
        puts( "No" );
        exit( 0 );
    }

    if( strncmp( s, t, strlen( s ) ) ) {
        puts( "No" );
        exit( 0 );
    }

    puts( "Yes" );
}


Measured memory_bytes: 1712
/// Codeforces - ishibly
#include "bits/stdc++.h"

using namespace std;

const int N = 1e5 + 5;

int in[N], dat[N];
int deg[N], seen[N];
vector< int> conn[N];
int dist[N], parent[N];
pair< int, int> p[N];
multiset< int> st;

void dfs(int a, int &node) {
	seen[a] = true;
	for (int &b : conn[a]) {
		if (seen[b]) continue;
		dist[b] = dist[a] + 1;
		if (dist[b] > dist[node]) node = b;
		parent[b] = a;
		dfs(b, node);
	}
}

void dfsx(int a) {
	seen[a] = 1;
	for (int &b : conn[a]) {
		if (seen[b]) continue;
		dfsx(b);
	}
	dat[a] = *st.begin();
	st.erase(st.begin());
}

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i ++) {
		int a, b;
		scanf("%d %d", &a, &b);
		conn[a].emplace_back(b);
		conn[b].emplace_back(a);
		p[i] = {a, b};
	}

	for (int i = 1; i <= n; i++) scanf("%d", dat + i);

	int u, v;	
	dfs(1, u);
	memset(dist, 0, sizeof dist);
	memset(seen, 0, sizeof seen);
	parent[u] = -1;
	dfs(u, v);
	vector< int> path;
	while (v != -1) {
		path.push_back(v);
		v = parent[v];
	}

	int s = path[path.size() / 2];
	for (int i = 1; i <= n; ++i) st.insert(dat[i]);

	memset(seen, 0, sizeof seen);
	dfsx(s);
	long long result = 0;
	for (int i = 0; i < n - 1; ++i) result += min(dat[p[i].first], dat[p[i].second]);
	cout << result << endl;
	for (int i = 1; i <= n; ++i) printf("%d ", dat[i]);
}

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

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt(), M = in.nextInt(), Q = in.nextInt();
            String[] S = new String[N + 1];
            char[] s0 = new char[M + 1];
            Arrays.fill(s0, '_');
            S[0] = new String(s0);
            for (int i = 1; i < N + 1; i++) {
                S[i] = "_" + in.next();
            }
//            System.out.println("S " + Arrays.toString(S));

            int[][] kuro = new int[N + 1][M + 1];
            int[][] tate = new int[N + 1][M + 1];
            int[][] yoko = new int[N + 1][M + 1];
            for (int i = 1; i < N + 1; i++) {
                int ki = 0, ti = 0, yi = 0;
                for (int j = 1; j < M + 1; j++) {
                    kuro[i][j] = kuro[i - 1][j];
                    tate[i][j] = tate[i - 1][j];
                    yoko[i][j] = yoko[i - 1][j];
                    if (S[i].charAt(j) == '1') {
                        ki += 1;
                        if (S[i - 1].charAt(j) == '1') {
                            ti += 1;
                        }
                        if (S[i].charAt(j - 1) == '1') {
                            yi += 1;
                        }
                    }
                    kuro[i][j] += ki;
                    tate[i][j] += ti;
                    yoko[i][j] += yi;
                }
            }
//            System.out.println("kuro " + Arrays.deepToString(kuro));
//            System.out.println("tate " + Arrays.deepToString(tate));
//            System.out.println("yoko " + Arrays.deepToString(yoko));

            StringBuilder ans = new StringBuilder();
            for (int q = 0; q < Q; q++) {
                int x1 = in.nextInt(), y1 = in.nextInt(), x2 = in.nextInt(), y2 = in.nextInt();
                int cum_kuro = cum(kuro, x1, y1, x2, y2);
                int cum_tate = cum(tate, x1 + 1, y1, x2, y2);
                int cum_yoko = cum(yoko, x1, y1 + 1, x2, y2);
//                System.out.println("cums " + cum_kuro + " " + cum_tate + " " + cum_yoko);

                ans.append(cum_kuro - cum_tate - cum_yoko).append('\n');
            }
            System.out.println(ans);
        }
    }

    private static int cum(int[][] mat, int x1, int y1, int x2, int y2) {
        x1 -= 1;
        y1 -= 1;
//        System.out.println(mat[x1][y1]);
//        System.out.println(mat[x2][y2]);
//        System.out.println(mat[x1][y2]);
//        System.out.println(mat[x2][y1]);
        return mat[x1][y1] + mat[x2][y2] - mat[x1][y2] - mat[x2][y1];
    }
}

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

using namespace std;

int main(void)
{
    string input;
    cin >> input;
    if(input[1] == 'B')
    {
        cout << "ARC";
    }
    if(input[1] == 'R')
    {
        cout << "ABC";
    }
}

Measured memory_bytes: 3560
n=gets.to_i
a=gets.split.map(&:to_i)
b=gets.split.map(&:to_i)

ans=0
n.times do |i|
    ans+=[a[i]+a[i+1],b[i]].min
    a[i+1]=[a[i+1]-[b[i]-a[i],0].max,0].max
end
puts ans


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, m; cin >> n >> m;
  vvi g(n);
  vi d(n);
  for(int i=0;i<m;++i) {
    int s, t; cin >> s >> t;
    s--; t--;
    g[s].push_back(t);
    d[s]++;
  }
  
  vector<double> dp(n, 0.0);
  vector<double> dpma(n, 0.0);
  dp[n-1] = 0.0;
  for(int i=n-2;i>=0;--i) {
    double su = 0.0;
    double ma = 0.0;
    for(int j=0;j<SZ(g[i]);++j) {
      su += dp[g[i][j]] + 1;
      ma = max(ma, dp[g[i][j]] + 1);
    }
    dp[i] = su / d[i];
    dpma[i] = ma;
  }
  //printv(dp);

  double ans = INF;
  for(int i=0;i<n-1;++i) {
    vector<double> dp2(n);
    for(int j=i+1;j<n;++j) {
      dp2[j] = dp[j];
    }
    if(d[i] > 1) dp2[i] = (dp[i] * d[i] - dpma[i]) / (d[i] - 1);
    else dp2[i] = dp[i];
    for(int j=i-1;j>=0;--j) {
      double su = 0;
      for(int k=0;k<SZ(g[j]);++k) {
        int nxt = g[j][k];
        su += dp2[nxt] + 1;
      }
      dp2[j] = su / d[j];
    }
    //printv(dp2);
    ans = min(ans, dp2[0]);
  }
  cout << ans << endl;

}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define maxn 100010
using namespace std;
#define G c=getchar()
typedef long long LL;
inline LL read()
{
    LL x=0,f=1;char G;
    while(c>57||c<48){if(c=='-')f=-1;G;}
    while(c>47&&c<58)x=x*10+c-48,G;
    return x*f;
}
LL n,a[maxn];
LL Abs(LL x){return x<0?-x:x;}
LL calc(LL p)
{
	LL s=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		if((s+a[i])*p<=0)ans+=Abs(s+a[i]-p),s=p;
		else s+=a[i];
		p=-p;
	}
	return ans;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	LL ans=min(calc(-1),calc(1));
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
/*********************************************************************************/
/* 0）test(i): i番目のフラグの状態がONの場合1、OFFの場合0を出力する              */
/* 1）set(i):  i番目のフラグをONにする                                           */
/* 2）clear(i):i番目のフラグをOFFにする                                          */
/* 3）flip(i): i番目のフラグを反転する                                           */
/* 4）all:     全てのフラグがONになっている場合1、なっていない場合0を出力する    */
/* 5）any:     何れかのフラグがONになっている場合1、なっていない場合0を出力する  */
/* 6）none:    全てのフラグがOFFになっている場合1、なっていない場合0を出力する   */
/* 7）count:   ONになっているフラグの数を出力する                                */
/* 8）val:     状態の整数値を出力する                                            */
/*********************************************************************************/

#include<stdio.h>

#define BY_8 64

typedef struct order{
	int cmd;
	int num;
}Order;

/*10⇒2変換*/
void di2bi(unsigned long x, int* b){
	int i;
	
	for(i=32-1; i>=0; i--){
		b[i] = (x>>i)&1;
	}
}
/*2⇒10変換*/
unsigned long bi2di(unsigned long *bi_x){
	int i;
	unsigned long di_x = 0;
	
	for(i=0; i<BY_8; i++){
		di_x = di_x + (bi_x[i] << i);
//		printf("%ld ", di_x);
	}
	return di_x;
}
int Flag_Chk(unsigned long *bi_x){
	int i, flag;
	flag = 0;
	
	for(i=0; i<BY_8; i++){
		if(bi_x[i] == 1) flag +=1;
	}
	return flag;
}
	

void Cmd_Exe(unsigned long *bi_x, int cmd, int num){
	int di_x, flag;
	flag = Flag_Chk(bi_x);
	di_x = bi2di(bi_x);
	switch (cmd){
		case 0:
			if(bi_x[num] == 1){
				printf("1\n");
			}else{
				printf("0\n");
			}
			break;
		case 1:
			bi_x[num] = 1;
			break;
		case 2:
			bi_x[num] = 0;
			break;
		case 3:
			bi_x[num] = bi_x[num]^1;
			break;
		case 4:
			if(flag == 64){
				printf("1\n");
			}else{
				printf("0\n");
			}
			break;
		case 5:
			if(flag > 0){
				printf("1\n");
			}else{
				printf("0\n");
			}
			break;
		case 6:
			if(flag == 0){
				printf("1\n");
			}else{
				printf("0\n");
			}
			break;
		case 7:
			printf("%d\n", flag);
			break;
		case 8:
			printf("%lu\n", bi2di(bi_x));
			break;
		default:
			break;
	}
}

int main(){
	int i, num;
	Order Ord[200001];
	unsigned long x;
	unsigned long bi_x[BY_8] = {0};
	
	scanf("%d", &num);
	
	for(i=0; i<num; i++){
		scanf("%d", &Ord[i].cmd);
		if(Ord[i].cmd < 4){
			scanf("%d", &Ord[i].num);
		}else{
			getchar();
		}
	}
	
	for(i=0; i<num; i++){
		Cmd_Exe(bi_x, Ord[i].cmd, Ord[i].num);
	}
	
	return 0;
}


Measured memory_bytes: 3272
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int X;
    cin >> X;
    int max_count = X / 100;
    int a = X % 100;
    //cout << a << endl;
    int count = 0;
    int n = 0;
    for (int i=5; 0<i; i--){
        n = a / i;
        count += n;
        a = a - n * i;
        if(max_count < count){
            cout << "0" << endl;
            break;
        }
        if (a == 0){
            cout << "1" << endl;
            break;
        }
    }
    return 0;
}


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

using namespace std;
const int maxn = 505;
typedef long long ll;
const int mod = 1e9 + 7;
const ll inf = 1e18;
ll sum[maxn], dp[maxn][maxn];
int a[maxn];

int main() {
//    freopen("in.in", "r", stdin);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            dp[i][j] = inf;
        }
        dp[i][i] = 0;
    }
    ll ans = 0;
    for (int len = 1; len <= n; len++) {
        for (int i = 1; i <= n; i++) {
            int j = i + len;
            if (j > n) break;
            for (int k = i; k < j; k++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
            }
            ll t = dp[i][j];
            dp[i][j] += sum[j] - sum[i - 1];

        }
    }
    cout << dp[1][n] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>

#define f(i,x) for(int i=0;i<x;i++)


using namespace std;

int main()
{
	string a;
	cin >> a;
	cout << "ABC" + a ;

	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){

	int m1,m2,d1,d2;
	cin >> m1 >> d1
		>> m2 >> d2;
	if (m1 < m2)
	{
		cout << "1"<< endl;
	}
	else cout << "0"<<endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
#define mod 1000000007
#define ln "\n"
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define f first
#define s second
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fio;
    ll t;
    cin>>t;
    string s[t];
    string str1="AC";
    string str2="WA";
    string str3="TLE";
   string  str4="RE";
    ll c0=0,c1=0,c2=0,c3=0;
    for(ll i=0;i<t;i++)
    {
        cin>>s[i];
        if(s[i]==str1)
            c0++;
        else if(s[i]==str2)
            c1++;
        else if(s[i]==str3)
            c2++;
        else if(s[i]==str4)
            c3++;
    }
    cout<<"AC x "<<c0<<ln;
    cout<<"WA x "<<c1<<ln;
    cout<<"TLE x "<<c2<<ln;
    cout<<"RE x "<<c3<<ln;
    return 0; 
} 

Measured memory_bytes: 6744
#include <iostream>
#include <string>

using namespace std;

bool isPalindrome( string str, int len )
{
  int cnt = 0;
  
  while ( cnt < (len - cnt - 1) ) {
    if ( str[cnt] != str[len - cnt - 1] ) {
      return false;
    }
    
    cnt++;
  }
  
  return true;
}


int main( void )
{
  string str;
  cin >> str;
  
  int len = str.length();
  
  cout << ((isPalindrome(str, len) && isPalindrome(str, len / 2)) ? "Yes" : "No") << endl;
  
  return 0;
}

Measured memory_bytes: 256
def rec (i,a,b,c):
    if i==N:
        if a==0 or b==0 or c==0:
            return INF
        else:
            return abs(a-A)+abs(b-B)+abs(c-C)
    res = rec(i+1,a,b,c)
    
    res = min(res,rec(i+1,a+L[i],b,c)+(10 if a>0 else 0))
    res = min(res,rec(i+1,a,b+L[i],c)+(10 if b>0 else 0))
    res = min(res,rec(i+1,a,b,c+L[i])+(10 if c>0 else 0))
    
    return res
N,A,B,C = list(map(int,input().split()))
INF=10**8
L = [int(input()) for _ in range(N)]
print(rec(0,0,0,0))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<algorithm>
#define lint long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define PI 3.14159265358979323846264338327950288
using namespace std;

int main(){
  int w,h;
  while(1){
    cin>>h>>w;
    if(h==0&&w==0)break;
    rep(i,h){
      rep(j,w){
        cout<<"#";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#define MAX_N 1000000
using namespace std;

int main(){
    long int n;
    while(cin >>n){
        if(n == -1) break;
        vector<int> vec;
        int shift = 0;
        for(long int i = 3; i <= MAX_N; i = i << 2){
            int tmp = n & i;
            for(int j = 0; j < shift; j++){
                tmp = tmp >> 2;
            }
            shift++;
            vec.push_back(tmp);
        }
        int stop = vec.size() - 1;
        while(vec[stop] == 0){
            stop--;
            if(stop < 0) break;
        }
        if(stop < 0){
            cout <<"0" <<endl;
        } else{
            for(int i = stop; i >= 0; i--){
                cout <<vec[i];
            }
            cout <<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
 
using namespace std;
int main(){
string s;
cin>> s;
int ans=700;
if(s[0]=='o')ans+=100;
if(s[1]=='o')ans+=100;
if(s[2]=='o')ans+=100;
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,i,c=0,d=0,n,m,t,j;
cin>>n;
long long A[n];
for(i=0;i<n;i++)
cin>>A[i];
sort(A,A+n);
for(i=0;i<n-1;i++)
{
  if(A[i]==A[i+1])
  {
    c+=2;
    i++;
  }
}
std::cout <<n-c<< '\n';
return 0;
}


Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
#define     ll      long long int
vector<ll>v;
set<char>st;
int main()
{
    ll n;
    cin>>n;
    if(n%1000==0){
        cout<<0<<endl;
    }
    else{
        ll bagses=n%1000;
        cout<<1000-bagses<<endl;
    }
    return 0;
}


Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        int s = fs.nextInt();
        Set<Integer> seen = new HashSet<>();
        seen.add(s);
        for (int i = 1; true; i++) {
            if (s % 2 != 0) {
                s = (3 * s) + 1;
            } else {
                s /= 2;
            }
            if (!seen.add(s)) {
                System.out.println(i + 1);
                break;
            }
        }
    }

    static final class Utils {
        public static void shuffleSort(int[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffleSort(long[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffle(int[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void shuffle(long[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void swap(int[] arr, int i, int j) {
            final int t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        public static void swap(long[] arr, int i, int j) {
            final long t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        private Utils() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

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


Measured memory_bytes: 32300
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








int main(){
    int N, M; std::cin >> N >> M;
    std::cout << ((1900*M + 100*(N-M)) << M) << std::endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int dist(int x1, int x2, int y1, int y2) {
    return abs(x1-x2) + abs(y1-y2);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    vi a(n), b(n), c(m), d(m);
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, m) cin >> c[i] >> d[i];

    rep(i, n) {
        int ans = 0;
        int mn = 1001001001;
        rep(j, m) {
            if (chmin(mn, dist(a[i], c[j], b[i], d[j]))) {
                ans = j+1;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <set>

using namespace std;

int main() {
    int n;
    set<int> se;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int d;
        scanf("%d", &d);
        se.insert(d);
    }
    printf("%ld\n", se.size());
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int insertionSort(int *a, int n, int g){
    int i, j, v;
    int cnt = 0;
    for(i=g;i<n;i++){
        v = a[i];
        j = i - g;
        while(j>=0&&a[j]>v){
            a[j+g] = a[j];
            j -= g;
            cnt++;
        }
        a[j+g] = v;
    }
    return cnt;
}

int shellSort(int *a, int n){
    int cnt = 0;
    int i;
    int m = int(log(n)/log(2)) + 1;
    printf("%d\n",m);
    int *g = new int [m];
    for(i=0;i<m;i++){
        g[i] = pow(2,m-1-i);
    }
    for(i=0;i<m;i++){
        if(i>0)printf(" ");
        printf("%d",g[i]);
    }
    printf("\n");
    for(i=0;i<m;i++)cnt+=insertionSort(a,n,g[i]);
    return cnt;
}

int main(){
    int i, n, cnt;
    scanf("%d",&n);
    int *a = new int [n];
    for(i=0;i<n;i++){
        scanf("%d",a+i);
    }
    cnt = shellSort(a,n);
    printf("%d\n",cnt);
    for(i=0;i<n;i++){
        printf("%d\n",a[i]);
    }
    return 0;
}



Measured memory_bytes: 6888
n,m = gets.split.map(&:to_i)
cost = n.times.map{Array.new(n, 10**9)}
n.times{|i|cost[i][i] = 0}
path = m.times.map{
  x = gets.split.map(&:to_i)
  a,b,c = x
  cost[a-1][b-1] = c
  cost[b-1][a-1] = c
  x
}

n.times{|k|
  n.times{|i|
    n.times{|j|
      cost[i][j] = cost[i][k] + cost[k][j] if cost[i][j] > cost[i][k] + cost[k][j]
    }
  }
}

ans = 0
path.each{|a,b,c|
  ans+=1 if cost[a-1][b-1] < c
}

p ans

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

#define ll long long int
#define f(i,n) for(ll i = 0; i < n ; i++)
#define F first 
#define pb push_back
#define S second
using namespace std;
ll dp[100001];
ll solve(ll a[], ll n)
{
  if(n <= 0)
    return 0;
  if(dp[n] != -1)
    return dp[n];

  return dp[n] = min(abs(a[n] - a[n-1]) + solve(a,n-1),abs(a[n] - a[n-2]) + solve(a,n-2));
}


 
int main()
{

     #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
     #endif
     
         ll n ;
         cin>>n;
         ll a[n];
 
         f(i,n)
         {
            cin>>a[i];
         }
         memset(dp,-1,sizeof(dp)); 
         cout<<solve(a,n-1);
   return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 * 1000 + 13;

int n;
int h[N];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n)
		scanf("%d", &h[i]);
	return true;
}

li dp[N];

void solve() {
	forn(i, n + 1) dp[i] = INF64;
	dp[0] = 0;
	forn(i, n){
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		if (i + 2 < n)
			dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	printf("%lld\n", dp[n - 1]);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {	
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 1408
n,m = map(int, input().split())
data = []
for i in range(m):
    data.append(list(map(int, input().split())))

not_bridge = 0
def dfs(node, finished):
    finished.add(node)
    global not_bridge
    if len(finished) == n:
        not_bridge += 1
    else:
        for i in adjacent_list[node]:
            if i not in finished:
                dfs(i, finished)
    
#iが省く要素
for i in range(m):
    adjacent_list = [[]for i in range(n+1)]
    finished = set()
    for j in range(m):
        if i != j:
            a, b = data[j]
            adjacent_list[a].append(b)
            adjacent_list[b].append(a)
    dfs(1, finished)
print(m - not_bridge)


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

vector<vector<int>> edge;
ll ans;
ll ans_leaf = -1;

void calc(int a, int b) {
    vector<pair<int, int>> root;
    bool nopar;
    ll al_cand = 1;
    if (b == -1) {
        root.push_back({a, -1});
        nopar = true;
    }else {
        root.push_back({a, b});
        root.push_back({b, a});
        nopar = false;
        al_cand = 2;
    }
    while (!root.empty()) {
        vector<pair<int, int>> root_nxt;
        ll dup = 1;
        for (auto p : root) {
            int now = p.first;
            int par = p.second;
            for (int nxt : edge[now]) {
                if (nxt == par) continue;
                root_nxt.push_back({nxt, now});
            }
            if (nopar) {
                dup = max(dup, (ll)edge[now].size());
                nopar = false;
            }else {
                dup = max(dup, (ll)edge[now].size()-1);
            }
        }
        al_cand *= dup;
        root = root_nxt;
    }
    if (ans_leaf < 0 || ans_leaf > al_cand) ans_leaf = al_cand;
    return;
}

int main() {
    int N;
    cin >> N;
    edge.resize(N+1);
    vector<vector<int>> dist(N+1, vector<int>(N+1, 999));
    
    for (int i = 1; i <= N; i++) dist[i][i] = 0;
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
        dist[a][b] = 1;
        dist[b][a] = 1;
    }
    
    for (int k = 1; k <= N; k++) {
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    
    int dl_max = N;
    vector<int> dist_from_leaf(N+1, 0);
    for (int i = 1; i <= N; i++) {
        int d_max = 0;
        for (int j = 1; j <= N; j++) {
            d_max = max(d_max, dist[i][j]);
        }
        dist_from_leaf[i] = d_max;
        dl_max = min(dist_from_leaf[i], dl_max);
    }
    vector<pair<int, int>> root;
    vector<int> kariroot;
    for (int i = 1; i <= N; i++) {
        if (dist_from_leaf[i] == dl_max) kariroot.push_back(i);
    }
    
    if ((int)kariroot.size() == 1) {
        ans = dl_max+1;
        int cen = kariroot[0];
        calc(cen, -1);
        for (int nxt : edge[cen]) {
            calc(cen, nxt);
        }
    }else if ((int)kariroot.size() == 2) {
        ans = dl_max;
        calc(kariroot[0], kariroot[1]);
    }
    cout << ans << " " << ans_leaf << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>

using namespace std;

int main(){
    int n;
    cin >> n;
    string s[n+1];
    for(int i=1;i<=n;i++) cin >> s[i];

    int dp[n+1], dpmin[26];
    fill(dpmin, dpmin+26, n);
    dpmin[s[1][0]-'a'] = 0;
    for(int i=1;i<=n;i++){
        char start_char = s[i][0], end_char = s[i][s[i].length()-1];
        dp[i] = dpmin[start_char-'a'] + 1;
        dpmin[end_char-'a'] = min(dpmin[end_char-'a'], dp[i]);
    }

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


Measured memory_bytes: 10004
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;

map<pair<ll, ll>, ll> M, MS;
ll d2[200010];
ll zc = 0;

ll my_gcd(ll x, ll y) {
	if (x < 0)x = -x;
	if (y < 0)y = -y;
	while (x) {
		y %= x;
		swap(x, y);
	}
	return y;
}

int main() {
	d2[0] = 1;
	for (int i = 1;i < 200010;i++) {
		d2[i] = d2[i - 1] * 2 % MOD;
	}
	ll N, g, c, d;
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> c >> d;
		if (c == 0 || d == 0) {
			if (c == 0 && d == 0) {
				zc++;
				continue;
			}
			if (c == 0)d = -1;
			else c = 1, d = 0;

			if (M.count({ c,d }))M[{c, d}]++;
			else M.insert({ {c,d},1 });

			continue;
		}
		g = my_gcd(c, d);
		c /= g;
		d /= g;
		if (c < 0) {
			c = -c;
			d = -d;
		}
		if (M.count({ c,d }))M[{c, d}]++;
		else M.insert({ {c,d},1 });
	}
	MS = M;
	pair<ll, ll> P;
	ll x, y, sa, fa = 1;
	set<pair<ll, ll>> S;
	for (auto a : MS) {
		tie(P, y) = a;
		if (S.count(P))continue;
		tie(c, d) = P;
		swap(c, d);

		c = -c;
		if (c <= 0)c = -c, d = -d;

		if (M.count({ c,d })) {
			x = M[{c, d}];
			sa = d2[x] + d2[y] - 1;
			fa *= sa % MOD;
			fa %= MOD;
			S.insert({ c,d });
		}
		else {
			sa = d2[y];
			fa *= sa;
			fa %= MOD;
		}
	}
	fa += zc - 1;
	if (fa < 0)fa += MOD;
	fa %= MOD;
	cout << fa << endl;
}

Measured memory_bytes: 30040
#include<stdio.h>
#include<iostream>
#include<map>
using namespace std;
long long cou;
long long i,j,t,n,k,s;
map<long long,int> mapAns;
map<long long,int>::iterator iter;
int main()
{
    
    while(scanf("%lld %lld",&n,&k)!=EOF)
{
    mapAns[0]=1;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&t);    
        s+=t;
        if(s>=k)s=s%k;
        mapAns[s]++;
    }
    for(iter=mapAns.begin();iter!=mapAns.end();++iter)
    {
        t=iter->second;
        if(t>1)
        {
            cou+=t*(t-1)/2;
        }
    }
    printf("%lld",cou);
}
    return 0;
}

Measured memory_bytes: 4224
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    if N == 1:
        print('Hello World')
    else:
        A, B = map(int, read().split())
        print(A + B)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9100