akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int mincost(int heights[], int n)
{
    int dp[n + 1];
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(heights[1] - heights[0]);
    for (int i = 3; i <= n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(heights[i - 1] - heights[i - 2]), dp[i - 2] + abs(heights[i - 1] - heights[i - 3]));
    }
    return dp[n];
}

int main()
{
    int n;
    cin >> n;
    int heights[n];
    for (int i = 0; i < n; i++)
    {
        cin >> heights[i];
    }
    int p = mincost(heights, n);
    cout << p;
    return 0;
}

Measured memory_bytes: 4336
/******************************************************************************

                              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 <iostream>

using namespace std;

int main()
{
    long long n,i,sum;
    cin>>n;
    long long arr[n];
    sum=0;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        sum=sum^arr[i];
    }
    for(i=0;i<n;i++)
    {
        cout<<(sum^arr[i])<<" ";
    }

    return 0;
}


Measured memory_bytes: 5136
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,bj;
int main()
{
    cin>>a>>b>>c;
    if(b>=a)
    {
        cout<<1<<endl;
        return 0;
    }
    if(c>=b)
    {
        cout<<-1<<endl;
        return 0;
    }
    if((a-b)%(b-c)>=1)bj=1;
    cout<<((a-b)/(b-c)+bj)*2+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n,k;
int a[200000];
int main(){
	cin >> n >> k;
	REP(i,n) {
		cin >> a[i];
	}

	sort(a,a +n);

	vector<int> b;int l = 0;
	REP(i,n){
		l++;
		if(i + 1 < n && a[i] != a[i + 1]){
			b.pb(l);
			l = 0;
		}
	}
	if(l > 0)
		b.pb(l);

	sort(b.begin(),b.end());

	int m = b.size() - k;

	int ans = 0;
	REP(i,m) {
		ans += b[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	int a,b;cin>>a>>b;
	if(a+b==15){
		cout<<"+"<<endl;
	}
	else if(a*b==15){
		cout<<"*"<<endl;
	}
	else{
		cout<<"x"<<endl;
	}
}

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

typedef long long int LL;
#define ED return 0;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x) LL(pow(x))
#define EQUAL(vec1,vec2) equal((vec1).cbegin(), (vec1).cend(), (vec2).cbegin());
const int INF = 999999999;
const long long int mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long int N;
    cin >> N;
    for(int i = int(sqrt(N));true;i--){
        if(N % i == 0){
            cout << int(log10(N / i)) + 1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a-1);i>=(b);i--)
#define all(x) (x).begin(), (x).end()
const int INF = 1e18;
const int MOD = 1e9+7;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<string> vstr;
void print() {cout<<'\n';}template<class Head,class...Tail>void print(Head&&head,Tail&&...tail){cout<<head;if(sizeof...(tail)!=0)cout<<" ";print(forward<Tail>(tail)...);}template<class T>void print(vector<T>&vec){for(auto&a:vec){cout<<a;if(&a!=&vec.back())cout<<" ";}cout<<'\n';}template<class T>void print(vector<vector<T>>&df){for(auto&vec:df){print(vec);}}
template<class T=int>T in() {T x;cin>>x;return(x);}
template<class T=int>vector<T> input_to_vector(int n) {vector<T>x;rep(i,n){T a;cin>>a;x.push_back(a);}return(x);}

signed main(){
     int n, i;
     cin >> n >> i;
     print(n - i + 1);
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
A.sort()
#print(A)

Ac = Counter(A).most_common()
#print(Ac)
ans = 0

for i in range(len(Ac)):
    if Ac[i][1] > 1:
        ans += Ac[i][1]-1

print(N-ans if ans%2 == 0 else N-ans-1)


Measured memory_bytes: 21980
import itertools
import numpy as np


def main():
    N, M = list(map(int, input().split(' ')))
    con = np.zeros((M, N))
    for i in range(M):
        row = np.array(list(map(int, input().split(' '))))
        switch_indices = row[1:] - 1
        con[i, switch_indices] = 1
    p = np.array(list(map(int, input().split(' '))))
    switches = itertools.product([0, 1], repeat=N)
    answer = 0
    for s in switches:
        lamp = np.dot(con, np.array(s)) % 2
        all_on = np.count_nonzero(lamp - p) == 0
        if all_on:
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14436
#include<iostream>
#include<string>
using namespace std;
int main(){
  string word;
  while(getline(cin,word)){
    for(int i=0; i<26; i++){
      string::size_type thisp = word.find("this");
      string::size_type thatp = word.find("that");
      string::size_type thep = word.find("the");
      if(thisp != string::npos || thatp != string::npos || thep != string::npos){cout <<word<<endl;break;}
      for(int j=0; j<word.size(); j++){
	if(word[j]<'z' && word[j]>='a'){word[j]++;}
	else if(word[j] == 'z'){word[j] = 'a';}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

#define N_MAX 10000005

using namespace std;

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

const ll mod = 1e9 + 7;
const int inf = 1e9;
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    bool can = true;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(x % 2 == 0){
            if(x % 3 != 0 && x % 5 != 0){
                can = false;
            }
        }
    }
    if(can){
        cout << "APPROVED";
    }else{
        cout << "DENIED";
    }
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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 C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define VIN(x) for(auto&youso_: (x) )cin>>youso_
#define VOUT(x, delim) for(auto&youso_: (x) )cout<<youso_<<delim;cout<<endl

#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) i64 __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    CIN(K);

    i64 x = 0;
    i64 idx = 1;
    i64 shift = 10 % K;
    i64 add = 7 % K;
    vector<bool> done(K, false);
    while (1) {
        x *= shift;
        x += add;
        x %= K;
        if (x == 0) {
            COUT(idx);
            break;
        }
        if (done[x]) {
            COUT(-1);
            break;
        } else done[x] = true;
        idx++;
    }

    return 0;
}


Measured memory_bytes: 3756
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")
           
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
           
using namespace std;
using namespace __gnu_pbds;
           
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
           
using matrix = vector<vector<ll>>;
template<typename T>
using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
           
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
//#define int long long;
           
void FAST_IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(20);
    #ifndef _offline
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif
}

const ll mod = 998244353;
const int MAXN = 1e5 + 100;
ll cnt[MAXN], dp[MAXN];

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

signed main() {
    FAST_IO();
    int n;
    cin >> n;
    int mx = 0;
    for (int i = 0; i < n; ++i) {
        int d;
        cin >> d;
        mx = max(mx, d);
        if (i == 0 && d != 0) {
            cout << 0 << '\n';
            return 0;
        }
        cnt[d]++;
    }
    if (cnt[0] != 1) {
        cout << 0 << '\n';
        return 0;
    }
    dp[0] = 1;
    for (int i = 1; i <= mx; ++i) {
        dp[i] = (dp[i - 1] * binpow(cnt[i - 1], cnt[i])) % mod;
    }
    cout << dp[mx] << '\n';
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<math.h>
#define ll long long
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define mp make_pair
using namespace std;
const int maxn = 2e5+5;

int main(){
	ll a; 
	string b;
	cin >> a >> b;
	ll x = (b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0');
	cout << a * x / 100 << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main(){
  int s,w; cin>>s>>w;
  if(w>=s) cout<<"unsafe"<<endl;
  else cout<<"safe"<<endl;
  return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int[][][] a = new int[5][4][11];
		
		for(int i=1; i<=4; i++){
		for(int j=1; j<=3; j++){
		for(int q=1; q<=10; q++){
			a[i][j][q] = 0;}}}
		
		int n = scan.nextInt();
		
		for(int i=0; i<n; i++){
			int b = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			int v = scan.nextInt();
			
			a[b][f][r] += v;}
			
		for(int i=1; i<=4; i++){
		for(int j=1; j<=3; j++){
		for(int q=1; q<=10; q++){
			System.out.print(" "+a[i][j][q]);}
			System.out.print("\n");}
			if(i!=4){
			System.out.println("####################");}}
	}
}


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

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	std::vector<int> a(n + 1);
	std::vector<long long[2]> sum(n + 1);
	for (int i{1}; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i{1}; i <= n; i++)
		sum[i][0] = sum[i - 1][0] + a[i];
	sum[1][1] = a[1];
	for (int i{2}; i <= n; i++)
		sum[i][1] = sum[i - 2][1] + a[i];
	
	// 最初ini個取る場合right[ini]が上限
	std::vector<int> right((n + 1) / 2 + 1);
	right[0] = 1 << 30;
	for (int ini{1}; ini <= (n + 1) / 2; ini++)
		right[ini] = (a[n - ini + 1] + a[n - 2 * ini + 2]) / 2;
	for (int q_i{}; q_i < q; q_i++)
	{
		int x;
		scanf("%d", &x);
		int lb{}, ub{(n + 1) / 2 + 1};
		while (lb + 1 < ub)
		{
			int mid{(lb + ub) / 2};
			if (right[mid] >= x) lb = mid;
			else ub = mid;
		}
		long long takahashi{sum[n][0] - sum[n - lb][0]};
		takahashi += sum[std::max(0, n - lb * 2)][1];
		printf("%lld\n", takahashi);
	}
	
	return 0;
}

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

#define rep(i,l,r) for(int i=l;i<=r;++i)
void out()
{
	puts("No");
	exit(0);
}
const int N=1e5+5;
int n,a0[3][N],a[N];
bool vis[N];

int main()
{
	//freopen("1.in","r",stdin);
	cin>>n;
	rep(i,0,2)
	rep(j,1,n)scanf("%d",a0[i]+j);
	bool fu[2]={};
	rep(i,1,n)
	{
		rep(j,0,1)
		if(abs(a0[j][i]-a0[j+1][i])!=1)out();
		a[i]=(a0[1][i]+1)/3;
		if(a[i]%2!=i%2)out();
		if(a0[0][i]>a0[2][i])fu[i%2]^=1;
	}
	rep(i,1,n)
	if(!vis[i])
	{
		bool w=0;vis[i]=1;
		for(int y=i;!vis[y=a[y]];){vis[y]=1;w^=1;}
		fu[i%2^1]^=w;
	}
	if(fu[0]||fu[1])out();
	puts("Yes");
}

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

int main () {
  int a, b;
  cin >> a >> b;
  if (b >= 0 && a <= 0) {
    cout << "Zero" << endl;
    return 0;
  }
  if (a > 0) {
    cout << "Positive" << endl;
    return 0;
  }
  if (b < 0 && a < 0) {
  	if ((b - a) % 2 == 0) {
      cout << "Negative" << endl;
    }  
    else {
      cout << "Positive" << endl;
    }
  }
}


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

using namespace std;

int main(){
	int n;
	cin>>n;
	set<string>s;
	for(int i = 1;i <= n;i++)
	{
		string s1;
		cin>>s1;
		s.insert(s1);
	}
	cout<<s.size()<<endl;
	return 0;
}

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

int main() {
  double N;
  cin >> N;
  vector<int> L(N);
  for(int i = 0; i < N; i++) {
    cin >> L.at(i);
  }
  sort(L.begin(), L.end());
  int a = 0;
  for(int i = 0; i < N-1; i++) {
    a = a + L.at(i);
  }
  if(a > L.at(N-1)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=[ii() for _ in range(n)]

chk=False
tmp=0
ans=0
for _ in range(n):
    if chk==False:
        ans+=1
    p=arr[tmp]
    if p==2:
        chk=True
    
    tmp=p-1

if chk:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 14516
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  std::set<int> v;
  int N; std::cin >> N;
  for (int i = 0; i < N; ++i) {
    int a; std::cin >> a;
    if (v.count(a)) {
      std::cout << "NO" << std::endl;
      return 0;
    }

    v.insert(a);
  }
  std::cout << "YES" << std::endl;
}


Measured memory_bytes: 9600
using System;
using System.Linq;

public class Program
{
	//limit
	static int A, B, C, N;

	static int[] l;

	public static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
		var A = input[0];
		var B = input[1];
		var C = input[2];

		var result = B / A;
		if (result > C)
		{
			result = C;
		}

		Console.WriteLine(result);
	}
}


Measured memory_bytes: 13268
#include <iostream>
using namespace std;
int main(){
int W,H,x,y,r;

cin>>W>>H>>x>>y>>r;

if(-100<=x&&x<=100&&-100<=y&&y<=100&&0<W&&W<=100&&0<H&&H<=100&&0<r&&r<=100){
if(x<=(W-r)&&y<=(H-r)&&r<=x&&r<=y)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}

return 0;

}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    map<string,string> ans{
        {"A","T"},
        {"T","A"},
        {"G","C"},
        {"C","G"}
    };
    string st;
    cin>>st;
    cout<<ans[st]<<endl;
    return 0;
}

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

pen= [0] * (n+1)
result=[False] * (n+1)
cnt = 0
pen_sum = 0
for i in range(m):
    p1, s1 = input().split()
    p1 = int(p1)
    if s1 == "AC" and not result[p1]:
        result[p1] = True
        cnt += 1
        pen_sum += pen[p1]
    if s1 == "WA" and not result[p1]:
        pen[p1] += 1

print("{} {}".format(cnt, pen_sum))


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, a, b;
  cin >> k >> a >> b;
  if(a%k && b%k && a/k == b/k) {
    cout << "NG";
  } else {
    cout << "OK";
  }
  cout << endl;
  return 0;
}

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    string s, t = ""; cin >> s;
    REP(i, 0, s.size()){
        if(s[i] != 'x'){
            t = t + s[i];
        }
    }
    int en = t.size()-1;
    REP(i, 0, t.size()/2){
        if(t[i] != t[en-i]){
            cout << -1 << endl;
            return 0;
        }
    }
    vector<int> lis(t.size()+1, 0), lis2(t.size()+1, 0);
    int l = 0;
    REP(i, 0, (t.size()+1)/2){
        int count = 0;
        while(1){
            if(s[l] == t[i]){
                lis[i] = count;
                l++;
                break;
            }else{
                count++;
                l++;
            }
        }
    }
    reverse(ALL(s));
    reverse(ALL(t));
    l = 0;
    REP(i, 0, (t.size()+1)/2){
        int count = 0;
        while(1){
            if(s[l] == t[i]){
                lis2[i] = count;
                l++;
                break;
            }else{
                count++;
                l++;
            }
        }
    }
    ll ans = 0;
    REP(i, 0, lis.size()){
        ans += abs(lis[i] - lis2[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1464
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: usize,
    p: [usize1; n]
  }
  let mut rev = vec![0; n];
  for &i in p.iter() {
    rev[p[i]] = i;
  }
  let mut max_inc = 0;
  let mut l = 0;
  for r in 0 .. n {
    if l < r && rev[r-1] > rev[r] {
      max_inc = cmp::max(max_inc, r - l);
      l = r;
    }
  }
  max_inc = cmp::max(max_inc, n - l);

  println!("{}", n - max_inc);
}


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

using namespace std;

int n;
set<string> cnt;

bool check(string s){
	bool siti=false,go=false,san=false,other=false;

	for(auto a:s){
		if(a=='7'){
			siti=true;
		}else if(a=='5'){
			go=true;
		}else if(a=='3'){
			san=true;
		}else{
			other=true;
		}
	}

	if(siti && go && san && !other) return true;
	else return false;
}

void solve(string s){
	if(stoll(s)>n) return;

	if(check(s)) cnt.insert(s);

	solve(s+"3");
	solve(s+"5");
	solve(s+"7");

	return;
}

int main(){
	cin>>n;
	solve("3");
	solve("5");
	solve("7");

	cout<<cnt.size()<<endl;

	return 0;
}


Measured memory_bytes: 3072
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
m=0

for i in range(n):
    b[i]=(a[i]+1)/2

c=sum(b[:k])
m=c
for i in range(n-k):
    c-=b[i]
    c+=b[k+i]
    m=max(m,c)
print(m)

Measured memory_bytes: 99840
<?php
 
$line = fgets(STDIN); 
$arr = explode(" ", $line);
$N = $arr[0];
$M = $arr[1];
$line = fgets(STDIN); 
$A = explode(" ", $line);

for($i=0; $i<$M; $i++){
  $N = $N - $A[$i];
  if($N < 0) {
    $ans = -1;
    break;
  }
  $ans = $N;
}

echo $ans;

Measured memory_bytes: 16864
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define el(a) (a).end()-(a).begin()
#define mod 1000000007
#define inf 2147483647
int main(){
	int h,w,k;
	cin>>h>>w>>k;
	char c[h][w];
	rep(i,h)rep(j,w)cin>>c[i][j];
	int row[h],col[w],count,ans=0;
	rep(i,1<<h){
		rep(o,h)row[o]=(i>>o)&1;
		rep(j,1<<w){
			rep(o,w)col[o]=(j>>o)&1;
			count=0;
			rep(a,h)rep(b,w){
				if(row[a]==0&&col[b]==0){
					if(c[a][b]=='#'){
						count++;
					}
				}
			}
		if(count==k)ans++;
		}
	}
	cout<<ans;		
	return 0;
}

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

int main(void) {
  int N, ans = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  for (int i = 0; i < N; i++) {
    ans += (i % 2 == 0 ? a[i] : -a[i]);
  }
  cout << ans << endl;
  return 0;
}

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

int isKaibun(int n){
  if((n/10000==n%10) && ((n/1000)%10==(n/10)%10))return 1;
  return 0;
}

int main(){
  int a,b,i,cnt=0;
  cin>>a>>b;
  for(i=a;i<=b;i++){
    if(isKaibun(i)==1)cnt++;
  }
  cout<<cnt;
}

Measured memory_bytes: 256
def readinput():
    n=int(input())
    ab=[]
    for _ in range(n):
        a,b=map(int,input().split())
        ab.append((a,b))
    return n,ab

def main(n,ab):
    count=0
    for a,b in ab:
        if a==b:
            count+=1
            if count>=3:
                return 'Yes'
        else:
            count=0
    return 'No'

if __name__=='__main__':
    n,ab=readinput()
    ans=main(n,ab)
    print(ans)


Measured memory_bytes: 9192
from collections import deque
N,Q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N-1)]
px = [list(map(int,input().split())) for _ in range(Q)]

tree = [[] for _ in range(N)]
for a, b in ab:
  tree[a-1].append(b-1)
  tree[b-1].append(a-1)

counter = [0] * N
for p, x in px:
  counter[p-1] += x
  
flag = [1] * N
t = deque()
t.append(0)

#1(0)から順に探索していけば、自然と親→子の順番になる
while t:
  v = t.popleft()
  flag[v] = 0
  for i in tree[v]:
    if flag[i]:
      counter[i] += counter[v]
      t.append(i)
      
print(*counter)

Measured memory_bytes: 127552
#include<iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n,i,j,t;
	while(cin>>n)
	{
		t=0;
		for(i=0;i<=n/4;i++)
		{
			for(j=0;j<=(n-4*i)/7;j++)
			{
				if((4*i+j*7)==n)
				   t++;
			}
		}
		if(t==0)
		   cout<<"No"<<endl;
		else
		   cout<<"Yes"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b, c;

    cin >> a >> b >> c;

    int res = min(c, b / a);
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret

print(dfs(0, 'TTT'))

Measured memory_bytes: 81392
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

//----------------------------------------
int n;
vector<int> x;

vector<int> y;

double ans=0;

int kaijo(int r)
{
	if (r == 1) return 1;
	else  return r * kaijo(r - 1);

}


void func(vector<int> a, int keta, vector<bool> use)
{
	if (keta == n)
	{
		double dist=0;
		for (int i = 1; i < n ; i++)
		{
			dist +=sqrt(pow(x[a[i]-1] - x[a[i-1 ]-1], 2) + pow(y[a[i]-1] - y[a[i-1 ]-1], 2));
		}
		int s;

		ans += dist;
		return;
	}

	else
	{
		for (int i = 1; i <= n; i++)
		{
			if (!use[i])
			{
				vector<bool> use2 = use;
				use2[i] = true;
				vector<int> a2 = a;
				a2.push_back(i);
				func(a2, keta + 1,use2);


			}
		}
	}
}



int main(void)
{
	
	cin >> n;

	x = vector<int>(n+1);
	y = vector<int>(n+1);
	rep(i, n)
	{
		cin >> x[i] >> y[i];
	}

	vector<int> a;
	int keta = 0;

	vector<bool> use(n+1);

	func(a, keta,use);
	
	ans /= kaijo(n);

	cout<<setprecision(12) << ans << endl;

}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vi g[300];
vi cost;
bool dfs(int v, int c=1){
    cost[v] = c;
    for(auto u : g[v]){
        if(cost[u] == 0 && !dfs(u, c+1)) return false;
        if(abs(cost[v] - cost[u]) % 2 == 0) return false;
    }
    return true;
}

int bfs(int s){
    int res = 0;
    queue<int> Q; Q.emplace(s);
    cost[s] = 1;
    while(!Q.empty()){
        int v = Q.front(); Q.pop();
        res = max(res, cost[v]);
        for(auto u : g[v]){
            if(cost[u] == 0){
                Q.emplace(u);
                cost[u] = cost[v] + 1;
            }
        }
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    cost = vi(n);

    rep(i,n) rep(j,n){
        if(s[i][j] == '1') g[i].push_back(j);
    }
    fill(all(cost), 0);
    if(!dfs(0)){
        cout << -1 << endl;
    }else{
        int ans = 0;
        rep(i,n){
            fill(all(cost), 0);
            ans = max(ans, bfs(i));
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3880
/*

(1,1)ÂÂ©ÂÃ§(i,j)ÂÃÂÃÂÃÂAJ, O, IÂÃÂÂÂÂªÂÂ¢ÂÂ­ÂÃÂÂ ÂÃ©ÂÂ©ÂÃ°ÂÂ ÂÃ§ÂÂ©ÂÂ¶ÂÃDPÂÃÂÂÂÂ¦ÂÃ£ÂÂ°ÂÃÂÂ¨ÂÂ­ÂB
  = sum[1010][1010]

ÂÂ»ÂÂ¤ÂÂ·ÂÃªÂÃÂA(i,j)ÂÂ©ÂÃ§(k,l)ÂÃÂÃÂÃÂÂÂÃ°ÂÂÂÃÂÃ©ÂÃÂÂ«ÂÃÂA
  = sum[k][l] - sum[i-1][l] - sum[k][j-1] + sum[i-1][j-1]
ÂÃÂÃ¦ÂÃ¨ÂÂÂÃÂÃ©ÂÂ±ÂÃÂÂªÂÃÂÂ«ÂÃ©ÂB

ÂvÂZÂÃÂÃÂAÂÃÂÂÂÃÂÂÂÂ¦ÂÃ£ÂÂ°ÂÃÂÂªÂÃ1000*1000ÂiÂTÂ^ÂIÂÃDPÂjÂB
ÂÂ ÂÃÂÃO(1)ÂÃÂÂÂÃÂÃ°ÂÂÂÃÂÃ§ÂÃªÂÃ©ÂÃÂÃÂAÂvÂZÂÃÂÃ°ÂCÂÃÂÂ·ÂÃ©ÂKÂvÂÃÂÂµÂB

 */
#include <iostream>
#include <cstring>
using namespace std;

int h, w, k;
int sumj[1010][1010], sumo[1010][1010], sumi[1010][1010];
char t[1010][1010];

int main(){
  while(cin >> h >> w >> k){
    memset(sumj, 0, sizeof(sumj));
    memset(sumo, 0, sizeof(sumo));
    memset(sumi, 0, sizeof(sumi));

    for(int i = 1; i <= h; i++){
      cin >> &t[i][1];

      for(int j = 1; j <= w; j++){
        sumj[i][j] = sumj[i - 1][j] + sumj[i][j - 1] - sumj[i - 1][j - 1];
        sumo[i][j] = sumo[i - 1][j] + sumo[i][j - 1] - sumo[i - 1][j - 1];
        sumi[i][j] = sumi[i - 1][j] + sumi[i][j - 1] - sumi[i - 1][j - 1];

        if(t[i][j] == 'J')      sumj[i][j]++;
        else if(t[i][j] == 'O') sumo[i][j]++;
        else                    sumi[i][j]++;
      }
    }

    for(int i = 0; i < k; i++){
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      cout << sumj[c][d] - sumj[a - 1][d] - sumj[c][b - 1] + sumj[a - 1][b - 1] << " "
           << sumo[c][d] - sumo[a - 1][d] - sumo[c][b - 1] + sumo[a - 1][b - 1] << " "
           << sumi[c][d] - sumi[a - 1][d] - sumi[c][b - 1] + sumi[a - 1][b - 1] << endl;
    }
  }
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
#define ll long long
#define P pair<string,int>
using namespace std;
  
string d(string e){
    string f;
    for(char g:e){
    if(g!='*')f+=g;
    }
    return f;
    } 
int main(){
    int a,b;
    while(cin>>a>>b,a|b){
    P c[100];
    for(int e=0;e<a;e++){
        string f;int g;
        cin>>f>>g;
        c[e]=P(d(f),g);
        }
        multiset<string>h;
        for(int i=0;i<b;i++){
        string j;
        cin>>j;
        string k;
        for(int l=7;l!=-1;l--){
            k=j[l]+k;
            h.insert(k);
            }
        }
        ll s=0;
        for(P o:c){
        s+=o.second*h.count(o.first);
        }
        cout<<s<<endl;
    }
    }

Measured memory_bytes: 3912
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL)

int main() {
   int n,m;
    cin>>n>>m;
    int l=1,h=n;
    for(int i=0;i<m;i++)
    { int a,b;
       cin>>a>>b;
       if(l<a)l=a;
	   if(h>b)h=b; 
	}
	if(h-l+1<0)
	cout<<0;
	else
	cout<<h-l+1;
}

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

#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  string s;
  cin >> s;
  int n = s.size() + 1;		//文字列の長さ
  
  vector<ll> ans(n,0);
  
  rep(i, n-1){
    if(s.at(i) == '<'){
      ans.at(i+1) = ans.at(i) + 1;
    }
  }
  
  for(int i = n-2; i>=0; i--){
    if(s.at(i) == '>'){
      ans.at(i) = max(ans.at(i), ans.at(i+1) + 1);
    }
  }
  
  
  cout << accumulate(all(ans), 0LL) << endl;
}

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

int main() {
  char a, b; cin >> a >> b;
  bool mode = false;
  if ((a == 'H') && (b == 'H')) {
    mode = true;
  }
  else if ((a=='D') && (b=='D')) {
    mode = true;
  }
  if (mode) {
    cout << "H" << endl;
  }
  else {
    cout << "D" << endl;
  }
}



Measured memory_bytes: 384
N=int(input())
b=list(map(int, input().split()))
a=[]

def f(b):
  i=len(b)-1
  while i>=0 and b[i]!=i+1:
    i-=1
  if i>=0:
    del b[i]
    return i, b
  else:
    return -1, []

j, b_=f(b)
while j>=0:
  a=[j]+a
  j, b_=f(b_)
  
if len(a)==N:
  for i in range(N):
    print(a[i]+1)
else:
  print(-1)

Measured memory_bytes: 3064
//Keep pluggin',this is your only outlet.
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cctype>
#define MM(x,y) memset(x,y,sizeof(x))
#define MCPY(a,b) memcpy(a,b,sizeof(b))
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define fi first
#define mp make_pair
#define se second
using namespace std;
#define int long long

inline int quickpow(int m,int n,int p){int b=1;while(n){if(n&1)b=b*m%p;n=n>>1;m=m*m%p;}return b;}
inline int quickmul(int x,int y,int mod){return (x*y-(int)((long double)x/mod*y)*mod+mod)%mod;}
inline int getinv(int x,int p){return quickpow(x,p-2,p);}
inline int read(void){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){f=ch=='-'?-1:1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x * f;
}

int a[100010],b[100010],cur = 0,n;

///------------------head------------------
signed main(signed argc, char *argv[]){
    n = read();
    rep(i,1,n) a[i]=read(),b[i]=read();
    per(i,n,1) {
        int d = (a[i] + cur) % b[i];
        if (d == 0) continue;
        cur += b[i] - d;
    }
    printf("%lld\n",cur);
    return 0;
}

/* Examples: */
/*

*/

/*

*/


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int chmin(long long *x, long long y) { if (*x > y) { *x = y; return 1; } return 0; }
int chmax(long long *x, long long y) { if (*x < y) { *x = y; return 1; } return 0; }
const long long INF = LONG_MAX >> 5;

int main() {
    const int MAX = 1e5;
    int N;
    int a[MAX + 10][3];
    long long dp[MAX + 10][3];
    scanf("%d", &N);

    for (int i = 0; i < N; i++)
        for (int j = 0; j < 3; j++) 
            scanf("%d", &a[i][j]);

    for (int i = 0; i < MAX + 10; i++)
        for (int j = 0; j < 3; j++)
            dp[i][j] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                chmax(&dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(&res, dp[N][j]);
    printf("%lld\n", res);
    return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    vector<bool> tenbou(N, true);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        if (H[a] == H[b]) {
            tenbou[a] = false;
            tenbou[b] = false;
        } else if (H[a] > H[b]) {
            tenbou[b] =false;
        } else {
            tenbou[a] = false;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (tenbou[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3784
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//using ll=long long;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/*-------------ここまで---------------------------------------------*/

/*signed*/int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if (a > b) {
        ans += a;
        a -= 1;
    }
    else {
        ans += b;
        b -= 1;
    }
    ans += max(a, b);
    cout << ans << endl;
}

Measured memory_bytes: 3608
import qualified Data.ByteString.Char8 as BS
import qualified Data.Maybe as MA
import qualified Data.List as L

main = do
    (n, _) <- MA.fromJust . BS.readInt <$> BS.getLine
    ans <- and . fmap (\n -> n `mod` 3 == 0 || n `mod` 5 == 0) . L.filter (\n -> n `mod` 2 == 0) . fmap (fst . MA.fromJust . BS.readInt) . BS.words <$> BS.getLine
    putStrLn $ if ans then "APPROVED" else "DENIED"


Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int A, B;
    cin >> A >> B;

    cout << MAX(A - 2 * B, 0) << "\n";
    return 0;
}



Measured memory_bytes: 256
def win_rsp(hand):
    if hand == 'r':
        return 'p'
    elif hand == 's':
        return 'r'
    else:  # 'p'
        return 's'


N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

get_score = {'r': R, 's': S, 'p': P}

player_hands = [''] * N
score = 0
# for i in range(N):
#     if player_hands[i] != '':
#         continue
#     if i > K - 1:  # K 回前と同じ手は出せない
#         for j in range(i, N, K):
#             if player_hands[j] != '':
#                 continue
#             if win_rsp(T[j]) == player_hands[j - K]:  # 勝てない
#                 player_hands[j] = 'X'  # 残りふたつのどちらか
#                 player_hands[j + K] = win_rsp[T[j + K]] # j + K 回目で勝つしか無い
#                 # add score
#                 score += get_score[player_hands[j + K]]

#     else:  # ただ勝てばいい
#         player_hands[i] = win_rsp(T[i])
#         # add score
#         score += get_score[player_hands[i]]

t = list(T)
# print(t)
for i in range(K):
    spl = t[i::K]
    win_l = list(map(win_rsp, spl))
    # print(win_l)
    # for i in range(len(win_l)):
    j = 0
    while j < len(win_l):
        if j == len(win_l) - 1:
            score += get_score[win_l[j]]
            # print(get_score[win_l[j]])
            # print('score:', score)
            break
        if win_l[j] != win_l[j + 1]:
            score += get_score[win_l[j]]
            # print(get_score[win_l[j]])
            # print('score:', score)
            j += 1
        else:
            score += get_score[win_l[j]]
            # print(get_score[win_l[j]])
            j += 2

    # print(spl)
    # odd_l = spl[::2]
    # eve_l = spl[1::2]
    # print(odd_l)
    # print(eve_l)

    # win_odd_l = list(map(win_rsp, odd_l))
    # win_eve_l = list(map(win_rsp, eve_l))
    # print('win_odd_l', win_odd_l)
    # print('win_eve_l', win_eve_l)

    # odd_score = 0
    # eve_score = 0
    # for o in win_odd_l:
    #     odd_score += get_score[o]
    # for e in win_eve_l:
    #     eve_score += get_score[e]

    # m = max(odd_score, eve_score)
    # print(m)
    # score += m

print(score)


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

int main() {
  int N;
  cin >> N;
  int a[N];
  int max=0;
  for(int i=0; i<N; i++)
    cin >> a[i];
  
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      if(a[j]>a[i]){
        if(a[j]-a[i]>max)
          max=a[j]-a[i];
      }else{
        if(a[i]-a[j]>max)
          max=a[i]-a[j];
      }
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

using std::cin;
using std::cout;
using std::string;

using ll = int;

struct Item
{
  Item() : is_inv_(false), start_(0), end_(0),csum_(0) {}
  ll start_;
  ll end_;
  bool is_inv_;
  ll csum_;
};

void print(std::vector<Item> lis, int num)
{
  cout << "---" << num << "------------"
       << "\n";
  for (const auto& item : lis)
  {
    cout << item.start_ << ", " << item.end_ << ", " << item.is_inv_ << ", "
         << "\n";
  }
}


int main()
{
  int n, k;
  string s;
  cin >> n >> k;
  cin >> s;
  std::vector<Item> lis;
  int cmax = 0;
  int csum =0;
  for (size_t i = 0; i < n; ++i)
  {
    Item item;
    item.start_ = i;
    item.is_inv_ = s[i] == '1';
    while (i < n)
    {
      if (s[i] != s[i + 1])
      {
        break;
      }
      i++;
    }

    item.end_ = i;
    int length_ = item.end_ - item.start_ + 1;
    cmax = std::max(cmax, length_);
    csum+= length_;
    item.csum_ = csum;
    lis.emplace_back(item);
  }

  // print(lis, 0);
  int result = cmax;
  // int result = get_num(lis, k);
  // int current = result;
  // cout << "[" << 0 << ", " << lis[0].is_inv_ << "].result-> " << result <<
  // "\n";

  for(int i = 1; i < lis.size(); ++i)
  {
    int mnum = i-2*k;
    // if(mnum < 0) {continue;}
    if(!lis[i].is_inv_ && i+1 < lis.size()){i++;}
    int tmp = lis[i].csum_  - (mnum < 0 ? 0 :lis[mnum].csum_);
    // cout <<i << ": " <<  tmp << ", " << lis[i].csum_ << "\n";
    result = std::max(tmp, result);
  }
  // for (int i = 1; i < lis.size(); ++i)
  // {
  //   int tmp = current;
  //   if (lis[i].is_inv_)
  //   {
  //     if (i - 1 >= 0)
  //     {
  //       tmp -= lis[i - 1].length_;
  //       if (i - 2 >= 0)
  //       {
  //         tmp -= lis[i - 2].length_;
  //       }
  //       // cout << "tmp: " << tmp << "\n";
  //     }
  //     
  //     int K = 2 * k - 1;
  //     if (i + K < lis.size())
  //     {
  //       tmp += lis[i + K].length_;
  //       if (i + K + 1 < lis.size())
  //       {
  //         tmp += lis[i + K + 1].length_;
  //       }
  //     }
  //
  //     i++;
  //   }

    // cout << "[" << i << ", " << lis[i].is_inv_ << "].result-> " << tmp <<
    // "\n";
    // result = std::max(result, tmp);
    // current = tmp;
  // }

  cout << result << "\n";

  return 0;
}


Measured memory_bytes: 2548