akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
int n, x, y, a[1005], b[1005], o;
char c[] = "RUDL";
int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d%d", &x, &y);
    if(i && x+y&1^o) return puts("-1")*0;
    else o = x+y&1;
    if(!o) x++;
    a[i] = (1<<30)-(x+y+1)/2; b[i] = (1<<30)-(x-y+1)/2;
  }
  printf("%s", o ? "31\n" : "32\n 1 ");
  for(int i = 0; i < 31; i++) printf("%d%s", 1<<i, i == 30 ? "\n" : " ");
  for(int i = 0; i < n; i++){
    if(!o) printf("L");
    for(int j = 0; j < 31; j++) printf("%c", c[((a[i]>>j)&1)*2+((b[i]>>j)&1)]);
    puts("");
  }
}

Measured memory_bytes: 256
s=int(input())

li = list(map(int,input().split()))
li.sort()
cnt = 0
import bisect
for a in range(len(li)):
    for b in range(a + 1, len(li)):
       i = bisect.bisect_left(li, li[a]+li[b])
       cnt += i - b - 1

print(cnt)

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

using namespace std;
typedef long long nagai;

int main()
{
	int k;
	cin >> k; 
	vector<nagai> a(k);
	for (auto& x : a)
		cin >> x;
	nagai curmn = 2, curmx = 2;
	reverse(a.begin(), a.end());
	for (auto x : a)
	{
		if (curmn % x)
			curmn += x - curmn % x;
		curmx -= curmx % x;
		curmx += x - 1;
	}
	if (curmn > curmx)
		cout << -1 << endl;
	else
		cout << curmn << ' ' << curmx << endl;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	int a = 1, e = 1;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		a *= 3;
		if (A % 2 == 0) e *= 2;
	}
	cout << a - e << endl;
	return 0;
}


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

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

    if(abs(c-a)<=d){
        cout << "Yes" << endl;

    }
    else if(abs(b-a)<=d && abs(c-b)<=d){
        cout << "Yes" << endl;

    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0

for i in range(n):
    if a[i] < b[i]:
        b[i] -= a[i]
        ans += a[i]
        if b[i] < a[i + 1]:
            ans += b[i]
            a[i + 1] -= b[i]
        else:
            ans += a[i + 1]
            a[i + 1] = 0
    else:
        ans += b[i]
        b[i] = 0
        
print(ans)

Measured memory_bytes: 18476
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;}

/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r;
ll x[500005],y[500005],z[1200005];
ll dp[1005][1005];
bool flag,dame;
ll sta;
ll po[1200000];

int main(){
	cin >> h >> w >> n;
	if(n % 2 == 1){
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if((i + j) % 2 == 1)pu("R");
				if((i + j) % 2 == 0)pu("G");
			}
			el;
		}
		return 0;
	}else{
		ll syuki = 2 * n;
		for(i=0;i<2*n;i++){
			for(j=0;j<2*n;j++){
				a = 0;
				if(0 <= (i + j) % syuki && ((i + j) % syuki) < n)a += 2;
				if(0 <= ((i - j + 1000 * syuki) % syuki) && ((i - j + 1000 * syuki) % syuki) < n)a += 1;
				dp[i][j] = a;
			}
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				a = i % syuki;
				b = j % syuki;
				if(dp[a][b] == 1)pu("R");
				if(dp[a][b] == 2)pu("Y");
				if(dp[a][b] == 3)pu("G");
				if(dp[a][b] == 0)pu("B");
			}
			el;
		}
	}
	return 0;
}

Measured memory_bytes: 44032
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N;
  cin >> N;

  ll x = 0;
  ll y = 0;
  ll z = 0;

  rep (i, N) {
    ll a, b, c;
    cin >> a >> b >> c;

    ll s, t, u;
    s = max(a+y, a+z);
    t = max(b+x, b+z);
    u = max(c+x, c+y);

    x = s;
    y = t;
    z = u;
  }

  cout << max(max(x, y), z) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	int count;
	public static void main(String[] args) {
		Main pmClass = new Main();

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
			pmClass.calc(array[i]);
		}
		System.out.println(pmClass.count);
	}
	public void calc(int a){
		boolean pm = true;
		if(a <= 1 || a % 2 == 0) {
			pm = false;
		}
		if(a == 2) {
			pm = true;
		}
		for(int i = 3; i <= Math.sqrt(a); i += 2) {
			if (a % i == 0) {
				pm = false;
				break;
			}
		}
		if (pm) count++;
	}
}


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

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

using namespace std;

vector<vector<int>> L;

int dfs(int i){
	int m=L[i].size();
	vector<int> dep(m);
	rep(j,m) dep[j]=dfs(L[i][j]);
	sort(dep.rbegin(),dep.rend());

	int res=0;
	rep(j,m) res=max(res,dep[j]+j+1);
	return res;
}

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

	printf("%d\n",dfs(0));

	return 0;
}


Measured memory_bytes: 19712
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;

using namespace std;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie();
    int n;
    cin >> n;
    cout << (n + 1) / 2;
}

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

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

	long long count = 0;

	// A * B + C = N
	for (int numA = 1; numA <= numN; numA++)
	{
		int tmpCount = (numN-1) / numA;
		count += tmpCount;
	}
	
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
 
bool check(int a, int b , int c){
    return ( a*a == ( b*b + c*c ) )? true : false ;
}
 
int main(){
    int n, a, b, c;
 
    cin >> n;
    for(int i=0 ; i<n ; i++){
        cin >> a >> b >> c;
        if( check(a,b,c) || check(b,c,a) || check(c,a,b) ){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
constexpr auto INF = 2147483647;
typedef long long ll;

int main(){

  ll h, w;
  ll ans = 0;
  cin >> h >> w;
  
  ans += (h/2)*w;
  if(h%2 != 0) ans += (w/2) + (w%2);

  if(h == 1 or w == 1) ans = 1;
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
    string S, T;
    cin >> S >> T;

    u64 ans = UINT64_MAX;

    for(u64 i=0; i<=S.size()-T.size(); i++) {
        u64 tans = 0;
        for(u64 j=0; j<T.size(); j++) {
            if(S[i+j] != T[j]) tans++;
            if(tans >= ans) break;
        }
        ans = min(ans, tans);
    }

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

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

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


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a,b,c;
	cin>>a>>b;
	cout<<(a+b+1)/2;
}

	


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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define MOD 1000000007
const double PI=3.14159265358979323846;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> T Ceil(T a, T b){return (a+b-1)/b;}

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

int main() {
    cout<<fixed<<setprecision(10);

    ll a,b,c,d; cin>>a>>b>>c>>d;

    while(true){
        c -= b;
        if(c<=0){
            puts("Yes");
            return 0;
        }

        a -= d;
        if(a<=0){
            puts("No");
            return 0;
        }
    }

    return 0;

}

Measured memory_bytes: 3676
N, K = map(int, input().split())
A = list(map(int, input().split()))

def is_ok(L):
    count = 0
    for a in A:
        count += a // L
        if a % L == 0:
            count -= 1
    return count <= K

ng = 0
ok = max(A)
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if is_ok(mid):
        ok = mid
    else:
        ng = mid
print(ok)


Measured memory_bytes: 93764
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<Pi,int> Pii;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int a,b,c,d;
	char s[5];

	cin>>s[0]>>s[1]>>s[2]>>s[3];

	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';

	if((a+b+c+d)==7){
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
	}else if((a+b+c-d)==7){
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
	}else if((a+b-c-d)==7){
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
	}else if((a-b-c-d)==7){
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
	}else if((a-b+c+d)==7){
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
	}else if((a-b-c+d)==7){
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
	}else if((a+b-c+d)==7){
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
	}else if((a-b+c-d)==7){
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
	}


	return 0;
}


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

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, M; cin >> M >> N;
  vector<vector<PII>> R(M, vector<PII>(N,PII(0,1000)));
  bool valid = true;
  REP(i,M){
	int K; cin >> K;
	REP(j,K){
	  int s, t; string c;
	  cin >> s >> c >> t;
	  --s;
	  if(c == "<=")
		R[i][s].SS = min(R[i][s].SS, t);
	  else
		R[i][s].FF = max(R[i][s].FF, t);
	  if(R[i][s].FF > R[i][s].SS) valid = false;
	}
  }
  if(!valid){
	cout << "No" << endl;
	return 0;
  }
  
  VVI G(M);
  REP(i,M) REP(j,M){
	if(i == j) continue;
	bool ok = true;
	REP(s,N){
	  if(R[j][s].SS < R[i][s].FF) ok = false;
	}
	if(!ok) G[i].PB(j);
  }

  vector<bool> use(M);
  bool up = true;
  while(up){
	up = false;
	REP(i,M){
	  if(use[i]) continue;
	  bool ok = true;
	  for(int to: G[i])
		if(!use[to])
		  ok = false;
	  if(ok) use[i] = up = true;
	}
  }
  cout << (all_of(ALL(use),[](bool x){return x;})? "Yes": "No") << endl;
  
  return 0;
}

Measured memory_bytes: 3340
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      
      // 計算
      Long sum = 0L;
      for(int i = 1; i <= N; i++){
        if(i % 5 != 0 && i % 3 != 0){
          sum += i;
        }
      }
      
      // 出力
      System.out.println(sum);
    }

}

Measured memory_bytes: 48260
n,a,b,c,d = map(int,input().split())
s = input()

if('##' in s[a-1:d]):
    print('No')
    exit()
if(c < d):
    print('Yes')
else:
    if('...' in s[b-2:d+1]):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
signed main(){
	string S;
	cin >> S;
	ll sum = 0;
	for(int i = 0; i < S.length(); i++){
		sum += S.at(i)-'0';
	}
	cout << ((sum%9 == 0)?"Yes":"No") << endl;
 
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

using BS = bitset<25601>;

void solve() {
  int h, w;
  cin >> h >> w;
  vector<vi32> a(h, vi32(w));
  vector<vi32> b(h, vi32(w));
  cin >> a >> b;
  
  vector<vi32> c(h, vi32(w));
  rep(i, h) rep(j, w) c[i][j] = abs(a[i][j] - b[i][j]);

  vector<vector<BS>> dp(h, vector<BS>(w));

  dp[0][0] = BS().set(12800 + c[0][0]);
  rep(i, h) rep(j, w) {
    if (i < h - 1) {
      dp[i + 1][j] |= dp[i][j] << c[i + 1][j];
      dp[i + 1][j] |= dp[i][j] >> c[i + 1][j];
    }
    if (j < w - 1) {
      dp[i][j + 1] |= dp[i][j] << c[i][j + 1];
      dp[i][j + 1] |= dp[i][j] >> c[i][j + 1];
    }
  }
  int ans = 1e9;
  repc(i, 25600) if (dp[h - 1][w - 1].test(i)) {
    amin(ans, abs(i - 12800));
  }
  cout << ans << endl;
}


Measured memory_bytes: 20736
while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        exit()
    if m==-1 or f==-1:
        print('F')
    elif m+f>=80:
        print('A')
    elif m+f>=65:
        print('B')
    elif m+f>=50:
        print('C')
    elif m+f>=30 and r>=50:
        print('C')
    elif m+f>=30:
        print('D')
    else:
        print('F')


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define DEBUG(x) cerr << #x << " = " << x << endl

pair<int, int> getFirstSecond(const map<char, int> &cnt) {
  vector<int> numbers;
  for(auto iter : cnt) numbers.push_back(iter.second);
  sort(numbers.begin(), numbers.end());
  if(numbers.size() == 1) {
    return make_pair(numbers.back(), 0);
  }
  else {
    return make_pair(numbers[numbers.size() - 1], numbers[numbers.size() - 2]);
  }
}

signed main() {
  ios::sync_with_stdio(false);
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    vector<char> C(N);
    REP(i,N) cin >> C[i];
    map<char, int> cnt;
    bool TIE = true;
    char ansC;
    int ansNum;
    for(int i = 0; i < N; ++i) {
      cnt[C[i]]++;
      auto pii = getFirstSecond(cnt);
      if(pii.first > pii.second + (N - i - 1)) {
        TIE = false;
        ansC = C[i];
        for(auto iter : cnt) {
          if(iter.second > cnt[ansC]) {
            ansC = iter.first;
          }
        }
        ansNum = i;
        break;
      }
    }
    if(TIE) {
      cout << "TIE" << endl;
    }
    else {
      cout << ansC << " " << ansNum + 1 << endl;
    }
  }
}

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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
		int[] arr = new int[n];
		for(int i = 0 ; i < n ; ++i)arr[i] = scan.nextInt();
		int[] dp = new int[n];
		dp[0] = 0;
		for(int i = 1 ; i < n ; ++i) {
			int min = Integer.MAX_VALUE;
			for(int j = i - 1 ; j >= Math.max(0,i - k); j--) {
				min = Math.min(min, Math.abs(arr[i]-arr[j])+dp[j]);
			}
			dp[i] = min;
		}
		
		System.out.println(dp[n-1]);
	}
}


Measured memory_bytes: 50484
#include<bits/stdc++.h>
using namespace std;
int ar[100005];
int main()
{
  int n, a, b,ok=0,sum=0,x;
  cin>>a>>b;
  for(int i=1; i<=b; i++)
  {
   cin>>x;
   sum=sum+x;
  }
  if(sum>=a)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}

Measured memory_bytes: 256
### subroutines

def check_rank(favs, nofavs, j, k, l)
  tx, tname = nofavs[k - j]
  sum = 0

  for i in (0...j)
    xi, namei = favs[i]
    diff = tx - xi
    diff += 1 if namei > tname
    sum += diff if diff > 0
  end

  sum <= l
end

### main

loop do
  n, m, k, l = gets.split.map(&:to_i)
  break if (n | m | k | l) == 0

  chrs = []
  for i in (0...n)
    namei, xi = gets.strip.split
    chrs << [xi.to_i, namei]
  end

  fcache = {}
  m.times do
    fcache[gets.strip] = true
  end

  favs = []
  nofavs = []
  for ch in chrs.sort{|a, b| c = (b[0] <=> a[0]); c != 0 ? c : a[1] <=> b[1]}
    if fcache[ch[1]]
      favs << ch
    else
      nofavs << ch
    end
  end
  #p favs
  #p nofavs

  lb = 0
  ub = [m, k].min + 1

  while lb + 1 < ub
    mb = (lb + ub) / 2

    if k - mb >= n - m
      lb = mb
      next
    end

    if check_rank(favs, nofavs, mb, k, l)
      lb = mb
    else
      ub = mb
    end
  end

  puts lb
end

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

int main() {
	int a=0, b=0, c=0, k=0;
	cin >> a >> b >> c >> k;
	rep(i, k) {
		if (a >= b) b *= 2;
		else if (b >= c) c *= 2;
	}
	if (a < b && b < c) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

int main()
{
    ll l, r, d;
    cin >> l >> r >> d;
    ll sum = 0;
    for(ll i = l;i <= r;i++)
    {
        if(i % d == 0)sum++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int T[N],M;
    int sum =0;
    for(int i=0; i<N; i++){
       cin >> T[i];
       sum=sum+T[i];
    }
    cin >> M;
    int X[M],P[M],SUM[M];
    for (int j=0; j<M; j++){
        cin >> P[j] >> X[j];
        SUM[j]=sum-T[P[j]-1]+X[j];
    }
    for(int k=0; k<M; k++){
    cout << SUM[k] << endl;}
       return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
using namespace std;

int main() {
	int n, q;
	cin >> n >> q;
	int time;
	string name;
	queue<pair<string, int> > process;
	for (int i = 0; i < n; i++) {
		cin >> name >> time;
		process.push(make_pair(name, time));
	}

	long long ans = 0;
	while (!process.empty()) {
		int t = process.front().second;
		string s = process.front().first;
		process.pop();
		if (t <= q) {
			ans += t;
			cout << s << " " << ans << endl;
		}
		else {
			ans += q;
			t -= q;
			process.push(make_pair(s, t));
		}
	}

}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

struct RMQ {
	using type = int;
	static type id() { return INT_MAX; }
	static type op(const type& l, const type & r) { return min(l, r); }
};

struct RMaxQ {
	using type = int;
	static type id() { return INT_MIN; }
	static type op(const type& l, const type & r) { return max(l, r); }
};

template <typename M>
class segment_tree {
	using T = typename M::type;
	const int n;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
public:
	segment_tree(int n_) : n(size(n_)), data(n * 2, M::id()) {}
	segment_tree(int n_, T val) : n(size(n_)), data(n * 2, val) {}
	void init(const vector<T>& data_) {
		for (int i = 0; i < (int)data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = M::op(data[i * 2], data[i * 2 + 1]);
	}
	void update(int p, T val) {
		p += n;
		data[p] = val;
		while (p >>= 1) data[p] = M::op(data[p * 2], data[p * 2 + 1]);
	}
	void add(int p, T val) {
		p += n;
		data[p] += val;
		while (p >>= 1) data[p] = M::op(data[p * 2], data[p * 2 + 1]);
	}
	T find(int l, int r) {
		l += n; r += n + 1;
		T res1 = M::id(), res2 = M::id();
		while (l < r) {
			if (l & 1) res1 = M::op(res1, data[l++]);
			if (r & 1) res2 = M::op(data[--r], res2);
			l >>= 1; r >>= 1;
		}
		return M::op(res1, res2);
	}
};

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

  LL N, K;
  cin >> N >> K;
  vector<int> P(N);

  segment_tree<RMQ> seg_min(N);
  segment_tree<RMaxQ> seg_max(N);

  REP(i,N){
    cin >> P[i];
  }
  
  seg_min.init(P);
  seg_max.init(P);

  set<pii> set_ans;

  vector<LL> sorted_down(N, 0);
  vector<LL> sorted_up(N, 0);
  
  REP(i,N){
    if(i==0){
      sorted_down[i] = 0;
    }else{
      if(P[i]>P[i-1]){
        sorted_down[i] = sorted_down[i - 1] + 1;
      }
      else
      {
        sorted_down[i] = 0;
      }
    }
  }
  
  REP(j,N){
    LL i = N - j - 1;
    if (i == N - 1 )
    {
      sorted_up[i] = 0;
    }else{
      if(P[i] < P[i+1]){
        sorted_up[i] = sorted_up[i + 1] + 1;
      }
      else
      {
        sorted_up[i] = 0;
      }
    }
  }

  LL cnt = 0;

  REP(i,N-K + 1){
    LL left = i;
    LL right = i + K - 1;
    if(sorted_up[left]>=K-1 &&sorted_down[right]>=K-1){
      cnt++;
      continue;
    }
    LL min_num = seg_min.find(left, right);
    LL max_num = seg_max.find(left, right);
    LL ans_left = left;
    LL ans_right = right;
    if (left != 0)
    {
      if(P[left-1] < min_num){
        ans_left -= sorted_down[left-1] + 1;
      }
    }
    if (right != N-1)
    {
      if(P[right+1] > max_num){
        ans_right += sorted_up[right+1] + 1;
      }
    }
    set_ans.insert({ans_left, ans_right});
  }

  cout << set_ans.size() + min(cnt,1LL)<< endl;
}


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

typedef long long int ll;
typedef vector<int> vi;            typedef vector<ll> vl;
typedef vector<vi> vvi;         typedef vector<vl> vvl;
typedef pair<int, int>     pii;    typedef pair<ll, ll> pll;
typedef vector<pii> vii;         typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
const ll INFL = 1e18;
const int INFI = 1e9;
#ifdef KARAN
    #include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
    while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
    int n; cin>>n;
    string s; cin>>s;
    if(s.size()<=n)
        cout<<s<<endl;
    else
        cout<<s.substr(0, n)<<"..."<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifdef KARAN
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        freopen("err.txt", "w", stderr);
    #endif
    int t=1;
    while(t--)
        solve();
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<math.h>
#include<utility>
#include<iomanip>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	int ans = log(n) / log(k) + 1;
	cout << ans;

}



Measured memory_bytes: 512
#include<stdio.h>
int main(){
    int i,a,b,c,a1,a2,a3,sum=0;
    scanf("%d%d%d",&a1,&a2,&a3);
    a=(a=(a1>a2)?a1:a2)>a3?a:a3;
    if((a1>a2&&a2<a3)||(a3>a2&&a2<a1)) b=a2;
    else if((a2>a1&&a1<a3)||(a3>a1&&a1<a2)) b=a1;
    c=(c=(a1<a2)?a1:a2)<a3?c:a3;
    sum+=(a-b)+(b-c);
    printf("%d\n",sum);

    return 0;
}


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

int main(){
	string s;
	cin>>s;
	string res=s;
	int p = 0;
	for (int i = 0; i < s.length(); i++){
		if(s[i]=='0'){
			res[p++] = '0';
		}else if(s[i]=='1'){
			res[p++] = '1';
		}else{
			p += p>0?-1:0;
		}
	}
	for (int i = 0; i < p; i++){
		cout<<res[i];
	}
	cout<<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++)

int main(){
  long long n,m,a;
  cin >> n >> m;
  rep(i,m){
    scanf("%lld",&a);
    n = n-a;
    if(n<0){
      n = -1;
      break;
    }
  }
  cout << n << endl;
}

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

#define INF 1e9
using namespace std;

long int vi[100005];
long int dp[100005][105];
int wi[100005];
int main()
{
	int n,w,sum=0,value=0;
	scanf("%d%d",&n,&w);
	for(int i=0;i<n;++i)
	{
		scanf("%d%ld",wi+i,vi+i);
		sum += vi[i];
	}
	for(int i=0;i<=sum;++i)
	{
		for(int j=0;j<=n;++j)
		{
			if(i == 0 && j == 0)
			dp[i][j] = 0;
			else if(j == 0)
			dp[i][j] = INF;
			else if(vi[j-1] > i)
			dp[i][j] = dp[i][j-1];
			else
			dp[i][j] = min(dp[i][j-1],dp[i-vi[j-1]][j-1]+wi[j-1]); 
		}
		if(dp[i][n] <= w)
		value = i;
	}
	printf("%d\n",value);
	return 0;
}


Measured memory_bytes: 82304
/*
  AOJ 2205
  Title:Lottery Checker
  @kankichi573
*/
#include <stdio.h>

int n,m;
char tousen[1000][9];
int  shoukin[1000];
char mykuji[9];

my_match(char c1,char c2)
{
  return((c1==c2)||(c1=='*'));
}

mystrncmp(char s1[],char s2[],int n)
{
  int i;
  for(i=0;i<n;i++)
    if(!my_match(s1[i],s2[i]))
      return(0);
  return(-1);
}
solve(char kuji[])
{
  int i,sum;
  sum=0;
  for(i=0;i<n;i++)
    {
      //printf("%s %s",&tousen[i][0],kuji);
      if(mystrncmp(&tousen[i][0],kuji,8))
	sum += shoukin[i];
    }
  return(sum);
}
main()
{
  int i,sum;

  while(scanf("%d %d",&n,&m) && (n||m))
    {
      for(i=0;i<n;i++)
	scanf("%s %d",&tousen[i][0],&shoukin[i]);
      sum=0;
      for(i=0;i<m;i++)
	{
	  scanf("%s",mykuji);
	  //printf("%s\n",mykuji);
	  sum += solve(mykuji);
	}
      printf("%d\n",sum);
    }
  return(0);
}

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

using namespace std;


int main(){
    long long a, b, x, cnt = 0;
    scanf("%lld %lld %lld", &a, &b, &x);
    long long c1 = a/x;
    long long c2 = b/x;
    cnt = c2 - c1;
    if(a % x == 0) cnt++;
    printf("%lld\n", cnt);
    return 0;
}


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

to0 = list(range(n+1))[:x]
cost1 = len(set(to0) & set(a))

ton = list(range(n+1))[x:]
cost2 = len(set(ton) & set(a))

ans = min(cost1, cost2)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
 int A,B;
 cin>> A >> B;
 int count = 0;
  int one = max(A,B);
  if(one==A){
  count += A;
  A -=1;
  }
  else{
  count += B;
  B -=1;
  }
  int two = max(A,B);
  if(two==A){
    count += A;  
  }
  else{
    count += B;
  }
  cout<< count <<endl;

  }


Measured memory_bytes: 256
def main():
    cnt = int(input())
    str = input()

    sum_str = []
    sum_cnt = 0
    for i in range(len(str)):
        sum_cnt += 1
        if (sum_cnt > cnt):
            sum_str.append('...')
            break
        sum_str.append(str[i])

    str2 = ''.join(sum_str)

    print(str2)


if __name__ == "__main__":
    main()

Measured memory_bytes: 8896
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;
    ll ac=0,tle=0,wa=0,re=0;
    while(n--)
    {

        string s;
        cin>>s;
        
        if(s=="AC")
        ac++;
        else if(s=="TLE")
        tle++;
        else if(s=="WA")
        wa++;
        else
        re++;
    }
    
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
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()
{
  string s; cin >> s;
  int k; cin >> k;
  vector<int> d(k);
  rep(i,k) cin >> d[i];
  
  set<int> st;
  rep(i,k) st.insert(d[i]);
  
  vector<int> x;
  rep(i,10) if( st.find(i) == st.end() ) x.push_back(i);

  int n = s.size();
  const int inf = 1e+9;
  vector<vector<int>> dp(n+1, vector<int>(2, inf));
  if(x[0] == 0) dp[0][1] = x[1];
  else dp[0][1] = x[0];
  dp[0][0] = 0;
  rep(i,n) {
    int m = s[i] - '0';
    rep(j,x.size()) {
      chmin(dp[i+1][1], dp[i][1]*10 + x[j]);
      if(m == x[j]) {
	chmin(dp[i+1][0], dp[i][0]*10 + x[j]);
      }
      else if(m < x[j]) {
	chmin(dp[i+1][1], dp[i][1]*10 + x[j]);
	chmin(dp[i+1][1], dp[i][0]*10 + x[j]);
      }
    }
  }
  
  cout << min(dp[n][0], dp[n][1]) << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check
const ll INF = 1LL << 60;

void solve(long long H, long long W, long long D, std::vector<std::vector<long long>> A, long long Q, std::vector<long long> L, std::vector<long long> R){
    map<ll, pll> AijToCoord;
    vector<vll> rec(D), sum(D);
    REP(i, H){
        REP(j, W){
            AijToCoord[A[i][j]] = pll(i, j);
            rec[A[i][j]%D].push_back(A[i][j]);
        }
    }
    REP(i, D){
        sort(ALL(rec[i]));
        sum[i].push_back(0);
        REP(j, rec[i].size()-1){
            ll tmp = sum[i][j];
            auto p = AijToCoord[rec[i][j]], p1 = AijToCoord[rec[i][j+1]];
            tmp += abs(p.first-p1.first) + abs(p.second-p1.second);
            sum[i].push_back(tmp);
        }
        /*
        REP(j, rec[i].size()){
            cout<< sum[i][j]<<" ";
        }
        cout<< endl;
        */
    }

    REP(q, Q){
        ll d = L[q] % D;
        ll L_idx = lower_bound(ALL(rec[d]), L[q]) - rec[d].begin();
        ll R_idx = lower_bound(ALL(rec[d]), R[q]) - rec[d].begin();
        cout<< sum[d][R_idx] - sum[d][L_idx]<<endl;
    }



}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long D;
    scanf("%lld",&D);
    std::vector<std::vector<long long>> A(H, std::vector<long long>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> L(Q);
    std::vector<long long> R(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
    }
    solve(H, W, D, std::move(A), Q, std::move(L), std::move(R));
    return 0;
}


Measured memory_bytes: 18176
#include<iostream>
#include<algorithm>

using namespace std;

int main(void){
    int w,h,n,i,ans=0,sx,sy,ex,ey;
    cin >> w >> h >> n;
    cin >> sx >> sy;
    n--;
    for(i=0; i<n; i++){
        cin >> ex >> ey;
        if((ex-sx)*(ey-sy)>0){
            ans += max(abs(ex-sx),abs(ey-sy));
        }else{
            ans += abs(ex-sx)+abs(ey-sy);
        }
        sx = ex;
        sy = ey;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string S; ll K; cin >> S >> K;
  
  for(ll i = 0; i < (ll) S.size(); i++){
    ll num = S[i] - 'a' ; 
    if( num == 0){ continue;}
    if( 26-num<= K){ S[i] = 'a'; K -= 26-num;}
  }
  
  if( K > 0){ //最後の文字に対してK回残りの操作を行う
    ll num = (ll)(S[(ll)S.size()-1] - 'a');
    K += num; K %= 26;S[(ll) S.size()-1] = (char)(K +'a');}
  
  cout << S << endl;  return 0;}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
string s;
int main(){
  cin>>s;
  int n=s.size();
  int cnt1=0,cnt2=0;
  rep(i,n){
    if(i%2==0){
      if(s[i]!='0'){
	cnt1++;
      }
    }
    else{
      if(s[i]!='1'){
	cnt1++;
      }
    }
  }
  rep(i,n){
    if(i%2==1){
      if(s[i]!='0'){
	cnt2++;
      }
    }
    else{
      if(s[i]!='1'){
	cnt2++;
      }
    }
  }
  // prin2(cnt1,cnt2);
  prin(min(cnt1,cnt2));

  

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
using namespace std;
typedef pair<string,string> P;
typedef pair<int,string> C;
#define F first
#define S second
int main(){
  int n;
  int i,j,k;
  while(cin >> n,n){
    vector<P> v;
    P p;
    for(i=0;i<n;i++) {
      cin >> p.F >> p.S;
      v.push_back(p);
    }
    queue<C> q;
    C c,b;
    int o=-1;
    c.F=0;cin >> c.S;
    string s,g;cin >> g;
    q.push(c);
    while(!q.empty()){
      c=q.front();q.pop();
      //cout << c.F << c.S << endl;
      if(c.S==g){
	o=c.F;
	break;
      }
      if(c.S.size()>=g.size()) continue;
      for(i=0;i<n;i++){
	b.F=c.F+1;b.S=c.S;
	if(b.S.find(v[i].F)==-1) continue;
        string::size_type pos = b.S.find(v[i].F);
	while(pos != string::npos){
	  b.S.replace(pos, v[i].F.size(), v[i].S);
	  pos = b.S.find(v[i].F, pos + v[i].S.size());
	}
	q.push(b);
      }
    }
    cout << o << endl;
  }
  return 0;
}

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

// 💖 Hi, thanks for using ICIE! 💖
// 🔧 To use a custom code template, press Ctrl+Shift+P and select "ICIE Template configure" from the list 🔧
// 📝 If you spot any bugs or miss any features, create an issue at https://github.com/pustaczek/icie/issues 📝
// 🎉 ... or just ask me about anything via Discord at https://discord.gg/ffSEhtb 🎉

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
int a,b;cin>>a>>b;
cout<<a*b<<endl;
}


Measured memory_bytes: 3652
# https://atcoder.jp/contests/abc126/tasks/abc126_f
import itertools
from collections import Counter
from collections import defaultdict
import bisect

def main():
    M, K = map(int, input().split())

    if M == 0:
        if K == 0:
            print('0 0')
        else:
            print('-1')
        exit()
    if M == 1:
        if K == 0:
            print('0 0 1 1')
        else:
            print('-1')
        exit()

    if 2 ** M <= K:
        print('-1')
    else:
        a = [i for i in range(2 ** M) if i != K]
        b = reversed(a)
        ans = ' '.join(map(str, a)) + ' ' + str(K) + ' ' + ' '.join(map(str, b)) + ' ' + str(K)
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 106748
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 for(;;){
  int n=ir.nextInt();
  int m=ir.nextInt();
  if(n==0&&m==0) return;
  int[][] r=new int[n][];
  for(int i=0;i<n;i++) r[i]=ir.nextIntArray(2);
  Arrays.sort(r,new Comparator<int[]>(){
   public int compare(int[] p,int[] q){
    return -Integer.compare(p[1],q[1]);
   }
  });
  int tot=0;
  for(int i=0;i<n;i++){
   if(m>=r[i][0]){
    m-=r[i][0];
   }
   else{
    r[i][0]-=m;
    m=0;
    tot+=r[i][0]*r[i][1];
   }
  }
  out.println(tot);
 }
}

public static void main(String[] args) throws Exception{
 ir=new InputReader(System.in);
 out=new PrintWriter(System.out);
 solve();
 out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;

 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
 
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }

 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

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

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

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

 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}

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

int h,w;
int i,j,count;
char field[100][105];

void erase(int x,int y){
	char t=field[x][y];
	field[x][y]=' ';
	if(x>0 && field[x-1][y]==t)erase(x-1,y);
	if(x<h-1 && field[x+1][y]==t)erase(x+1,y);
	if(y>0 && field[x][y-1]==t)erase(x,y-1);
	if(y<w-1 && field[x][y+1]==t)erase(x,y+1);
}

int main(){
	while(scanf("%d %d",&h,&w)*h*w){
		count=0;
		for(i=0;i<h;i++)scanf("%s",field[i]);
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(field[i][j]!=' '){
					count++;
					erase(i,j);
				}
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 1380
inf = 1 << 60
N,M=map(int,input().split())
X=[0]
Y=[0]
Z=[0]
for i in range(N):
    x,y,z=map(int,input().split())
    X.append(x)
    Y.append(y)
    Z.append(z)

max_sc = -inf
for sign in range(8):
    sign_x = 1 if (sign & 1) != 0 else -1
    sign_y = 1 if (sign & 2) != 0 else -1
    sign_z = 1 if (sign & 4) != 0 else -1

    # dp[i][j] = i個目までのケーキのうちj個選択したときの合計の最大値
    dp = [[-inf for j in range(M+1)] for i in range(N+1)]
    dp[0][0] = 0
    for i in range(1,N+1):
        for j in range(0,M+1):
            dp[i][j] = max(dp[i][j], dp[i-1][j])
        for j in range(1,M+1):
            dp[i][j] = max(dp[i][j], dp[i-1][j-1] + X[i]*sign_x + Y[i]*sign_y + Z[i]*sign_z)
    sc = dp[N][M]
    max_sc = max(max_sc, sc)
print(max_sc)


Measured memory_bytes: 122588