akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	static String reverce(String str) {
		String strr="";
		for(int i=str.length()-1;i>=0;i--) {
			strr+=str.charAt(i);
		}
		return strr;
	}
	public static void main(String[] args) {
		int a=scan.nextInt();
		int b=scan.nextInt()/2;
		System.out.println(a+b);
	}
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<endl;
#define PI 2*acos(0.0)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define yes cout<<"Yes"<<endl
#define no cout<<"-1"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
///................Graph's Move.................
///const int dx[] = {+1,-1,+0,+0}; ///Rock's Move
///const int dy[] = {+0,+0,+1,-1}; ///Rock's Move
///const int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
///const int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int dx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's Move
///const int dy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's Move
///*.....................-_-........................*///
int main()
{
    FIO;
    int n,k,i,j;
    cin>>n>>k;
    vi v(n);
    read(v,0,n);
    vi dp(n,1000000000);
    dp[1] = abs(v[0]-v[1]);
    dp[0]=0;
    for(i=2; i<n; i++)
    {
        for(j=max(0,i-k); j<i; j++)
            dp[i] = min(abs(v[i]-v[j])+dp[j],dp[i]);
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 3916
import math        # factorical（階乗) # hypot(距離)
import heapq
# from fractions import gcd # Python3.5以前 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # Python3.6以降
# --------------------------------------------------------------

n,m = map(int,input().split())
price = list(map(int,input().split()))

price = [-i for i in price]

heapq.heapify(price)

for i in range(m):
    sm = heapq.heappop(price)
    sm = -(-sm//2)
    heapq.heappush(price,sm)

price = [-i for i in price]

print(sum(price))

Measured memory_bytes: 20384
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

RGB = [0, 0, 0]

ans = 1
for i in range(N):
    cnt = RGB.count(A[i])
    ans = (ans * cnt) % mod
    for j in range(3):
        if A[i] == RGB[j]:
            RGB[j] += 1
            break

print(ans)


Measured memory_bytes: 20652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
#define MOD 1e9+7


int main(){
    int n,m;
    cin >> n >> m;
    map<int,ll,greater<ll>> mp;
    rep(i,n){
        int a;
        cin >> a;
        mp[a]++;
    }
    rep(i,m){
        int temp;
        for(auto x:mp){
            if(x.second<=0) continue;
            mp[x.first/2]++;
            mp[x.first]--;
            temp=x.first;
            break;
        }
        if(mp[temp]<=0) mp.erase(temp);
    }
    ll ans=0;
    for(auto x:mp){
        //cout << x.first << " " << x.second << endl;
        if(x.second<=0) continue;
        ans+=x.first*x.second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9736
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
signed main()
{
    IOS
    int n; cin>>n;
    int A[n+1],B[n];
    for(int i=0;i<=n;i++) cin>>A[i];
    for(int i=0;i<n;i++) cin>>B[i];
    int ans = 0,te;
    for(int i=0;i<n;i++)
    {
        te = min(A[i],B[i]);
        ans += te;
        B[i] -= te;
        if(B[i] > 0)
        {
            te = min(B[i],A[i+1]);
            A[i+1] -= te;
            ans += te;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
string st;
int i,s;
int main()
{
	cin>>st;
	for(i=1; i<=st.size(); i++)
	{
		if(st[i]=='a'||st[i]=='b'||st[i]=='c'||st[i]=='d'||st[i]=='e'||st[i]=='f'||st[i]=='g'||st[i]=='h'||st[i]=='i'||st[i]=='j'||st[i]=='k'||st[i]=='l'||st[i]=='m'||st[i]=='n'||st[i]=='o'||st[i]=='p'||st[i]=='q'||st[i]=='r'||st[i]=='s'||st[i]=='t'||st[i]=='u'||st[i]=='v'||st[i]=='w'||st[i]=='x'||st[i]=='y'||st[i]=='z')
		s=0;
		else
		st[i]=' ';
	}
	cout<<st;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x;
  cin >> x;

  cout << x*x << endl;
  return 0;
}

Measured memory_bytes: 256
// SeeAlso: https://atcoder.jp/contests/abc152/tasks/abc152_b

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 1; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    ll N;
    cin >> N;
    ll p; 
    cin >> p;
    ll ans = 1;
    ll temp = p; 
    rep(i, N) {
        cin >> p;
        if(temp >= p) {
            ans++;
            temp = p;
        }
    }

    print(ans);
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

const unsigned int BIT_FLAG_0 = (1 << 0);  // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1);  // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2);  // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3);  // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4);  // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5);  // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6);  // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7);  // 0000 0000 1000 0000

const double PI = 3.14159265358979323846;

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

#define H_MAX 500
#define W_MAX 500
#define INF 1e9 + 7

int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    rep(i, N) {
        cout << S[i] << T[i];
    }
    cout << endl;
}


Measured memory_bytes: 3604
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    s = S()

    if s.islower():
        print('a')
    else:
        print('A')


if __name__ == '__main__':
    main()


Measured memory_bytes: 74456
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll h, w, a[1008][1008];
string buf;

int main(){
	cin >> h >> w;
	memset(a, 0, sizeof(a));
	queue<pair<ll, ll>> q[2];
	
	for(ll i = 1; i <= h; i++){
		cin >> buf;
		a[i][0] = 1;
		a[i][w+1] = 1;
		for(ll j = 1; j <= w; j++){
			if(buf[j-1] == '#'){
				a[i][j] = 1;
				q[0].push(P(i, j));
			}
		}
	}
	for(ll j = 1; j <= w; j++){
		a[0][j] = 1;
		a[h+1][j] = 1;
	}
	
	ll ite = -1;
	while(!q[0].empty()){
		auto pp = q[0].front(); q[0].pop();
		ll hh = pp.first;
		ll ww = pp.second;
		if(a[hh-1][ww] == 0){q[1].push(P(hh-1, ww)); a[hh-1][ww] = 1;}
		if(a[hh+1][ww] == 0){q[1].push(P(hh+1, ww)); a[hh+1][ww] = 1;}
		if(a[hh][ww-1] == 0){q[1].push(P(hh, ww-1)); a[hh][ww-1] = 1;}
		if(a[hh][ww+1] == 0){q[1].push(P(hh, ww+1)); a[hh][ww+1] = 1;}
		
		if(q[0].empty()){
			q[0].swap(q[1]);
			ite++;
		}
	}
	
	cout << ite << endl;
	return 0;
}

Measured memory_bytes: 24500
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
using namespace std;
#define pi M_PI

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

    if(x < a && x < b){
        if(a - x < b - x){
            cout << 'A' << endl;
        }
        else cout << 'B' << endl;
    }
    else if(a < x && b < x){
        if(x - a < x - b){
            cout << 'A' << endl;
        }
        else cout << 'B' << endl;
    }
    else if(a < x && x < b){
        if(x - a < b - x){
            cout << 'A' << endl;
        }
        else cout << 'B' << endl;
    }
    else if(x < a && b < x){
        if(a - x < x - b){
            cout << 'A' << endl;
        }
        else cout << 'B' << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n<10)
    {
        cout<<n<<endl;
    }
    else if(n<=99)
    {
        cout<<"9"<<endl;
    }
    else if(n>=100&&n<=999)
    {
        printf("%d\n",(n-99)+9);
    }
    else if(n>=1000&&n<=9999)
    {
        cout<<"909"<<endl;
    }
    else if(n>=10000&&n<=100000)
    {
        if(n==100000)
        {
            cout<<"90909"<<endl;
        }
        else
        {
          printf("%d\n",(n-9999)+909);
        }

    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int main()
{
	int n;
	cin>>n;
	int a[maxn][3],dp[maxn][3];
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d %d",&a[i][1],&a[i][2],&a[i][3]);
		
	}
	dp[1][1]=a[1][1];
	dp[1][2]=a[1][2];
	dp[1][3]=a[1][3];
	for(int i=1;i<=n;i++)
	{
		dp[i][1]=a[i][1]+max(dp[i-1][2],dp[i-1][3]);
		dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][3]);
		dp[i][3]=a[i][3]+max(dp[i-1][2],dp[i-1][1]);
	}
	cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>

using namespace std;

int main() {
    unordered_map<int, char> mapping;
    for (int i = 0; i <= 25; i++) mapping[i] = 'a' + i;
    //mapping[0] = 'z';

    long long n;
    cin >> n;
    n--;
    vector<char> name_stack;
    while (n >= 26) {
        name_stack.push_back(mapping[n % 26]);
        n /= 26;
        n--;
    }

    name_stack.push_back(mapping[n % 26]);

    string s;
    while (name_stack.size() != 0) {
        s.push_back(name_stack[name_stack.size() - 1]);
        name_stack.pop_back();
    }
    cout << s << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int N=110;
char str[N];
int cut1,cut2,n;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>str[i];
    for(int i=1;i<=n;i++){
        if(str[i]=='(') cut1++;
        if(str[i]==')'){cut1--;if(cut1<0)cut2++,cut1=0;}
    }
    for(int i=1;i<=cut2;i++)cout<<"(";
    for(int i=1;i<=n;i++)cout<<str[i];
    for(int i=1;i<=cut1;i++)cout<<")";
    cout<<"\n";
}

Measured memory_bytes: 256
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
using namespace std;
int main()
{
	string s;
	int chk,l;
	map <char,int> mp;
	cin>>s;
	if(s.size()<26)
	{
		for(int i=0;i<s.size();i++) mp[s[i]]++;
		for(char j='a';j<='z';j++) 
			if(mp[j]==0)
			{
				cout<<s<<j;
				rt0;
			}
	}
	else
	{
		for(int i=s.size()-1;i>=0;i--)
		{
			if(s[i]=='z') s.pop_back();
			else
			{
				for(char k=s[i]+1;k<='z';k++) 
				{
					for(l=0;l<s.size();l++)
						if(k==s[l])	break;
					if(l==s.size())
					{
						s.pop_back();
						cout<<s<<k;
						rt0;
					}
				}
				s.pop_back();
			}
		}
	}
	cout<<"-1";
    rt0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, m, q; cin >> n >> m >> q;
    vector<vector<int>> x(n, vector<int>(n,0));
    vector<vector<int>> c(n+1, vector<int>(n+1,0));
    rep(i,m){
        int l, r; cin >> l >> r;
        --l, --r;
        x[l][r]++;
    }
    rep(i,n)rep(j,n) c[i][j+1] = c[i][j] + x[i][j];//c[l][r] = [l,r)の和, x[l][r] = [l,r]の個数
    rep(i,q){
        int p, q; cin >> p >> q;
        --p, --q;
        int sum = 0;
        for(int i = p; i <= q; ++i) sum += c[i][q+1] - c[i][p];
        cout << sum << endl;
    }
}

Measured memory_bytes: 2944
N, Q = [int(i) for i in input().split()]
S = input()
lrs = [[int(i) for i in input().split()] for _ in range(Q)]


cache = {1: {'c': 0, 'm': False}}
cnt = 0
for i in range(1, N):
    if S[i - 1]+S[i] == 'AC':
        cnt += 1
    cache[i + 1] = {'c': cnt, 'm': True}

for l, r in lrs:
    print(cache[r]['c'] - cache[l]['c'])


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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 200005;
int n, a[MX], lis[MX], res[MX];
vi adj[MX];

void dfs (int u, int p, int sz) {
	res[u] = sz;

	for (int v : adj[u]) {
		if (v == p) continue;

		int j = lower_bound(lis, lis + sz, a[v]) - lis;
		int aux = lis[j];
		lis[j] = a[v];
		dfs(v, u, sz + (j == sz));
		lis[j] = aux;
	}
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n;
	
	for (int i = 1; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}

	lis[0] = a[1];
	dfs(1, 1, 1);

	for (int i = 1; i <= n; i++)
		cout << res[i] << endl;

	return 0;
}


Measured memory_bytes: 30420
// Some Sums

#include <bits/stdc++.h>

using namespace std;

int sum_degit(int a, int b){
    int sum=0;
    for(int i=0;i<b;++i){
        sum+=a%10;
        a/=10;
    }
    return sum;
}

unsigned int get_degit(unsigned int num){
    int degit=0;
    while(num!=0){
        num/=10;
        ++degit;
    }
    return degit;
}

int main(){
    int n,a,b,tmp,ans=0;
    cin >> n >> a >> b;
    for(int i=1;i<=n;++i){
        int tmp=0;
        tmp=sum_degit(i,get_degit(i));
        if(tmp>=a && tmp<=b) ans+=i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func min(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	m, mina, sum := 0, int(1e18), 0
	for i := range A {
		A[i] = nextInt(sc)
		if A[i] < 0 {
			m++
		}
		t := abs(A[i])
		if mina > t {
			mina = t
		}
		sum += t
	}
	// fmt.Println("sum", sum, "mina", mina, "m", m)
	if m%2 != 0 {
		sum -= mina * 2
	}
	fmt.Println(sum)
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int a;
    int n[3];
    bzero(n, sizeof(n));
    rep(0, 2) {
        cin >> a;
        n[a-1] = 1;
    }

    rep(0, 3) {
        if (n[i] == 0) cout << (i + 1);
    }
    cout << endl;

    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> AA(A), BB(B), SA, SB;
  for (int i = 0; i < A; i++) {
    cin >> AA[i];
  }
  for (int i = 0; i < B; i++) {
    cin >> BB[i];
  }
  SA = AA, SB = BB;
  sort(SA.begin(), SA.end());
  sort(SB.begin(), SB.end());
  int res = SA[0] + SB[0];
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--, y--;
    res = min(res, AA[x] + BB[y] - c);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

void
solve() {
  int a, b;
  cin>>a>>b;

  map<int, bool> wrong;
  wrong[a] = true;
  wrong[b] = true;

  for (int i=1; i<=3; i++)
    if (!wrong[i]) {
      cout<<i<<endl;
      break;
    }
}

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

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define pb(x) push_back(x)
#define PRIME 1000000007
using namespace std;
typedef vector<vector<ll>> matrix;

int main()
{
   string s, t;
   cin >> s;
   cin >> t;
   if (s.length() + 1 == t.length())
   {
      int flag = 0;
      for (int i = 0; i < s.length(); i++)
      {
         if (s[i] != t[i])
         {
            flag = 1;
            break;
         }
      }
      if (flag == 0)
         cout << "Yes" << endl;
      else
         cout << "No" << endl;
   }
   else
      cout << "No" << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin>>s;
if((s[0]==s[1]&&s[1]==s[2])||
    (s[1]==s[2]&&s[2]==s[3])){
        cout<<"Yes"<<endl;
    }
else{
    cout<<"No"<<endl;
}
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf = 1e9;
int n, m;

int main(){
  cin>>n>>m;
  vector<int> vec(m);
  for(int i = 0; i < m; ++i){cin>>vec[i];n-=vec[i];}
  if(n< 0)cout<<-1<<endl;
  else cout<<n<<endl;
  return 0;
}


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

int main() {
 #define int long long
  int N;
  cin >> N;
  vector<int> A(N),B(N);
  int a,sum;
  for(int i=0;i<N;i++){
    cin >> a;
    A[i]=a;
    B[a-1]++;
  }
  for(int j=0;j<N;j++){
    sum+=(B[j]*(B[j]-1)*0.5);
  }
  int ans;
  for(int i=0;i<N;i++){
    ans=0;
    ans=sum - (B[A[i]-1]*(B[A[i]-1]-1)*0.5);
    B[A[i]-1]--;
    ans+=(B[A[i]-1]*(B[A[i]-1]-1)*0.5);
    cout << ans << endl;
    B[A[i]-1]++;
  }

}

Measured memory_bytes: 5760
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	String str = "";	
	while(true){
	    str = scan.next();
	    if(str.equals("#END")){
		return;
	    }else{
		str = rs(str);
		System.out.println(str);
	    }	    
	}
    }
    public static String rs(String str){
	char[] chr = str.toCharArray();
	int cl = chr.length;
	int[][] m = new int[cl][cl];
	char[] c_lcs = new char[cl/2 + 1];
	int lcsl = 0;
	String tmplcs = "";
	String lcs = "";
	int i = 1;
	int j = 1;
	for(int k = 0; k < cl; k++) m[k][0] = 0;
	for(int k = 0; k < cl; k++) m[0][k] = 0;
	for(int split = 1; split < cl; split++){
	    for(int k = 0; k < cl/2 + 1; k++) c_lcs[k] = ' ';
	    tmplcs = "";
	    i = 1;
	    while(i <= split){
		j = 1;
		while(j <= cl - split){
		    if(chr[i-1] == chr[j-1+split]) m[i][j] = m[i-1][j-1] + 1;
		    else m[i][j] = Math.max(m[i-1][j],m[i][j-1]);
		    j++;
		}
		i++;
	    }
	    lcsl = m[i-1][j-1];
	    if(lcsl > lcs.length()){
		i--;
		j--;
		while(i > 0 && j > 0){
		    if(m[i][j] == m[i-1][j])i--;
		    else if(m[i][j] == m[i][j-1])j--;
		    else{
			c_lcs[m[i][j]] = chr[i-1];
			i--;
			j--;
		    }
		}
		for(int k = 1; k <= lcsl; k++){
		    tmplcs += c_lcs[k];
		}
		lcs = tmplcs;
	    }
	}
	return lcs;
    }
}

Measured memory_bytes: 64876
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  cout << a + b + c - max({a,b,c}) << endl;
}

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

int main() {
  int N;
  cin >> N;
  set<int> SE;
  SE.insert(N);
  int cnt = 1;
  while (++cnt) {
    if (N % 2) {
      N = 3 * N + 1;
    } else {
      N = N / 2;
    }
    if (SE.count(N)) return cout << cnt << "\n", 0;
    else SE.insert(N);
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int A, B;
    cin >> A >> B;
    if (A >= 13)
    {
        cout << B << endl;
    }
    else if (A >= 6 && A <= 12)
    {
        cout << (B * 0.5) << endl;
    }
    else if (A <= 5)
    {
        cout << "0" << endl;
    }

    return 0;
   }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll v(n), c(n);
    REP(i, n) cin >> v[i];
    REP(i, n) cin >> c[i];

    ll ans = 0, res;
    REP(i, n){
        res = v[i] - c[i];
        if(res > 0) ans += res;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Maybe
import Data.Ord
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  [h,w] <- readLnList
  -- s <- zip [1..] <$> (replicateM h $ zip [1..] . words <$> getLine)
  s <- replicateM h $ words <$> getLine
  let ans = head [(i,j) | (i,t) <- zip [1..] s, (j,u) <- zip ['A'..] t, u == "snuke"]
  putStrLn $ [snd ans] ++ show (fst ans)


type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "Yes"
yesNo False = "No"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 1020
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr ,greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,0 }, dy[] = { 1,0,-1,0,0 };
const int SIZE1 =3e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 22;
const int SIZE = SIZE1;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
ut N, M, K, X, L, Y,H,W,Q;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], nums[SIZE], maps[SIZE3][SIZE3], answer = zero;
LL A[SIZE], B[SIZE];
bool used[11];
inline LL dist(LL a,LL b) {
	return abs(a / 3 - b / 3) + abs(a % 3 - b % 3);
}
LL solve() {
	cin >> N;
	string s;
	cin >> s;
	REP(i, N) {
		A[i] = s[i] - '0';
		if (i)
			maps[A[i]][A[i - 1]]++;
	}
	VI v(9);
	EFOR(i, 0 ,8) v[i] = i+1;
	LL minium = INF;
	VI ansv(9);
	do {
		LL ans = 0;
		REP(i,9) REP(j,9) {
			ans += maps[v[i]][v[j]] * dist(i, j);
		}
		if (MN(minium,ans )) {
			REP(i, 9) ansv[i] =v[i] ;
		}
	} while (next_permutation(ALL(v)));
	REP(i, 9) {
		cout << ansv[i];
		if (i % 3 == 2) cout << endl;
	}
	return 0;
}
signed main() {
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	solve();
//	cin >> N;
	return 0;
}


Measured memory_bytes: 11144
#include <bits/stdc++.h>
using namespace std;
using large = long long;

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

    // N  =  (1+xK)(K^y)  =  (K^y) + x(K^(y+1))
    // x : subtractions
    // y : divisions

    // if y==0, N = 1+xK, then K = (N-1)/x
    // if y!=0, N'= 1+xK and N=N' * K^y, then K = (N'-1)/x

    auto cnt = 0LL;
    for (auto div = 1LL; div * div <= n - 1; ++div) {
        if ((n - 1) % div != 0)
            continue;

        if (div != 1)
            ++cnt;

        auto div2 = (n - 1) / div;
        if (div2 != div)
            ++cnt;
    }

    for (auto div = 1LL; div * div <= n; ++div) {
        if (n % div != 0)
            continue;

        large k[2] = {div, n / div};
        int offset = 0;
        if (k[0] == 1)
            ++offset;
        if (k[0] == k[1])
            ++offset;

        for (int i = offset; i < 2; ++i) {
            auto x = n;
            auto rem = 0LL;
            while ((rem = x % k[i]) == 0)
                x /= k[i];
            if (rem == 1)
                ++cnt;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
ll gcd(ll a,ll b){
  if (a%b==0) return(b);
  else return(gcd(b,a%b));
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

int main(){
  string S;
  cin >> S;
  if(S[0]==S[1] and S[1]==S[2]) cout << "No" << endl;
  else if(S[0]==S[1] and S[2]==S[3]) cout << "Yes" << endl;
  else if(S[0]==S[2] and S[1]==S[3]) cout << "Yes" << endl;
  else if(S[0]==S[3] and S[1]==S[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main() {
	vint a(3);
	rep(i,3) cin >> a[i];
	sort(be(a));
	int ans=0;
	ans+=abs(a[1]-a[0]);
	ans+=abs(a[2]-a[1]);
	cout << ans << endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long li;


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

    li n, m, l;
    cin >> n >> m >> l;

    const li inf = 1LL << 58;
    vector<vector<li>> g(n, vector<li>(n, inf));
    for (int i = 0; i < n; ++i) {
        g[i][i] = 0;
    }
    for (int i = 0; i < m; ++i) {
        li a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g[a][b] = g[b][a] = c;
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }

    vector<vector<li>> gg(n, vector<li>(n, inf));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (g[i][j] <= l) {
                gg[i][j] = 1;
            }
        }
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                gg[i][j] = min(gg[i][j], gg[i][k] + gg[k][j]);
            }
        }
    }

    li q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        li s, t;
        cin >> s >> t;
        s--; t--;
        li ans = gg[s][t];
        if (ans >= inf) {
            cout << -1 << endl;
        } else {
            cout << ans - 1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>
#include <string.h>

char *caesar(char str[], char caesar_str[], int shift) {
  int i;

  for (i = 0; str[i] != '\0'; i++) {
    if (str[i] == ' ')
      caesar_str[i] = ' ';
    else if (str[i] == '.')
      caesar_str[i] = '.';
    else if (str[i] + shift <= 122)
      caesar_str[i] = str[i] + shift;
    else
      caesar_str[i] = str[i] + shift - 26;
  }
  caesar_str[--i] = '\0';

  return caesar_str;
}

int main(void) {
  int i;
  char str[81], caesar_str[81];

  while (fgets(str, sizeof(str), stdin) != NULL) {
    for (i = 0; i < 26; i++) {
      if (strstr(caesar(str, caesar_str, i), "the"))
        printf("%s\n", caesar_str);
      else if (strstr(caesar(str, caesar_str, i), "this"))
        printf("%s\n", caesar_str);
      else if (strstr(caesar(str, caesar_str, i), "that"))
        printf("%s\n", caesar_str);
    }
  }

  return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = (x2 - x1), dy = (y2 - y1);
  if (dx <= 0 && dy >= 0) {
    int x3 = x2 - abs(dy), y3 = y2 - abs(dx), x4 = x1 - abs(dy), y4 = y1 - abs(dx);
    printf("%d %d %d %d", x3, y3, x4, y4);
  }else if (dx <= 0 && dy <= 0) {
    int x3 = x2 + abs(dy), y3 = y2 - abs(dx), x4 = x1 + abs(dy), y4 = y1 - abs(dx);
    printf("%d %d %d %d", x3, y3, x4, y4);
  }else if (dx >= 0 && dy <= 0) {
    int x3 = x2 + abs(dy), y3 = y2 + abs(dx), x4 = x1 + abs(dy), y4 = y1 + abs(dx);
    printf("%d %d %d %d", x3, y3, x4, y4);
  } else {
    int x3 = x2 - abs(dy), y3 = y2 + abs(dx), x4 = x1 - abs(dy), y4 = y1 + abs(dx);
    printf("%d %d %d %d", x3, y3, x4, y4);
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int t;
long long a,b,c,d,g,yu;
void solve(){
	cin>>a>>b>>c>>d;
	if(b>a){
		cout<<"No"<<endl;
		return;
	}
	if(b>d){
		cout<<"No"<<endl;
		return;
	}
	g=__gcd(b,d);
	yu=a%g;
	//不管-b或+d，模最大公约数的值不变
	//MIN mod g ...yu,MIN>=c-b+1
	long long kk=(c-b+1LL)/g;
	//d≥b    D      N     D
	//最低：c-b+1 ->c+1->c-b+1......
	//求≥c-b+1,mod gcd =a mod gcd 的 x（最低点） 
	if((c-b+1LL)<0LL)
		kk--; 
	long long mm=kk*g+yu;
	if(mm<(c-b+1LL))
		mm+=g;
	assert((mm%g+g)%g==yu);
	if(mm>=0){
		cout<<"Yes"<<endl;
		return;
	}
	cout<<"No"<<endl;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 256
n,t = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
amax = [a[-1]]
for i in range(n-2,0,-1): amax.append(max(amax[-1],a[i]))
num,ans,amax = 0,0,amax[::-1]
for i in range(n-1):
	if num<amax[i]-a[i]: ans,num = 1,amax[i]-a[i]
	elif num==amax[i]-a[i]: ans += 1
print(ans)

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
    int h, w;
    cin >> h >> w;
    int H[] = {1, 1, 1, 0, 0, 0, -1, -1, -1};
    int W[] = {1, 0, -1, 1, 0, -1, 1, 0, -1};
     string s[h];
    rep(i, h) {
        cin >> s[i];
    }
rep(i,h){
    rep(j,w){
        int count=0;
        rep(k,9){
            int A=i+H[k],B=j+W[k];
            if(A==-1||A==h) continue;
            if(B==-1||B==w) continue;
            if(s[A][B]=='#'){
                count++;
            }
        }
        if(s[i][j]=='#'){
            cout<<'#';
        }else
        {
            cout<<count;
        }
        

    }
    cout<<endl;
}
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int calc_d0(int n) {
    return n/10000;
}
int calc_d1(int n) {
    return (n/1000)%10;
}
int calc_d3(int n) {
    return (n/10)%10;
}
int calc_d4(int n) {
    return n%10;
}
int check_palindrome(int n) {
    if((calc_d0(n)==calc_d4(n))&&(calc_d1(n)==calc_d3(n))) return 1;
    else return 0;
}

int main() {
    int A, B;
    scanf("%d %d", &A, &B);

    int i, count=0;
    for(i=A; i<=B; i++) {
        if(check_palindrome(i)) {
            count += 1;
        }
    }

    printf("%d\n", count);
    
    return 0;

}

Measured memory_bytes: 128
ans_list = []

while True:
    n,m = map(int,input().split())
    if (n,m) == (0,0):
        break
    S = [int(input()) for _ in range(n)]
    T = [int(input()) for _ in range(m)]
    ss = sum(S)
    tt = sum(T)
    ans = (101,101)
    for s in S:
        for t in T:
            if ss - s + t == tt - t + s and s + t < sum(ans):
                ans = (s,t)
    if ans == (101,101):
        ans = -1
    else:
        ans = "{} {}".format(ans[0],ans[1])
    ans_list.append(ans)

for ans in ans_list:
    print(ans)


Measured memory_bytes: 5604
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int n = sc.nextInt();
    int limit = sc.nextInt();
    int ans = 9999;
    for(int i = 0; i < n; i++){
      int c = sc.nextInt();
      int t = sc.nextInt();
      if(t <= limit && c < ans){
        ans = c;
      }
    }

    if(ans == 9999){
      System.out.println("TLE");
    }else{
      System.out.println(ans);
    }

  }
 
 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

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

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    srand(322179);
#ifdef LOCAL
    freopen("/home/max/alg/clion_main/input.txt", "rt", stdin);
    freopen("/home/max/alg/clion_main/output.txt", "wt", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#define all(x) x.begin(), x.end()
#define vb vector<bool>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define vc vector
#define $ make_pair

#ifndef LOCAL
#define cerr if(0) cerr
#define DBG(...) (true)
#endif

#define D double
#define CD complex<D>
#define int long long

// ----------------------------- CODE NOW ------------------------



signed main() {
    doRoutine();

    int n;
    cin >> n;

    vi a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }

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

    set<pii> st;
    for (int i = 0; i < n; ++i) {
        if (a[i] < b[i]) {
            st.insert({b[i], i});
        }
    }

    int ans = 0;
    while (!st.empty()) {
        int i = (--st.end())->se;
        st.erase(--st.end());
        int v1 = b[(i + n - 1) % n], v2 = b[(i + 1) % n];
        int v = b[i];
        int t = max(v1, v2);
        int delta = v1 + v2;
        int cnt = (v - t + delta - 1) / delta;
        if (v - delta * cnt >= a[i]) {
            v -= delta * cnt;
            ans += cnt;
        }
        else {
            if ((v - a[i]) % delta == 0) {
                ans += (v - a[i]) / delta;
                v = a[i];
            }
            else {
                cout << -1 << endl;
                return 0;
            }
        }
        b[i] = v;
        if (b[i] > a[i]) {
            st.insert({b[i], i});
        }

//        for (int i = 0; i < n; ++i) {
//            cerr << b[i] << " ";
//        }
//        cerr << endl << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

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

int head(int x){
  while(x>=10){
    x /= 10;
  }
  return x;
}

int foot(int x){
  return x%10;
}

int main(){
  int N;cin >> N;
  vector<vector<int>> M(10,vector<int>(10,0));
  for(int i=1;i<=N;i++){
    M[head(i)][foot(i)] ++;
  }
  ll sum = 0;
  for(int i=1;i<=9;i++){
    sum += M[i][i]*M[i][i];
    for(int j=i+1;j<=9;j++){
      sum += M[i][j]*M[j][i]*2;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3640
import sys
input=sys.stdin.readline
n=int(input())
from collections import deque
G=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
check=[False]*n
check[0]=True
check[n-1]=True
f_q=deque([0])
s_q=deque([n-1])
f_c=1
s_c=1
while not (len(f_q)==0 and len(s_q)==0):
    f_n=len(f_q)
    for i in range(f_n):
        now=f_q.popleft()
        for j in G[now]:
            if not check[j]:
                check[j]=True
                f_c+=1
                f_q.append(j)
    s_n=len(s_q)
    for i in range(s_n):
        now=s_q.popleft()
        for j in G[now]:
            if not check[j]:
                check[j]=True
                s_c+=1
                s_q.append(j)
if f_c>s_c:
    print('Fennec')
else:
    print('Snuke')




Measured memory_bytes: 59900
import sys
input = sys.stdin.readline
R, L, K = map(int, input().split())
V = [[0]*R for _ in range(L)]
for _ in range(K):
    r, c, v = map(int, input().split())
    V[c-1][r-1] = v
A, B, C, D = [[0]*(R+1) for _ in range(4)]
for i in range(L):
    for j in range(R):
        A[j] = max(A[j-1],B[j-1],C[j-1],D[j-1])
        v = V[i][j]
        if v != 0:
            D[j], C[j], B[j] = max(C[j]+v,D[j]), max(B[j]+v,C[j]), max(A[j]+v,B[j])
print(max(A[-2],B[-2],C[-2],D[-2]))

Measured memory_bytes: 140668
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc080.contest.atcoder.jp/tasks/arc080_b>
問題文============================================================
 縦 H 行、横 W 列のマス目があります。
 すぬけ君は、このマス目を色 1, 2, …, N で塗り分けようとしています。 このとき、次の条件が成り立つようにします。
 
 各 i (1≤i≤N) について、色 i のマスはちょうど ai 個存在する。 ただし、a1+a2+…+aN=HW である。
 
 各 i (1≤i≤N) について、色 i のマスは上下左右に連結である。
 すなわち、どの色 i のマスからどの色 i のマスへも、上下左右に隣り合う色 i のマスのみを辿って行き来できる。
 
 条件を満たす塗り分け方をひとつ求めてください。 解は必ず存在することが示せます。

=================================================================

解説=============================================================

 蛇のようにマスをなぞりながら値を入れていけばok
 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll H,W; cin >> H >> W;
    ll N; cin >> N;
    vector<ll> a(N);
    for(auto& in:a) cin >> in;
    
    
    vector<vector<int>> masu(H+2,vector<int>(W+2,-1));
    for(int i = 1; i <=H;i++) for(int j = 1; j<= W;j++) masu[i][j] = 0;
    
    int aidx = 0;
    for(int i = 1; i<= H;i++){
        if(i%2 == 1){
            for(int j = 1; j <= W;j++){
                masu[i][j] = aidx+1;
                a[aidx]--;
                if(a[aidx] == 0) aidx++;
            }
        }else{
            for(int j = W; j >= 1;j--){
                masu[i][j] = aidx+1;
                a[aidx]--;
                if(a[aidx] == 0) aidx++;
            }
        }
    }
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W;j++){
            cout << masu[i][j] << " ";
        }
        cout << endl;
    }
    
	return 0;
}


Measured memory_bytes: 384