akhauriyash/Code-Regression huggingface dataset:
//--------------------------------------------------
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <stack>
#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.1415926;
//----------------------------------------------------
//#define endl '\n';
#ifdef MY_DEBUG
void deb(ld x) { cerr << x << endl; };
#else
void deb(ld x){};
#endif
//----------------------------------------------------
//----------------------------------------------------
bool used[2][3001][3001];
ll dp[2][3001][3001];
ll a[3000];
ll n;
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    forn(i, n) cin >> a[i];
}

ll cnt(uint tp, int l, int r){
    if(l > r)
        return 0;
    if(used[tp][l][r]) return dp[tp][l][r];
    used[tp][l][r] = true;
    if(tp == 0){
        dp[tp][l][r] = max(cnt(tp^1u, l+1, r) + a[l], cnt(tp^1u, l, r-1) + a[r]);
    }else{
        dp[tp][l][r] = min(cnt(tp^1u, l+1, r)-a[l], cnt(tp^1u, l, r-1) -a[r]);
    }

    return dp[tp][l][r];
}

int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    cout << cnt(0, 0, n-1);

}

Measured memory_bytes: 158848
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,q,a,t,x;
    cin >> n;
    std::vector<int> vec[n];
    cin >> q;
    for (int i=0;i<q;i++) {
        cin >> a >> t;
        if ( a==0 ) {
            cin >> x;
            vec[t].emplace_back(x);
        } else if ( a==1 ) {
            if ( vec[t].empty()!=true ) {
                for (int j=0;j<vec[t].size();j++) {
                if ( j==vec[t].size()-1 ) {
                    cout << vec[t][j] << endl;
                } else {
                    cout << vec[t][j] << " ";
                }
                }
            } else {
                cout << endl;
            }
        } else if ( a==2 ) {
            if ( vec[t].empty()!=true ) {
                vec[t].clear();
                vec[t].shrink_to_fit();
            }
        }
    }
}



Measured memory_bytes: 5920
import sys


def solve(n, aaa):
    if n == 2:
        h, m = divmod(sum(aaa), 2)
        if m == 1 or h > aaa[0]:
            return -1
        return aaa[0] - h

    x = 0
    for a in aaa[2:]:
        x ^= a
    a0, a1 = aaa[:2]
    s = a0 + a1

    if s & 1 != x & 1:
        return -1

    p, q = 0, 0

    b = 1 << 40
    swappable = []
    while b:
        bx = x & b
        if bx == 0:
            # print('bx=0', s)
            # print(f'{b:040b}')
            # print(f'{p:040b}')
            # print(f'{q:040b}')
            # print(f'{a0:040b}')
            # print(f'{a1:040b}')
            # print()
            if s >= 2 * b:
                if p | b <= a0:
                    p |= b
                    q |= b
                    s -= 2 * b
                elif swappable:
                    bs = swappable.pop()
                    p ^= bs
                    q ^= bs
                    p |= b
                    q |= b
                    s -= 2 * b
                else:
                    return -1
        else:
            if s < b:
                return -1
            if p | b <= a0 and q | b > a1:
                p |= b
                swappable.append(b)
            else:
                q |= b
            s -= b

            # print('bx=1', s)
            # print(f'{b:040b}')
            # print(f'{p:040b}')
            # print(f'{q:040b}')
            # print(f'{a0:040b}')
            # print(f'{a1:040b}')
            # print()

        b >>= 1

    if p == 0:
        return -1
    assert s == 0
    assert p ^ q == x
    assert a0 - p == q - a1
    return a0 - p


n, *aaa = map(int, sys.stdin.buffer.read().split())
print(solve(n, aaa))


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

#define fl(k, n) for(int i = k; i < n; i++)
#define flr(k, n) for(int i = n - 1; i >= k; i--)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define ll long long
#define llu long long unsigned int
#define mod 1000000007

using namespace std;

int binary_search(vector<int> nums, int target_val){
  int begin = 0;
  int end = nums.size();
  int mid;

  while(begin <= end){
    mid = begin + (end - begin) / 2;
    if(nums[mid] == target_val)
      return mid;
    else if(nums[mid] <= target_val && nums[mid + 1] > target_val)
      return mid;
    else if(nums[mid] > target_val)
      end = mid - 1;
    else
      begin = mid + 1;
  }

  if(begin == 0)
    return -1;
  else 
    return nums.size();
}

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

  int n, k;
  cin >> n >> k;

  vi stones(n);
  fl(0, n)
    cin >> stones[i];

  vector<bool> fp(k + 1);
  fl(0, k + 1){
    for(int a: stones){
      if(i >= a && !fp[i - a])
        fp[i] = true;
    }
  }

  if(fp[k])
    cout << "First\n";
  else
    cout << "Second\n";

}

Measured memory_bytes: 3668
n, m, x = list(map(int, input().split()))
A = list(map(int, input().split()))

zero_g = 0
n_g = 0

for i in range(len(A)):
    if A[i] < x:
        zero_g += 1
    else:
        n_g += 1
print(min(n_g, zero_g))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <deque>
#include <array>
#include <cmath>

using namespace std;

int main()
{
  int n;

  cin >> n;

  long long sum = 0;
  for (int i = 1; i <= n; i++)
  {
    if (i % 3 != 0 && i % 5 != 0)
    {
      sum += i;
    }
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <cstdio>

const int N=200005;

int fst[N],dep[N],d[N],a[N],b[N],fa[N],tot=0,ans=0;
bool u[N];
struct Edge{
	int to,nxt;
}e[N*2];

void addedge(int x,int y){
	e[++tot].to=y;e[tot].nxt=fst[x];fst[x]=tot;
}

void dfs(int x){
	for (int i=fst[x];i;i=e[i].nxt){
		int y=e[i].to;
		if (y!=fa[x]){
			fa[y]=x;
			dep[y]=dep[x]+1;
			dfs(y);
		}
	}
}

void dfs2(int x,int v){
	if (ans==-1 || d[x]>=dep[x]) return;
	if (u[x]) ans=-1;
		else if (dep[x]*2>ans) ans=dep[x]*2;
	for (int i=fst[x];i;i=e[i].nxt){
		int y=e[i].to;
		if (y!=v){
			d[y]=d[x]+1;
			dfs2(y,x);
		}
	}
}

int main(){
	int n,X,Y;
	scanf("%d%d%d",&n,&X,&Y);
	for (int i=1;i<n;i++) scanf("%d%d\n",&a[i],&b[i]);
	for (int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(x,y);
		addedge(y,x);
	}
	dfs(Y);
	for (int i=1;i<=n;i++) fst[i]=0;
	tot=0;
	for (int i=1;i<n;i++){
		int x=a[i],y=b[i],fx=fa[x],fy=fa[y];
		if (fx==y||fy==x||fa[fx]==y||fa[fy]==x||fx==fy) addedge(x,y),addedge(y,x);
			else u[x]=u[y]=1;
	}
	dfs2(X,0);
	printf("%d\n",ans);
}

Measured memory_bytes: 14208
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int time=sc.nextInt();
		int c[][]=new int[n][2];
		for(int i=0;i<n;i++) {
			c[i][0]=sc.nextInt();
			c[i][1]=sc.nextInt();
		}
		int min=1001;
	    for(int i=0;i<n;i++) {
	    	if(c[i][1]<=time) {
	    		if(min>c[i][0]) {
	    			min=c[i][0];
	    		}
	    	}
	    }
	    if(min==1001)
	    	System.out.println("TLE");
	    else
	    	System.out.println(min);
		

	}

}

Measured memory_bytes: 23892
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>

typedef struct Point
{
	double x, y;
}pnt;

void koch(int n, pnt a, pnt b)
{
	if (n == 0) return;
	pnt s, t, u;
	double th = M_PI * 60.0 / 180.0;
	s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
	s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
	t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
	t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
	u.x = (t.x - s.x)*cos(th) - (t.y - s.y)  * sin(th) + s.x;
	u.y = (t.x - s.x)*sin(th) + (t.y - s.y) * cos(th) + s.y;

	koch(n - 1, a, s);
	printf("%.8f %.8f\n", s.x, s.y);
	koch(n - 1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	koch(n - 1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	koch(n - 1, t, b);
}

int main()
{
	pnt a, b;
	int n;

	scanf("%d", &n);

	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;

	printf("%.8f %.8f\n", a.x, a.y);
	koch(n, a, b);
	printf("%.8f %.8f\n", b.x, b.y);

	return 0;
}


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

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var count = 0L;
            for (int i = 1; i <= N; i++)
            {
                count += i;
            }
            return count;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 27336
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    idx1 = S.index("A")
    S_r = S[::-1]
    idx2 = S_r.index("Z")
    idx2 = len(S) - 1 - idx2
    print(idx2-idx1+1)
if __name__ == '__main__':
    main()

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

void replace(string& str,string& target,string& replacement){
	if (!target.empty()) {
    std::string::size_type pos = 0;
    while ((pos = str.find(target, pos)) != std::string::npos) {
      str.replace(pos, target.length(), replacement);
      //pos += replacement.length();
      pos = 0;
    }
  }
}
int main(){
  string str;
  cin >> str;
  std::string target = ",";     // 検索文字列
  std::string replacement = " "; // 置換文字列
  replace(str,target,replacement);
  
  cout<<  str <<endl;
}

Measured memory_bytes: 256
class Dice

  def initialize( given_ary )
    @ary = given_ary
  end

  def topface( val )
    4.times do
      self.roll( "E" )
      if self.top == val
        return
      end
    end
    3.times do
      self.roll( "N" )
      if self.top == val
        return
      end
    end
  end

  def frontface( val )
    4.times do
      tmp = @ary[1]
      @ary[1] = @ary[2]
      @ary[2] = @ary[4]
      @ary[4] = @ary[3]
      @ary[3] = tmp
      if @ary[1] == val
        return
      end
    end
  end

  def checkall( givendice )
    4.times do
      self.roll( "E" )
      4.times do
        tmp = @ary[1]
        @ary[1] = @ary[2]
        @ary[2] = @ary[4]
        @ary[4] = @ary[3]
        @ary[3] = tmp
        if identical( givendice )
          return true
        end
      end
    end
    3.times do
      self.roll( "N" )
      4.times do
        tmp = @ary[1]
        @ary[1] = @ary[2]
        @ary[2] = @ary[4]
        @ary[4] = @ary[3]
        @ary[3] = tmp
        if identical( givendice )
          return true
        end
      end
    end
    return false
  end

  def roll( direction )
    case direction.downcase
    when "e"
      tmp = @ary[0]
      @ary[0] = @ary[3]
      @ary[3] = @ary[5]
      @ary[5] = @ary[2]
      @ary[2] = tmp
    when "w"
      tmp = @ary[0]
      @ary[0] = @ary[2]
      @ary[2] = @ary[5]
      @ary[5] = @ary[3]
      @ary[3] = tmp
    when "s"
      tmp = @ary[0]
      @ary[0] = @ary[4]
      @ary[4] = @ary[5]
      @ary[5] = @ary[1]
      @ary[1] = tmp
    when "n"
      tmp = @ary[0]
      @ary[0] = @ary[1]
      @ary[1] = @ary[5]
      @ary[5] = @ary[4]
      @ary[4] = tmp
    end
  end

  def top
    @ary[ 0 ]
  end

  def front
    @ary[ 5 ]
  end

  def right
    @ary[ 2 ]
  end

  def vals
    @ary
  end

  def compare( givendice )
    4.times do
      self.roll( "E" )
      if identical( givendice )
        return true
      end
    end
    3.times do
      self.roll( "N" )
      if identical( givendice )
        return true
      end
      4.times do
      self.roll( "E" )
      if identical( givendice )
        return true
      end
    end

    end
    false

  end

  def identical( givendice )
    @ary.zip( givendice.vals ).map{ | x, y | ( x - y ).abs }.inject(:+) == 0
  end

end


dice1 = Dice.new( gets.split.map(&:to_i) )
dice2 = Dice.new( gets.split.map(&:to_i) )
puts ( dice1.checkall( dice2 ) )? "Yes": "No"

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

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

    if (S == "abc" || S == "acb" || S == "bac" || S == "bca" || S == "cab" || S == "cba") cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    string s;
    int i, t;
    do{
        cin >> s;
        if ((int)s[0]-48 == 0)
            break;
        i = 0, t = 0;
        while (s[i])
        {
            t += ((int)s[i] - 48);
            i++;
        }
        cout << t << endl;
    } while (1);
    return 0;
}

Measured memory_bytes: 3136
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <bitset>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define ll long long
#define N 200100
#define M 1000000007
using namespace std;

ll n,m,mx,ans,dp[N],qz[N];
char str[N];

inline void Add(ll &u,ll v){u=(u+v)%M;}
int main()
{
	ll i,j,t;
	cin>>n>>m;
	scanf("%s",str+1);
	for(i=1;i<=m;i++) if(str[i]!=str[1]) break;
	mx=i-1;
	if(mx==m)
	{
		dp[0]=qz[0]=ans=1;
		for(i=0;i<=n;i++)
		{
			if(i>=2) dp[i]=qz[i-2];
			qz[i]=(qz[i-1]+dp[i])%M;
			if(n-i>=2) Add(ans,dp[i]*(n-i)%M);
		}
		cout<<ans;
		return 0;
	}
	if(n&1)
	{
		puts("0");
		return 0;
	}
	if(mx%2==0) mx++;
	for(t=0;i<=m;i++)
	{
		if(str[i]==str[1]) t++;
		else
		{
			if(t&1) mx=min(mx,t);
			t=0;
		}
	}
	n/=2,mx=(mx+1)/2;
	dp[0]=qz[0]=1;
	for(i=0;i<=n;i++)
	{
		if(i)
		{
			dp[i]=(M+qz[i-1]-(i-mx-1>=0?qz[i-mx-1]:0))%M;
			qz[i]=(qz[i-1]+dp[i])%M;
		}
		if(n-i<=mx) Add(ans,(n-i)*dp[i]*2%M);
	}
	cout<<ans;
}

Measured memory_bytes: 6536
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int keta(int x){
	int tmp = 0;
	while(x){
		x /= 10;
		tmp++;
	}
	return tmp;
}

signed main(){
	int n,ans = 0;
	cin >> n;
	for(int i = 1;i <= n;i++){
		if(keta(i) % 2) ans++;
	}
	cout << ans << endl;
}

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

using namespace std;

const int INF = 1 << 29;

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

	int left[100], right[100];
	int m[100][100];

	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			m[i][j] = INF;

	for(int i = 0; i < n; i++)
	{
		cin >> left[i] >> right[i];
		m[i][i] = 0;
	}

	for(int l = 1; l < n; l++)
	{
		for(int i = 0; i < n - l; i++)
		{
			int j = i + l;
			for(int k = i; k < j; k++)
			{
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + left[i] * right[k] * right[j]);
			}
		}
	}

	printf("%d\n", m[0][n - 1]);	
}


Measured memory_bytes: 3244
#include <iostream>
using namespace std;
long long f[10000];
int main()
{
    int n;
    f[0]=2;
    cin>>n;
    for(int i=1;i<=n;i++)
    f[i]=f[i-1]*2+2;
    cout<<f[n]<<endl;
    return 0;
}


//f[n]=f[n-1]*2+2

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

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

  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }

  int sum = a;
  for (int i = 0; ; i ++) {
    if (sum >= b) {
      cout << i + 1 << endl;
      return 0;
    } else {
      sum += (a - 1);
    }
  }
}

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

int main() {
	int one, two, thr, home;
	cin >> one >> two >> thr >> home;
	int sum = one + two + thr + home;
	int minute = sum / 60;
	cout << minute << endl;
	cout << sum - minute * 60 << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int i,m,n,c=0,s=0,l;
  cin>>n>>m;
  int a[n];
  for(i=0;i<n;i++)
  {
    cin>>a[i];
    s+=a[i];
  }
  l=ceil(s/(4.0*m));
  sort(a,a+n);
  for(i=n-1;i>=0;i--)
  {
    if(a[i]>=l)
      c++;
    else
      break;
  }
  if(c<m)
    cout<<"No\n";
  else
    cout<<"Yes\n";
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n = int(input())
h = list(map(int,input().split()))

inf=float("inf")
h += [inf]

cur_max_move = 0
cur_h = h[0]
cur_move = 0
for i in h[1::]:
    if i <= cur_h:
        cur_move+=1
        cur_h=i
    else:
        cur_h=i
        cur_max_move = max(cur_max_move,cur_move)
        cur_move=0
print(cur_max_move)

Measured memory_bytes: 14252
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <set>

using namespace std;

typedef long long lli;
typedef pair<int,lli> ip;

lli x[100001], v[100001], c;
int n;

lli process() {
	lli sum=0, res=0;
	for(int i=0;i<n;i++) {
		sum+=v[i];
		res=max(res,sum-x[i]);
	}
	set<ip> s;
	sum=0;
	for(int i=n-1;i>=0;i--) {
		sum+=v[i];
		if(sum-(c-x[i])<=0) continue;
		if(s.empty() || sum-(c-x[i])>(*s.begin()).second)
			s.insert(ip(i,sum-(c-x[i])));
	}
	sum=0;
	for(int i=0;i<n;i++) {
		sum+=v[i];
		lli val=sum-2*x[i];
		set<ip>::iterator it=s.lower_bound(ip(i+1,-1));
		if(it!=s.end()) val+=it->second;
		res=max(res,val);
	}
	return res;
}

int main() {
	scanf("%d %lld",&n,&c);
	for(int i=0;i<n;i++)
		scanf("%lld %lld",&x[i],&v[i]);
	lli res=process();
	for(int i=0;i<n;i++)
		x[i]=c-x[i];
	reverse(x,x+n);
	reverse(v,v+n);
	printf("%lld\n",max(res,process()));
	return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>

int main(){
  int n = 0;
  char str[10000] = {};
  int i = 0;
  int letnum = 0;
  char let = 'Z';
  
  scanf("%d",&n);
  scanf(" %s",str);
  // printf("%s",str);
  for(i=0;;i++){
    if(str[i] == '\0'){
      break;
    }
  }
  letnum = i;
  // printf("%d",i);
  for(i=0;i<letnum;i++){
    str[i] += n;
    if(str[i] > 90){
      str[i] -= 26;
    }
  }
  
  printf("%s",str);
  
   
  // A = 65 Z = 90
  return 0;
}
  

Measured memory_bytes: 128
X,K,D = map(int,input().split())
X = abs(X)
if X - D * K >= 0:
    print(X - D * K)
else:
    n = X // D
    X -= n * D
    if (K - n) % 2 == 0:
        print(X)
    else:
        print(abs(X - D))

Measured memory_bytes: 9108
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1LL << 60;

class SegTree {
 private:
  const ll def_val_ = 0;
  vl val_;
  ll n_;

  ll comp(ll l, ll r) { return min(l, r); }
  ll getr(ll x, ll y, ll k, ll l, ll r) {
    if (y <= l || r <= x) return def_val_;
    if (x <= l && r <= y) return val_[k];
    auto vl = getr(x, y, 2 * k + 1, l, (l + r) / 2);
    auto vr = getr(x, y, 2 * k + 2, (l + r) / 2, r);
    return comp(vl, vr);
  }

 public:
  SegTree(ll size) {
    n_ = 1;
    while (n_ < size) n_ *= 2;
    val_ = vl(2 * n_, def_val_);
  }
  void update(ll i, ll v) {
    i += (n_ - 1);
    val_[i] = v;
    while (i > 0) {
      i = (i - 1) / 2;
      val_[i] = comp(val_[2 * i + 1], val_[2 * i + 2]);
    }
  }
  // get XXX value between [x,y)
  ll getRange(ll x, ll y) { return getr(x, y, 0, 0, n_); }
};

struct edge {
  ll to, cost;
  edge(ll t, ll c) : to(t), cost(c) {}
};

class Dijkstra {
 private:
  ll n_;
  vector<vector<edge> > G_;
  vl d_;

 public:
  Dijkstra(ll n) : n_(n), G_(n), d_(n, INF) {}
  void addEdge(ll v, ll to, ll cost) { G_[v].push_back(edge(to, cost)); }
  void exec(ll s) {
    priority_queue<pll, vector<pll>, greater<pll> > que;
    d_[s] = 0;
    que.push({0, s});
    while (!que.empty()) {
      pll p = que.top();
      que.pop();
      ll v = p.second;
      if (d_[v] < p.first) continue;
      for (auto& e : G_[v]) {
        if (d_[e.to] > d_[v] + e.cost) {
          d_[e.to] = d_[v] + e.cost;
          que.push({d_[e.to], e.to});
        }
      }
    }
  }
  ll dist(ll g) { return d_[g]; }
};

int main() {
  ll n,m,s,t;
  cin>>n>>m>>s>>t;
  s--,t--;
  Dijkstra gs(n), gt(n);
  rep(i,m) {
    ll u,v,a,b;
    cin>>u>>v>>a>>b;
    u--,v--;
    gs.addEdge(u,v,a);
    gs.addEdge(v,u,a);
    gt.addEdge(u,v,b);
    gt.addEdge(v,u,b);
  }
  gs.exec(s);
  gt.exec(t);
  // SegTree st(n);
  // rep(i,n) {
  //   st.update(i, gs.dist(i) + gt.dist(i));
  // }
  vl ans(n);
  ans[n-1] = (ll)1e15 - (gs.dist(n-1) + gt.dist(n-1));
  for (int i = n - 2; i >= 0; i--) {
    ans[i] = max(ans[i+1], (ll)1e15 - (gs.dist(i) + gt.dist(i)));
  }
  rep(i,n) {
    // ll ans = 1e15 - st.getRange(0, n + 1);
    cout << ans[i] << endl;
    // st.update(i, INF);
  }
  return 0;
}


Measured memory_bytes: 19016
#include<iostream>
using namespace std ;
using ll = long long ;

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

ll lcm(ll a,ll b){
	return a/gcd(a,b)*b ;
}

int main(){
	ll n,m ;
	cin >> n >> m ;
	ll g,a ;
	cin >> g ;
	ll cnt = 0 ;
	ll two = 2 ;
	while(g%two==0){
	    cnt++ ;
	    two *= 2 ;
	}
	two /= 2 ;
	for(int i=0;i<n-1;i++){
		cin >> a ;
		if(a%two!=0||a/2%two==0){
		    cout << 0 << endl ;
		    return 0 ;
		}
		g = lcm(g,a) ;
		if(g>2*m){
		    cout << 0 << endl ;
		    return 0 ;
		}
	}
	cout << (m+g/2)/g << endl ;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
 
int as[101];
int bs[101];
void solve(){
	int N,M;
	cin>>N>>M;
	for(int i=0;i<M;i++)
		cin>>as[i]>>bs[i];
	int pos=0;
	int maxs=0;
	for(int i=0;i<M;i++){
		if(as[i]==1){
			if(bs[i]>maxs){
				maxs=bs[i];
				pos=i;
			}
		}
	}
	if(maxs==0){
		cout<<"Impossible"<<endl;
		return;
	}
	int cnt=1;
	while(1){
		int fin=bs[pos];
		maxs=-1;
		for(int i=0;i<M;i++){
			if(as[i]<=fin+1&&bs[i]>=fin+1){
				if(bs[i]>maxs){
					maxs=bs[i];
					pos=i;
				}
			}
		}
		if(maxs==-1){
			if(fin==N)
				cout<<cnt<<endl;
			else
				cout<<"Impossible"<<endl;
			return;
		}
		cnt++;
	}
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
 
public class Main{
 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //n個後の文字
		char[] s = stdIn.next().toCharArray(); //文字列S
		if(n==0) {
			System.out.println(s);
			System.exit(0);
		}
		
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < s.length; j++) {
				if(s[j] == 'Z') {
					s[j] ='A';
				}else {
				
					s[j]++;
				}
			
			}
		}	
		for(char a: s) {
			System.out.print(a);
		}
	}
 
}

Measured memory_bytes: 26916
import java.io.*;

class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] str_Numbers = br.readLine().split(" ");
    int first_Number = Integer.parseInt(str_Numbers[0]);
    int last_Number  = Integer.parseInt(str_Numbers[1]);
    int divisor      = Integer.parseInt(str_Numbers[2]);
    int counter      = 0;

    for(int i = first_Number; i <= last_Number; i++){
      if(divisor % i == 0){
        counter++;
      }
    }

    System.out.println(counter);
  }
}



Measured memory_bytes: 24420
#include<iostream>
using namespace std;
typedef long long int lli;
#define INF 1e9

lli a[101][100001]; lli v[101],w[101];

int main()
{
    lli n,W; cin>>n>>W; lli sum=0;
    for(lli i=0;i<n;i++) {cin>>w[i]>>v[i];sum += v[i];}
    
    
    for(lli i=0;i<n;i++) for(lli j=0;j<=sum;j++) a[i][j]=INF;
    
    a[0][0]=0;
    for(lli i=1;i<=sum;i++) {if(i==v[0]){a[0][i]=w[0]; break;}}
    for(lli i=1;i<n;i++)
    {
        for(lli j=0;j<=sum;j++)
        {
            if(j-v[i]>=0) a[i][j]=min(a[i-1][j],a[i-1][j-v[i]]+w[i]);
            else a[i][j]=a[i-1][j];
        }
    }
    lli ans=0;
    for(lli i=0;i<n;i++)
    {    for(lli j=0;j<=sum;j++)
        {
            if(a[i][j]<=W) ans=max(ans,j);
            //cout<<a[i][j]<<" ";
        }
        //cout<<endl;
    }    
    cout<<ans<<endl;
}








Measured memory_bytes: 78464
#include<iostream>
#include<string>
using namespace std;
int main(){
    int a,b,c,d,p;
    cin>>a>>b>>c>>d>>p;
    int e;
    if(p-c>=0){
        e=b+(p-c)*d;
      }
      else{e=b;}
    if(p*a<=e){
     cout<<p*a;
    }
    else{
        if(p-c>=0){
        cout<<b+(p-c)*d;
      }
      else{cout<<b;}
    }
    cout<< endl;
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 2e12
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e2 + 2;
ll i,j,n,m,c,s,a,ans;
ll b[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m>>c;
    rep(i,0,m) cin>>b[i];
    rep(i,0,n){
        s = c;
        rep(j,0,m){
            cin>>a;
            s += a * b[j];
        }
        if(s > 0) ans += 1;
    }
    cout<<ans;
    return 0;
}

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

string s;
vector<string> cand;
void dfs(int p, int C) {
    if (p == (int)s.size()) {
        cand.push_back(s);
        return;
    }
    int idx = (s[p] - 'a');
    if (idx == 0 || C >> (idx - 1) & 1) {
        dfs(p + 1, C);
    } 
    if (~C >> idx & 1) {
        if (s[p] != 'z') {
            s[p]++;
            C ^= 1 << idx;
            dfs(p + 1, C);
            C ^= 1 << idx;
            s[p]--;
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while (cin >> s && s[0] != '#') {
        cand.clear();
        dfs(0, 0);
        cout << cand.size() << '\n';
        if (cand.size() > 10) {
            vector<string> new_cand;
            for (int i = 0; i < 5; ++i) {
                new_cand.push_back(cand[i]);
            }
            for (int i = 0; i < 5; ++i) {
                new_cand.push_back(cand.rbegin()[i]);
            }
            cand = new_cand;
            reverse(cand.begin() + 5, cand.end());
        }
        for (auto &s : cand) cout << s << '\n';
    }
}

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

int main(){
  int n;
  cin>>n;
  int t1=0,t2,dt;

  string ans="Yes";
  int dif,x1=0,x2,y1=0,y2;

  r(i,n){
    cin>>t2;
    dt=t2-t1;
    t1=t2;

    cin>>x2>>y2;
    dif=abs(x2-x1)+abs(y2-y1);
    x1=x2;y1=y2;
    //cout<<dif<<endl;
    //cout<<dt<<endl;
    if(dt%2==0){
        if(dif>dt){
          ans="No";break;
        }
        if(dif<=dt and dif%2==1){
          ans="No";break;
        }
    }else{
      if(dif>dt){
        ans="No";break;
      }
      if(dif<=dt and dif%2==0){
        ans="No";break;
      }
      if(dif<=dt and dif==0){
        ans="No";break;
      }
    }
  }

  cout<<ans<<endl;
return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;

struct Input
{
	int n;char c;char str[10010];string s;ll l;double d;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	double nextDouble(){scanf("%lf", &d);return d;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

int h, w, n;
vector<string> s, t;
bool clear[40][40];
bool check(){
	// rep(i, h) cout<<t[i]<<endl;
	// cout<<endl;
	bool isclear = true;
	for(int  i = 0; i < h; i++) for(int j = 0; j < w; j++){
		if(t[i][j] != '.') {
			isclear = false;
			break;
		}
	}
	if(isclear) return true;
	for(int i = 1; i < h; i++){
		for(int j = 0; j < w; j++){
			if(t[i][j] == '.' && t[i-1][j] != '.'){
				for(int k = i; k > 0; k--) t[k][j] = t[k-1][j];
				t[0][j] = '.';
			}
		}
	}
	bool update = false;
	rep(i, h) rep(j, w) clear[i][j] = false;
	rep(i, h - n + 1) rep(j, w){
		if(t[i][j] == '.') continue;
		bool f = false;
		rep(k, n-1) if(t[i+k][j] != t[i+k+1][j]){
			f = true;
			break;
		}
		if(f) continue;
		rep(k, n) clear[i+k][j] = true;
		update = true;
	}
	rep(i, h) rep(j, w - n + 1){
		if(t[i][j] == '.') continue;
		bool f = false;
		rep(k, n-1) if(t[i][j+k] != t[i][j + k + 1]){
			f = true;
			break;
		}
		if(f) continue;
		rep(k, n) clear[i][j + k] = true;
		update = true;
	}
	for(int j = 0; j < w; j++){
		for(int i = 0; i < h; i++){
			if(!clear[i][j]) continue;
			for(int k = i; k > 0;k--) t[k][j] = t[k-1][j];
			t[0][j] = '.';
		}
	}
	if(!update) return false;
	return check();
}

int main(){
	h = in.nextInt();
	w = in.nextInt();
	n = in.nextInt();
	s.resize(h);
	rep(i, h) s[i] = in.next();
	// for(int x1 = 0; x1 < w; x1++){
	// 		for(int y1 = 0; y1 < h-1; y1++){
	// 				t = s;
	// 				swap(t[y1][x1], t[y1+1][x1]);
	// 				//cout<<"----------"<<endl;
	// 				if(check()) {
	// 					cout<<"YES"<<endl;
	// 					return 0;
	// 				}
	// 		}
	// }
	for(int x1 = 0; x1 < w-1; x1++){
			for(int y1 = 0; y1 < h; y1++){
					t = s;
					swap(t[y1][x1], t[y1][x1+1]);
					//cout<<"----------"<<endl;
					if(check()) {
						cout<<"YES"<<endl;
						return 0;
					}
			}
	}
	cout<<"NO"<<endl;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;

int main(){
    ll a,b,c,ans=0;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

LL S(LL n) {
	LL ret = 0;
	while (n) {
		ret += (n % 10);
		n /= 10;
	}
	return ret;
}
LL S(string s) {
	LL ret = 0;
	for (auto c : s) {
		ret += c - '0';
	}
	return ret;
}

void sync(string &s, int i) {
	if (s.size() <= i) {
		s.push_back('1');
	}
	else {
		if (s[i] == '9') {
			s[i] = '0';
			sync(s, i + 1);
		}
		else s[i]++;
	}
}
LL f(LL lb,LL s) {
	string latte = to_string(lb);
	reverse(ALL(latte));
	while (S(latte)>s) {
		int p = 0;
		while (latte[p] == '0')p++;
		latte[p] = '0';
		sync(latte, p + 1);
	}
	int need = s - S(latte);
	for (auto &it : latte) {
		int k = min(9-(it - '0'), need);
		it += k;
		need -= k;
	}
	while (need > 0) {
		int k = min(9, need);
		latte.push_back('0'+k);
		need -= k;
	}
	reverse(ALL(latte));
	return stoll(latte);
}
LL v[136];
int main() {
	int K;
	cin >> K;
	LL now = 0;
	while (K) {
		K--; now++;
		for (int d : range(1,136)) {
			v[d] = f(now, d);
		}
		int p = 1;
		for (int i : range(2, 136)) {
			if (v[p] * i > v[i] * p) {
				p = i;
			}
			else if (v[p] * i == v[i] * p&&v[p] > v[i])
				p = i;
		}
		now = v[p];
		cout << now << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define max 101
int main(void){
	int N,i,j,k,A[max],key;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	for(k=0;k<N;k++){
		printf("%d",A[k]);
		if(k!=N-1) printf(" ");
	}
	printf("\n");
	for(i=1;i<N;i++){
		key=A[i];
		j=i-1;
		while(j>=0 && A[j]>key){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=key;
		for(k=0;k<N;k++){
			printf("%d",A[k]);
			if(k!=N-1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 604
package main

import (
	"fmt"
)

func main() {
	var n int
	var result uint64
	fmt.Scan(&n)
	arr := make([]uint64, n)
	for i:=0; i<n; i++ {
		fmt.Scan(&arr[i])
		// 0が一個でも存在したら積は0になる。先に全部チェックしてしまうことで、無駄な計算量を減らす
		if arr[i] == 0 {
			fmt.Printf("%d", 0)
			return
		}
	}
	result = 1
	for _,value := range arr {
		// result * value はオーバーフローしてしまう
		// オーバーフローする可能性のある積を比較するのは積→割り算に変換する
		// TODO: これは正確には result * value > 1e18とは違う。割り算は切り捨てられるため。しかしこれで必要十分な理由を述べよ。
		if result > 1e18/value {
			fmt.Print(-1)
			return
		}
		result *= value
	}
	fmt.Printf("%d", result)
}


Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int N, C;
  cin >> N >> C;
  vector<vector<int>> D(C, vector<int>(C));
  rep(i, 0, C) rep(j, 0, C) { cin >> D[i][j]; }
  vector<vector<int>> c(N, vector<int>(N));
  rep(i, 0, N) rep(j, 0, N) {
    cin >> c[i][j];
    c[i][j]--;
  }
  vector<vector<int>> v(3, vector<int>(C));
  rep(x, 0, N) rep(y, 0, N) { v[(x + y) % 3][c[x][y]]++; }

  int ans = INF;
  rep(i, 0, C) rep(j, 0, C) rep(k, 0, C) {
    if (i == j or j == k or k == i)
      continue;
    int tmp = 0;
    dump(i, j, k);

    rep(l,0,C){
      tmp+=v[0][l]*D[l][i];

      tmp+=v[1][l]*D[l][j];

      tmp+=v[2][l]*D[l][k];
    }

    dump(tmp);
    chmin(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;

int main()
{
    int H, W;

    while (1)
    {
        cin >> H >> W;
        if (H == 0 && W == 0)
            break;
        rep(i, H)
        {
            if (i == 0 || i == H - 1)
            {
                rep(j, W)
                {
                    cout << "#";
                }
            }
            else
            {
                rep(j, W)
                {
                    if (j == 0 || j == W - 1)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
            }

            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3104
n = int(input())
a = input()
list1 = list(map(int,a.split()))
b = input()
list2 = list(map(int,b.split()))
c = input()
list3 = list(map(int,c.split()))
point = 0
for i in range(n):
    point += list2[list1[i]-1]
    if i < n-1:
        if list1[i] == list1[i+1] -1:
            point += list3[list1[i]-1]
print(point)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
   	scanf("%d%d%d",&a,&b,&c);
   	if(b-a==c-b) 
		cout<<"YES";
 	else
 	  	cout<<"NO";
 	cout<<endl;
   	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int l[5];
   int k=10,f=10,t=0;
   cin>>l[0];cin>>l[1];cin>>l[2];cin>>l[3];cin>>l[4];
   for(int i=0;i<5;i++){
       if(f>(l[i]%10)&&l[i]%10!=0){f=l[i]%10;t=i;};
   }
   f=0;
   for(int j=0;j<5;j++){
        if(j!=t){
            f+=int(l[j]/10)*10+(l[j]%10==0?0:10);
        }
    }
    cout<<f+l[t];
}

Measured memory_bytes: 256
n=int(input())
while n!=0:
    w=list(map(int,input().split()))
    check=[[False]*n for i in range(n)]
    for i in range(n-1):
        if abs(w[i+1]-w[i])<=1:
            check[i][i+1]=True
    for i in range(3,n,2):
        for j in range(n-i):
            for k in range(j+1,j+i):
                if check[j][j+i]==False and check[j][k] and check[k+1][j+i]:
                    check[j][j+i]=True
                    break
            if check[j][j+i]==False and abs(w[j]-w[j+i])<=1 and check[j+1][j+i-1]:
                check[j][j+i]=True
    dp=[0]*(n+1)
    for k in range(n):
        for m in range(k):
            if check[m][k]:
                dp[k]=max(dp[k],dp[m-1]+k-m+1)
        dp[k]=max(dp[k],dp[k-1])
    print(dp[n-1])
    n=int(input())


Measured memory_bytes: 7096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VI a(n); cin >> a;
    SORT(a);
    cout << a.back() - a[0] << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>

using namespace std;

int main()
{
	int n;
	cin >> n;
	long long a = 0;

	for (int i = 1; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0) {
			a += i;
		}
	}
	cout << a << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin>>n;
    if(n==1) cout<<1<<endl;
    else if(n%2==0) cout<<0.5<<endl;
    else cout<<(n+1)/(double)2.0/n<<endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  int cnt;
  ll ans = 0;
  int mini = 1e9;
  for (int i = 0; i < n; i++){
    if (a[i] < 0) cnt++;
    ans += abs(a[i]);
    mini = min(mini, abs(a[i]));
  }
  if (cnt % 2 == 0){
    cout << ans << endl;
  } else {
    cout << ans - 2 * mini << endl;
  }
  return 0;
}


Measured memory_bytes: 640
n,m = (int(x) for x in input().split())
frg = 0
ls=[0]*m
lc=[0]*m
for i in range(m):
  ls[i],lc[i] = (int(x) for x in input().split())

if m == 0:
  if n == 1:
    print(0)
  elif n == 2:
    print(10)
  else:
    print(100)

elif n == 1:
  if len(set(lc)) != 1:
    print(-1)
  else:
    print(lc[0])
  
else:
  for i in range(m):
    if ls[i] == 1:
      if lc[i] == 0:
        frg = 1

  if frg == 1:
    print(-1)
  else:
    A = [0]*n
    for i in range(n):
      ls_idx = [j for j, x in enumerate(ls) if x == i+1]
      if len(ls_idx)==1:
        A[i] = lc[ls_idx[0]]
      elif len(ls_idx)>1:
        lctmp = []
        for k in ls_idx:
          lctmp.append(lc[k])
        if len(set(lctmp))==1:
          A[i] = lc[ls_idx[0]]
        else:
          frg = 1
    if frg == 1:
      print(-1)
    else:
      if A[0] == 0:
        NA = '1'
      else:
        NA = str(A[0])
      for i in range(1,n):
        NA = NA + str(A[i])
      print(int(NA))

Measured memory_bytes: 3192
N, = map(int, raw_input().split())
d = {}
for i in range(N):
  a, = map(int, raw_input().split())
  d[a] = d.get(a, 0)+1
r = 0
for k in d.keys():
  r += 0 if d[k]%2==0 else 1
print r

Measured memory_bytes: 17084
package main

import (
  "fmt"
)

func main() {
  var sum int
  var a, b, c, k int
  fmt.Scanf("%d %d %d %d", &a, &b, &c, &k)

  if a >= k {
    sum = k
  } else if a + b >= k {
    sum = a
  } else {
    sum = a - (k - a - b)
  }
  fmt.Println(sum)
}

Measured memory_bytes: 1820
N, T=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(N)]
MAXN, MAXT=3001, 3001
dp1=[[0 for _ in range(MAXT)] for _ in range(MAXN+1)]
dp2=[[0 for _ in range(MAXT)] for _ in range(MAXN+1)]
for i in range(1, N+1):
  A, B=lst[i-1]
  for j in range(1, MAXT):
    dp1[i][j]=max(dp1[i-1][j], dp1[i-1][j-A]+B) if j>=A else dp1[i-1][j]
for i in range(N, 0, -1):
  A, B=lst[i-1]
  for j in range(1, MAXT):
    dp2[i][j]=max(dp2[i+1][j], dp2[i+1][j-A]+B) if j>=A else dp2[i+1][j]
ans=dp1[N-1][T-1]+lst[-1][1]
for i in range(1, N):
  A, B=lst[i-1]
  for j in range(T):
    ans=max(ans, dp1[i-1][j]+dp2[i+1][T-1-j]+B)
print(ans)

Measured memory_bytes: 195972