akhauriyash/Code-Regression huggingface dataset:
//কী পেয়েছো তুমি, কী চেয়েছিলে তুমি.? হিসেবটা তোমার বড়ই গড়মিল...!!//
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3F3F3F3F
typedef long long ll;
vector<ll>v;

int main ()
{
    ll n,m;
    while(scanf("%lld%lld",&n,&m)!=EOF){
        cout<<__gcd(n,m)<<" "<<(n*m)/__gcd(n,m)<<endl;
    }
}
/*
5 6
1 0
0 5
1 2
1 3
2 3
3 4
*/



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

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

    int n;
    cin >> n;
    vector <int> arr(n);
    for(int i = 0; i < n; i++) cin >> arr[i];
    bool good = 1;
    for(int i = 0; i < n; i++){
        if(arr[i]%2 == 0 && (arr[i]%3 != 0 && arr[i]%5 != 0)){
            good = 0;
            break;
        }
    }
    if(good) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

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

const int INF=100;
const char table[]={'g','c','p'};

int N,K;
int R,S,P;
string T;

int point(char x){
    if(x=='r'){
        return P;
    }else if(x=='s'){
        return R;
    }else if(x=='p'){
        return S;
    }
}

int main(){
    cin>>N>>K;
    cin>>R>>S>>P;
    cin>>T;

    int sum=0;
    for(int i=0;i<N;i++){
        if(i>=K){
            if(T[i-K]==T[i]){
                T[i]='x';
            }else{
                sum+=point(T[i]);
            }
        }else{
            sum+=point(T[i]);
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 512
gets
ary = gets.split.map(&:to_i)
flag = 'Yes'
tmp = 0
 
ary.each_with_index do |h, idx|
  next if ary[idx + 1] == nil

  tmp = h - 1 if h > tmp
  flag = 'No' if tmp > ary[idx + 1]
end
 
puts flag

Measured memory_bytes: 11012
import sys
import math
'''a,b= map(int,input().split())'''
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]
a=int(input())
count=0
for i in range(1,1+a):
  if len(str(i))%2==1:
    count+=1
print(count)

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

#define NM_MAX 3002

using namespace std;

string a, b;

int n, m;

int dp[NM_MAX][NM_MAX];
bool path[NM_MAX][NM_MAX];

int main()
{
    cin >> a >> b;
    n = a.size();
    m = b.size();
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            if(a[i - 1] == b[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
            {
                if(dp[i - 1][j] > dp[i][j - 1])
                    path[i][j] = 0;
                else
                    path[i][j] = 1;
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    string ans = "";
    for(int i = n, j = m; i >= 1 && j >= 1; )
    {
        if(a[i - 1] == b[j - 1])
        {
            ans += a[i - 1];
            i--;
            j--;
            continue;
        }
        if(path[i][j] == 0)
            i--;
        else
            j--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 44288
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt();
		int m = sc.nextInt();
 
 
 
 
			HashMap<Integer, HashSet<Edge>>graph = new HashMap<>();
			ArrayList<Edge> edgeList = new ArrayList<>();
			int[]nodeNum = new int[n+1];
			int[]nodeRevNum = new int[n+1];
 
			for (int i=1;i<=n;i++) {
				graph.put(i, new HashSet<Edge>());
			}
 
			for (int j=0;j<m;j++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				Edge edge = new Edge();
				edge.from=a;
				edge.to=b;
				edge.direction=1;
 
				graph.get(a).add(edge);
				graph.get(b).add(edge);
				edgeList.add(edge);
			}
			if (m%2==0) {
			ArrayDeque<Integer> q = new ArrayDeque<>();
			q.add(1);
			int number = 1;
			boolean[] used = new boolean[n+1];
			used[1]=true;
			while(!q.isEmpty()) {
				Integer intg = q.poll();
				nodeNum[intg]=number;
				nodeRevNum[number]=intg;
				number++;
				for (Edge e : graph.get(intg)) {
					int tmp = e.from+e.to-intg;
					if (!used[tmp]) {
						q.offer(tmp);
						used[tmp]=true;
					}
				}
			}
 
			for (int j=n;j>=1;j--) {
				int i = nodeRevNum[j];
				int sum = 0;
				for (Edge e : graph.get(i)) {
					if (e.from==i) {
						sum+=e.direction;
					} else  {
						sum+=(1-e.direction);
					}
				}
 
				if (sum%2!=0) {
					Edge min = null;
					for (Edge e : graph.get(i)) {
						if (min==null) {
							min=e;
						} else if (nodeNum[e.from+e.to-i] < nodeNum[min.from+min.to-i]) {
							min=e;
						}
					}
					min.direction=1-min.direction;
				}
			}
 
			for (Edge e : edgeList) {
				if (e.direction==1) {
					System.out.println(e.from+" "+e.to);
				} else {
					System.out.println(e.to+" "+e.from);
				}
			}
		} else {
			System.out.println(-1);
		}
	}
}
 
 
class Edge  {
	int from;
	int to;
	int direction; //1:from -> to
 
}
 

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

class UnionFind{
    public:
    vector< int > p,rank;
    UnionFind(int sz){
        p.resize(sz,0);
        rank.resize(sz,0);
        REP(i,sz) p[i]=i;
    }

    int find(int x){
        if(p[x]==x) return x;
        return p[x]=find(p[x]);
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(rank[x]>rank[y]) p[y]=x;
        else{
            p[x]=y;
            if(rank[x]==rank[y]) rank[y]++;
        }
    }
};

class Edge{
    public:
    int source,target,cost;
    Edge(int source=0,int target=0,int cost=0):
        source(source),target(target),cost(cost){}
    bool operator<(const Edge& e)const{
        return cost<e.cost;
    }
};

int kruskal(int N,vector< Edge > edges){
    int totalCost=0;
    sort(edges.begin(),edges.end());
    UnionFind tree=UnionFind(N+1);

    int source,target;
    REP(i,edges.size()){
        Edge e=edges[i];
        if(!tree.same(e.source,e.target)){
            totalCost+=e.cost;
            tree.unite(e.source,e.target);
        }
    }
    return totalCost;
}

int main(){
    int N,M,cost;
    int source,target;

    scanf("%d%d",&N,&M);

    vector< Edge > edges;
    REP(i,M){
        scanf("%d%d%d",&source,&target,&cost);
        edges.push_back(Edge(source,target,cost));
    }

    printf("%d\n",kruskal(N,edges));
    return 0;
}




Measured memory_bytes: 5160
N, X = map(int, input().split())
x = list(map(int, input().split()))
x_gcd = []
for i in range(N):
    x_gcd.append(abs(X-x[i]))


def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a


ans = x_gcd[0]
for i in range(N):
    ans = gcd(ans, x_gcd[i])
if ans:
    print(ans)
else:
    print(x[0] - X)

Measured memory_bytes: 14252
import java.io.*;
import java.text.*;
import java.util.*;

public class Main {

    static InputReader sc = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        solver s = new solver();
        int t = 1;
        while (t > 0) {
            s.solve();
            t--;
        }
        out.close();
    }

    static class InputReader {

        public BufferedReader br;
        public StringTokenizer token;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream), 32768);
            token = null;
        }

        public String sn() {
            while (token == null || !token.hasMoreTokens()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return token.nextToken();
        }

        public int ni() {
            return Integer.parseInt(sn());
        }

        public String snl() throws IOException {
            return br.readLine();
        }

        public long nlo() {
            return Long.parseLong(sn());
        }

        public double nd() {
            return Double.parseDouble(sn());
        }

        public int[] na(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.ni();
            return a;
        }

        public long[] nal(int n) {
            long a[] = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.nlo();
            return a;
        }
    }

    static int inf = 5000013;

    static class solver {
        DecimalFormat df = new DecimalFormat("0.00000000");
        int maxi = 200000000;

        void solve() {
            int n = sc.ni();
            long dp[] = new long[n];
            int k = sc.ni();
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = sc.ni();
                dp[i] = Integer.MAX_VALUE;
            }
            dp[0] = 0;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j <= Math.min(i + k, n - 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(a[j] - a[i]));
                }
            }
            out.println(dp[n - 1]);
        }
    }
}


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

using namespace std;

void solve()
{
    int x, n;
    cin >> x >> n;
    vector <int> a(102);
    for (int i = 0, y; i < n; i++)
    {
        cin >> y;
        a[y] = 1;
    }
    int mn = 1e9, ret;
    for (int i = 0; i <= 101; i++)
    {
        if (!a[i] && abs(x - i) < mn) mn = abs(x - i), ret = i;
    }
    cout << ret << endl;
}

int main()
{
    int tt = 1;
    //cin >> tt;
    while (tt--) solve();
}

Measured memory_bytes: 3640
var fs = require('fs'),
    length = fs.fstatSync(process.stdin.fd).size,
    buffer = new Buffer(length),
    bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
    input = buffer.toString('utf8', 0, bytesRead).split('\n');
function solve(n) {

}

function main() {
  while(input[0] !== '0'){
    console.log((input.shift() - 0)
    .toString(8)
    .split('')
    .map(function (ch) {
      if(ch === '4'){
        return +ch + 1;
      }
      if(ch - 0 >= 5) {
        return +ch + 2;
      }
      return +ch ;
    })
    .join(''));
  }
}
main();

Measured memory_bytes: 20024
#include<iostream>

using namespace std;

int main() {
  int n, l, lc = 0, max = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l;
    if (max < l) max = l;
    lc += l;
  }
  if (max < lc - max) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	ll n, m;
	cin >> n >> m;
	
	ll ans;
	if( n >= m / 2LL ) ans = m / 2LL;
	else ans = (n + m / 2LL) / 2LL;
	
	cout << ans << endl;	
	
	return 0;
}


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

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

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n, a, b;
    cin >> n >> a >> b;
    cout << n / (a + b) * a + min(n % (a + b), a);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

ll modinv(ll a, ll m=mod) {
  ll b = m, u = 1, v = 0;
  while(b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if(u < 0) u += m;
  return u;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  ll sum = 0, sum2 = 0;
  rep(i, n) {
    (sum += A[i]) %= mod;
    (sum2 += A[i] * A[i] % mod) %= mod;
  }
  cout << (sum * sum % mod - sum2 + mod) % mod * modinv(2) % mod << endk;
  return 0;
}


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int MOD = 1e9 + 7;
const int N = 51;

int n,k;
int a[N][N];

struct go
{
    int dp[51][51];
    
    go()
    {
        f(i,51) f(j,51) dp[i][j] = 0;
    }
    
    void iden()
    {
        f(i,51) dp[i][i] = 1;
    }
    
    int paths()
    {
        int res = 0;
        
        f(i,51) f(j,51) res+=dp[i][j];
        return res%MOD;
    }
    
};

go merge(go & x,go & y)
{
    go z;
    
    f(i,n) f(j,n) f(v,n) z.dp[i][j] = (z.dp[i][j] + (x.dp[i][v]*y.dp[v][j]))%MOD;
    
    return z;
}

go mod_pow(go x,int y)
{
    go res;
    res.iden();
    
    while(y > 0)
    {
        if(y & 1) res = merge(res,x);
        x = merge(x,x);
        y>>=1;
    }
    
    return res;
}

void solve()
{
    cin >> n >> k;
    
    go x;
    f(i,n) f(j,n) cin >> x.dp[i][j];
    
    cout << mod_pow(x,k).paths();
}

signed main()
{
    fast;
    solve();
}

Measured memory_bytes: 384
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    t1, t2 = list(map(int, readline().split()))
    a1, a2 = list(map(int, readline().split()))
    b1, b2 = list(map(int, readline().split()))
    a1 -= b1
    a2 -= b2
    if a1 * t1 + a2 * t2 == 0:
        print("infinity")
        exit()
    elif a1 < 0:
        if a1 * t1 + a2 * t2 < 0:
            print(0)
            exit()
    elif a1 > 0:
        if a1 * t1 + a2 * t2 > 0:
            print(0)
            exit()
    s = abs(a1 * t1) // abs(a1 * t1 + a2 * t2)
    m = abs(a1 * t1) % abs(a1 * t1 + a2 * t2)
    print(s * 2 if m == 0 else s * 2 + 1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int n;
    int l;
    int taste = 0;

    cin >> n >> l;
    int min =l;
    for (int i = 0; i < n; i++)
    {
        int itaste = l + i;
        if (abs(itaste) < abs(min))
            min = itaste;
        taste += itaste;
    }

    taste= taste - min;
    cout << taste;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <cassert>
#include <set>
#include <map>
#include <bitset>
#include <unordered_set>
#include <string>
#include <cstring>
#include <cmath>

#define forn(x, a)             for (int x = 0; x < a; x++)
#define fore(x, a, b, c)       for (int x = a; x <= b; x += c)
#define forr(x, a)             for (int x = a; x >= 0; x--)
#define all(container)         (container).begin(), (container).end()
#define rall(container)        (container).rbegin(), (container).rend()
#define sz(container)          (int) container.size()
#define mp                     make_pair
#define fi                     first
#define se                     second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector< vector< int > > vvi;
typedef vector<bool> vb;
typedef vector<long long> vll;

#ifdef LOCAL_DEFINE
    #include "../../library/debug.hpp"
#else
    #define debug(...) 0
#endif

void read(int &a) {scanf("%d", &a);}
void read(ll &a) {scanf("%lld", &a);}
void read(char* a, string& s) {scanf("%s", a); s = string(a);}
void read(float &a) {scanf("%f", &a);}
void read(double &a) {scanf("%lf", &a);}
void print(vi &a) {for (auto& x: a) printf("%d ", x); puts("");}
void print(int &a) {printf("%d ", a);}
void println(int &a) {printf("%d\n", a);}
void print(ll &a) {printf("%lld ", a);}
void println(ll &a) {printf("%lld\n", a);}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

void solve() {
    int n;
    ll x;
    read(n);
    read(x);
    vll arr(n);
    forn(i, n) read(arr[i]);
    ll ans = 0, left, right;
    forn(i, n - 1) {
        ll tmp = arr[i] + arr[i + 1];
        if (tmp > x) {
            right = min(arr[i + 1], tmp - x);
            ans += right;
            arr[i + 1] -= right;
            tmp -= right;
            if (tmp > x) {
                left = min(tmp - x, arr[i]);
                arr[i] -= left;
                ans += left;
            }
        }
    }
    print(ans);
}

int main(void) {
    int T = 1;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 1024
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    N, M = iim()
    it = map(int, sys.stdin.read().split())

    dp = [-1] * N

    def find(x):
        if dp[x] < 0:
            return  x

        ans = dp[x] = find(dp[x])
        return ans

    def union(x, y):
        x1 = find(x)
        y1 = find(y)

        if x1 == y1:
            return

        xr = dp[x1]
        yr = dp[y1]
        if xr <= yr:
            dp[y1] = x1
            dp[x1] += yr
        else:
            dp[x1] = y1
            dp[y1] += xr

    for ai, bi in zip(it, it):
        union(ai-1, bi-1)

    cnt = 0
    for rank in dp:
        if rank >= 0: continue
        cnt += 1
    print(cnt-1)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 86608
#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 i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; 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) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
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) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(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> 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; }

void solve() {
  int N, P;
  cin >> N >> P;
  string s;
  cin >> s;
  if (P == 2) {
    i64 ans = 0;
    rep(i, N) if ((s[i] - '0') % 2 == 0) {
      ans += i + 1;
    }
    cout << ans << endl;
    return;
  }
  if (P == 5) {
    i64 ans = 0;
    rep(i, N) if ((s[i] - '0') % 5 == 0) {
      ans += i + 1;
    }
    cout << ans << endl;
    return;
  }
  vi32 mod(N + 1);
  int acc = 0;
  rep(i, N) {
    acc = (acc * 10 + (s[i] - '0')) % P;
    mod[i + 1] = acc;
  }
  int x = 1;
  rreps(i, N) {
    mod[i] *= x, mod[i] %= P;
    x *= 10, x %= P;
  }
  vi32 cnt(P);
  rep(i, N + 1) cnt[mod[i]]++;
  i64 ans = 0;
  rep(i, P) {
    i64 x = cnt[i];
    ans += x * (x - 1) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1428
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n, m;
    cin >> n >> m;

    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> s(n+1);
    s[0] = 0;
    rep(i, n){
        s[i+1] = (s[i] + a[i]) % m;
    }

    map<int, int> mp;
    rep(i, n){
        if(mp.find(s[i+1]) == mp.end()){
            mp.emplace(s[i+1], 0);
        }
        mp[s[i+1]]++;
    }

    int ans = 0;
    for(P p : mp){
        if(p.first == 0){
            ans += p.second;
        }
        ans += (p.second - 1) * p.second / 2;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5760
// abc143_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

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

    int x = A - 2 * B;
    if (x < 0){
        print(0);
    } else{
        print(x);
    }


    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Text;

namespace ITP1_5_B_Print_a_Frame
{
    class Program
    {
        static string buildFrame(int h, int w)
        {
            var edge = new String( '#', w );
            var inner = string.Format( "#{0}#", new String( '.', w - 2 ) );
            return Enumerable.Range( 1, h )
                .Select( i => i == 1 || i == h ? edge : inner )
                .Aggregate( new StringBuilder(), (acc, s) => acc.AppendLine( s ) )
                .ToString();
        }
        static void Main(string[] args)
        {
            string[] input = null;
            do
            {
                if ( input != null )
                {
                    var size = input.Select( int.Parse ).ToArray();
                    Console.WriteLine( buildFrame( size[ 0 ], size[ 1 ] ) );
                }
                input = Console.ReadLine().Split( ' ' );
            } while ( input[ 0 ] != "0" || input[ 1 ] != "0" );
        }
    }
}

Measured memory_bytes: 5848
// AOJ DPL_1_A Coin Changing Problem
//
#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++)
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}

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

    int n, m;
    cin >> n >> m;

    vector<int> c(m);
    rep(i, n) cin >> c[i];

    vector<int> dp(n+1, INT_MAX);    
    dp[0] = 0;

    rep1(i, n+1) {
        rep(j, m) {
            if (i >= c[j]) {
                chmin(dp[i], dp[i-c[j]]+1);
            }
        }
    }

    cout << dp.back() << endl;

    // rep(i, dp.size()) {
    //     cout << dp[i] << " ";
    // }
    // cout << endl;
}



Measured memory_bytes: 3244
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 3000000007;
const double INFD = 1e100;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------


ll dp[101][5][5][5];
int main(){
  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    for(int j=0; j<5; j++){
      for(int k=0; k<5; k++){
        for(int l=0; l<5; l++){
          dp[i][j][k][l] = 0;
        }
      }
    }
  }
  dp[0][0][0][0] = 1;
  for(int n=0; n<N; n++){
    for(int i=0; i<5; i++){
      for(int j=0; j<5; j++){
        for(int k=0; k<5; k++){
          for(int l=1; l<5; l++){
            if(j==1 && k==2 && l==3) continue;
            if(j==2 && k==1 && l==3) continue;
            if(j==1 && k==3 && l==2) continue;
            if(i==1 && k==2 && l==3) continue;
            if(i==1 && j==2 && l==3) continue;
            dp[n+1][j][k][l] += dp[n][i][j][k]%mod;
            dp[n][j][k][l] %= mod;
          }
        }
      }
    }
  }
  ll ans=0;
  for(int i=1; i<5; i++){
    for(int j=1; j<5; j++){
      for(int k=1; k<5; k++){
        ans += dp[N][i][j][k]%mod;
        ans %= mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import sys

ns = sys.stdin.readline().strip()
ns = ns[::-1]
ns += '0'
ns_arr = list(ns)
n_arr = [int(s) for s in ns_arr]
nl = len(n_arr)

dp = [[float('inf')] * (nl+1) for _ in range(2)]

dp[0][0] = 0

for j in range(nl):
    for i in range(2):
        num = n_arr[j]
        num += i

        if num < 10:
            dp[0][j+1] = min(dp[0][j+1], dp[i][j] + num)

        if num > 0:
            dp[1][j+1] = min(dp[1][j+1], dp[i][j] + (10 - num))

ans = dp[0][nl]
print(ans)




Measured memory_bytes: 160236
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	cin >> s;
	cin >> k;
	ll cnt = 0;
	char lp = '0';
	bool flg = true;
	rep(i, s.size()) {
		if (i == 0) {
			lp = s[i];
			continue;
		}
		if (i != 0 && s[i] != lp) {
			flg = false;
			break;
		}
	}
	if (s.size() == 1) {
		if (k % 2 == 0) {
			cout << k / 2 << endl;
		}
		else {
			cout << (k - 1) / 2 << endl;
		}
		return 0;
	}
	if(flg){
		if ((s.size() * k) % 2 == 0) {
			cout << (s.size() * k) / 2 << endl;
		}
		else {
			cout << (s.size()* k - 1) / 2 << endl;
		}
		return 0;
	}
	if (k == 1) {
		rep(i, s.size() - 1) {
			if (s[i] == s[i + 1]) {
				s[i + 1] = 'B';
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	else {
		string t = s + s;
		ll pm = 0;
		rep(i, t.size() - 1) {
			if (t[i] == t[i + 1]) {
				t[i + 1] = '`';
				if (i + 1 <= s.size() - 1) {
					cnt++;
				}
				else {
					pm++;
				}
			}
		}
		cout << cnt + pm * (k - 1) << endl;
	}
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int cA,cB,n,i,j,A=0,B=0;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d%d",&cA,&cB);
			if(cA>cB)A+=cA+cB;
			else if(cB>cA)B+=cA+cB;
			else{
				A=A+cA;
				B=B+cB;
			}
		}
		printf("%d %d\n",A,B);
		A=B=0;
	}
	return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  for (int i=0; i<N; i++){
    int left, right;
    cin >> left >> right;
    
    sum += (right - left) + 1;
  }
  cout << sum << endl;
}
    

Measured memory_bytes: 256
N = int(input())
A,B,*C = list(map(int,input().split()))
X = 0
for c in C:
    X ^= c
S = A+B

K = 43
dp = [[[-1]*2 for _ in range(2)] for _ in range(K)]
dp[0][0][0] = 0

for i in range(K-1):
    cx = (X>>i)&1
    cs = (S>>i)&1
    ca = (A>>i)&1
    for j in range(2):
        for k in range(2):
            if dp[i][j][k] == -1: continue
            for na in range(2):
                for nb in range(2):
                    if (na^nb) != cx: continue
                    ns = na+nb+j
                    if ns%2 != cs: continue
                    nj = ns//2
                    if ca < na:
                        nk = 1
                    elif ca == na:
                        nk = k
                    else:
                        nk = 0
                    dp[i+1][nj][nk] = max(dp[i+1][nj][nk], dp[i][j][k] + 2**i * na)
a = dp[-1][0][0]
if a==0 or a==-1:
    print(-1)
else:
    print(A - a)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N;
  cin >> N;
  vi A(N), B(N);
  cin >> A >> B;

  i64 diff = accumulate(rng(B),0LL) - accumulate(rng(A),0LL);

  i64 a = 0, b = 0;

  rep(i,N){
    if(A[i]>B[i]){
      b += A[i] - B[i];
    } else if (A[i]<B[i]) {
      a += (B[i]-A[i]+1)/2;
      b += (B[i]-A[i])%2;
    }
  }

  if(diff<a or diff<b){
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }




}

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

Measured memory_bytes: 384
#include <stdio.h>
#include <ctype.h>
     
int par[100000];
     
void init(int);
int dep(int);
int inp();
    
char *p;
char in[1500000];
int tree[100000][15],idx[100000];
    
int main(void){
  int n,i,j,id,k,c;
    
  fread(in,sizeof(in),1,stdin);  
  p = in;
    
  n = inp(); init(n);
  for(i = 0 ; i < n ; i++){
    id = inp();
    k = inp();
    for(j = 0 ; j < k ; j++){
      c = inp();
      par[c] = id;
      tree[id][idx[id]++] = c;
    }
  }
     
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, depth = %d, "
           ,i,par[i],dep(i));
        
    if(par[i] == -1){
      printf("root, [");
    }else if(!idx[i]){
      printf("leaf, [");
    }else{
      printf("internal node, [");
    }
    
    for(j = 0 ; j < idx[i] ; j++){
      printf("%d",tree[i][j]);
      if(j < idx[i]-1) printf(", ");
    }
    puts("]");
  }
  return 0;
}
    
void init(int n){
  int i;
  for(i = 0 ; i < n ; i++){
    par[i] = -1;
  }
}
    
int dep(int x){
  if(par[x] == -1) return 0;
  return dep(par[x]) + 1;
}
    
int inp(){
  int v = 0;
  while(!isdigit(*p)) ++p;
  v = *p++&15;
  while(isdigit(*p)){
    v = (v<<3)+(v<<1)+(*p++&15);
  }
  return v;
}


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

int main(){
    ll q;
    cin>>q;
    vector<ll> l(q),r(q);
    rep(i,q)cin>>l[i]>>r[i];
    vector<bool> is_prime(1e5 + 1, true);
    for (int p = 2; p <= 1e5; p++) {
        if (!is_prime[p]) continue;
        // p の倍数を全て消す。
        for (int k = p * 2; k <= 1e5; k += p) is_prime[k] = false;
    }
    is_prime[1]=false;
    vector<ll> ok;
    rep(i,1e5+1){
        if(i%2==0)continue;
        if(is_prime[i]&&is_prime[(i+1)/2]){
            ok.push_back(i);
        }
    }
    rep(i,q){
        cout<<upper_bound(ok.begin(), ok.end(), r[i])-lower_bound(ok.begin(), ok.end(), l[i])<<endl;
    }
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int x[99][2],y[99][20],n,a,b,c,d,e,f,g,h,p,i,j,k;
int main() {
while(true) {
memset(x,0,sizeof(x));memset(y,0,sizeof(y));
cin>>n>>a>>b>>c;
if(n==0){break;}
for(i=0;i<c;i++){
cin>>d>>e>>f>>g;
if(g!=0){y[e][f]+=20;}
else{x[e][1]+=d+y[e][f];x[e][0]++;}
}p=0;
for(i=b;i>=0;i--){
for(j=0;j<=99999;j++){h=0;
for(k=a;k>0;k--){
if(x[k][0]==i&&x[k][1]==j){
if(h>=1){cout<<'=';}else if(p>=1){cout<<',';}cout<<k;p++;h++;
}
}}}
cout<<endl;}}

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

vector<ll> num;

void dfs(string n, int a, int digit){
    num.push_back(stoll(n));
    if(digit > 10) return;
    for(int i = -1; i <= 1; i++){
        if(a == 9 && i == 1) continue;
        else if(a == 0 && i == -1) continue;
        int b = a + i;
        char cb = b + '0';
        dfs(n+cb, b, digit+1);
    }
}

int main(){
    ll k; cin >> k;

    roop(i, 1, 10) {
        string n = "";
        n += i + '0';
        dfs(n, i, 1);
    }
    sort(num.begin(), num.end());
    // for(ll tmp : num) cout << tmp << endl;

    cout << num[k-1] << endl;

    return 0;
}

Measured memory_bytes: 10604
from collections import defaultdict
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(m)]
dc = defaultdict(int)
if (n,m) == (1,0):
  print(0)
  exit()
for i,j in a:
  if dc[i] and dc[i] != j+1:
    print(-1)
    exit()
  dc[i] = j+1
if dc[1] == 1:
  if n != 1:
    print(-1)
  else:
    print(0)
  exit()
ans = 0
for i,x in dc.items():
  if x != 0:
    ans += (x-1)*10**(n-i)
if ans < 10**(n-1):
  ans += 10**(n-1)
print(ans)

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

ll a[50], p[50];

ll f(int N, ll X) {
  if (N == 0) return 1;
  else if (X == 1) return 0;
  else if (X <= 1 + a[N-1]) return f(N-1, X-1);
  else if (X == 1 + a[N-1] + 1) return p[N-1] + 1;
  else if (X <= 1 + a[N-1] + 1 + a[N-1]) return p[N-1] + 1 + f(N-1, X - 1 - a[N-1] - 1);
  else return p[N-1] + 1 + p[N-1];
}

int main() {
  int N; cin >> N;
  ll X; cin >> X;
  a[0] = 1, p[0] = 1;
  for(int i = 1; i < N; ++i) {
    a[i] = a[i-1] * 2 + 3;
    p[i] = p[i-1] * 2 + 1;
  }
  cout << f(N, X) << endl;
  return 0;
}

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

int main()
{
    ll n,i,ans=0,f=0;
    cin>>n;
    ll a[n+2];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if((a[i]%2)==1)
        {
            f=1;
        }
    }
    if(f==1)
    {
        cout<<0<<endl;
    }
    else
    {
        f=0;
        while(f==0)
        {
            ans++;
            for(i=0;i<n;i++)
            {
                a[i]/=2;
                if((a[i]%2)==1)
                {
                    f=1;
                    break;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF (1e9)

struct P {
    int v, cost, visited;

    bool operator >(const P& p) const {
        return cost > p.cost;
    }
};

int main() {
    int n;
    while (cin >> n, n) {
        vvi stage(n, vi(n+1));
        REP(i, n) REP(j, n+1) cin >> stage[i][j];

        priority_queue<P, vector<P>, greater<P>> que;
        REP(i, n) que.push({i, stage[i][0], 1<<i});

        vvi G(1<<16, vi(16, INF));

        while (!que.empty()) {
            P p = que.top(); que.pop();

            if (p.visited == (1<<n)-1) {
                cout << p.cost << endl;
                break;
            }

            REP(i, n) {
                if (p.visited & (1<<i)) continue;

                int visited = p.visited | (1<<i);

                REP(j, n+1) {
                    if (j != 0 && !(p.visited & (1<<(j-1)))) continue;
                    int cost = p.cost + stage[i][j];
                    if (G[visited][0] > cost) {
                        G[visited][0] = cost;
                        que.push({i, cost, visited});
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 13148
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[][] delta = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] g = new char[h][w];
		for (int i = 0; i < h; i++) {
			g[i] = sc.next().toCharArray();
		}

		int answer = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (g[i][j] != '.') continue;
				boolean[][] visited = new boolean[h][w];
				int[][] d = new int[h][w];
				for (int l = 0; l < h; l++) {
					Arrays.fill(d[l], 10000);
				}

				Queue<int[]> q = new LinkedList<>();
				q.offer(new int[]{i, j, 0});
				//d[i][j] = 0;
				visited[i][j] = true;
				while (!q.isEmpty()) {
					int[] p = q.poll();
					visited[p[0]][p[1]] = true;
					for (int k = 0; k < 4; k++) {
						int ny = delta[k][0] + p[0];
						int nx = delta[k][1] + p[1];
						if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
						if (g[ny][nx] != '.' || d[ny][nx] != 10000) continue;
						if (g[ny][nx] != '.' || visited[ny][nx]) continue;
						d[ny][nx] = p[2] + 1;
						visited[ny][nx] = true;
						q.offer(new int[]{ny, nx, p[2] + 1});
					}

					//if (q.isEmpty()) answer = Math.max(answer, p[2]);
				}

				for (int k = 0; k < h; k++) {
					for (int l = 0; l < w; l++) {
						if (d[k][l] < 10000) answer = Math.max(answer, d[k][l]);
					}
				}
			}
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 34172
#include <stdio.h>
 
int main(void){
    long int A,B,K=0,ans,h=0;
    scanf("%ld%ld",&A,&B);
    while(A+B-2*K>=0){
        if((A+B-2*K)==0){
            ans=K;
            h=1;
            break;
           }else{
            K++;
        }
    }
    if(h==1){
        printf("%ld\n",ans);
    }else{
        printf("IMPOSSIBLE");
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
typedef long long ll;

using namespace std;

inline int input(){
    int a;
    cin >> a;
    return a;
}

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

// end of template

// union find
class union_find {
public:
    vector<int> parent, rnk;
    
    union_find(int n){
        parent.resize(n);
        rnk.resize(n, 0);
        rep(i, n){
            parent[i] = i;
        }
    }
    
    int root(int x){
        if (parent[x] == x) {
            return x;
        }
        else{
            return root(parent[x]);
        }
    }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (rnk[x] < rnk[y]) {
            parent[x] = y;
        }
        else{
            parent[y] = x;
            if (rnk[x] == rnk[y]) {
                rnk[x]++;
            }
        }
    }
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
};

struct edge{
    int f, t, cost;
    // define e1.cost < e2.cost : e1 < e2
    bool operator < (const edge &e) const{
        return cost < e.cost;
    }
};

class kruskal{
public:
    int v; // vertices
    vector<edge> e; // edges
    
    kruskal(int vt, int eg){
        v = vt;
        e.resize(eg);
    }
    
    int mst(){
        sort(e.begin(), e.end());
        union_find uf(v);
        int min_cost = 0;
        rep(i, e.size()){
            edge &d = e[i];
            if (!uf.same(d.f, d.t)) {
                min_cost += d.cost;
                uf.unite(d.f, d.t);
            }
        }
        
        return min_cost;
    }
};


int main() {
    cin.tie(0);
    // source code
    int V, E;
    cin >> V >> E;
    kruskal ks(V, E);
    rep(i, E){
        int s, t, c;
        cin >> s >> t >> c;
        ks.e[i] = edge{s, t, c};
    }
    
    cout << ks.mst() << endl;
    
    
    return 0;
}

Measured memory_bytes: 4080
if __name__ == "__main__":
    h, w = list(map(int, input().split()))
    cost = {}
    for i in range(10):
        for j, c in enumerate(map(int, input().split())):
            cost[(i, j)] = c

    for k in range(10):
        for i in range(10):
            for j in range(10):
                cost[(i, j)] = min(cost[(i, j)],  cost[(i, k)] + cost[(k, j)])
    
    cost[(-1, 1)] = 0
    
    print(sum([sum(map(lambda x: cost[(x, 1)], map(int, input().split()))) for i in range(h)]))
    



Measured memory_bytes: 3188
n,m = map(int, input().split())
wrong = [0] * n
wrongAns = [0] * n
goodAns = [0] * n
badAnsF = 0
greatAnsF = 0
#print(wrong)
for i in range(m):
  p,s = input().split()
  if(s == "WA"):
    wrong[int(p)-1] += 1
  elif(s == "AC"):
    if(goodAns[int(p)-1] == 0):
      wrongAns[int(p)-1] = wrong[int(p)-1]
      goodAns[int(p)-1] = 1
    
for i in wrongAns:
  badAnsF += i
for i in goodAns:
  greatAnsF += i

print(greatAnsF,badAnsF)

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;
signed main() {
    ll A,B,Q;
    cin>>A>>B>>Q;
    vector<ll> s(A),t(B);
    rep(i,0,A) cin>>s[i];
    rep(i,0,B) cin>>t[i];
    s.push_back(-10e12);
    s.push_back(10e12);
    t.push_back(-10e12);
    t.push_back(10e12);
    sort(begin(s), end(s));
    sort(begin(t), end(t));
    while(Q--){
        ll x, ans=10e12;
        cin>>x;
        auto it = lower_bound(begin(s), end(s), x);
        auto jt = lower_bound(begin(t), end(t), x);

        // どちらも東側
        ans = min(ans, max(*it, *jt) - x);

        // itのみ西側
        if (*it != x) it--;
        ll l1 = x - *it, l2 = *jt - x;
        ans = min(ans, min(l1,l2) + l1 + l2);

        // jtのみ西側
        if (*jt != x) jt--;
        if (*it != x) it++;
        l1 = x - *jt; l2 = *it - x;
        ans = min(ans, min(l1,l2) + l1 + l2);

        // どちらも西側
        if (*it != x) it--;
        ans = min(ans, x - min(*it, *jt));

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


Measured memory_bytes: 2912
#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>
using namespace std;

int main()
{
    long long x;
    cin>>x;
    bitset<32> b(x),c,d;
    c=d=b;
    cout<<b<<"\n";;
    cout<<(~b)<<"\n";
    cout<<(c<<1)<<"\n";
    cout<<(d>>1)<<"\n";

}





Measured memory_bytes: 3144
#include <iostream>

using namespace std;

int main(){
    int track[10], c, num;
    while(1){
        cin >> num;
        if(!num){
            if(!c) break;
            else cout << track[c--] <<endl;
        }
        else{
            if(c==10) cout << "Already Full" <<endl;
            else track[++c] = num;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long ll;
typedef pair<ll,ll> pll;
#define F first
#define S second
const int N = 106;
const double pi = acos(-1);
double rad(double x,double y)
{
    double d = atan2(y,x);
    while (d < 0)
        d += 2 * pi;
    while (d >= 2 * pi)
        d -= 2 * pi;
    return d;
}
ll x[N], y[N];
bool ok[N];
double ans[N];
pair<ll,ll> vec(int i,int j)
{
    return {x[j]-x[i],y[j]-y[i]};
}
ll crx(pll a,pll b)
{
    return a.F * b.S - a.S * b.F;
}
int main()
{
    int n;
    cin >> n;
    vector<int> w,v;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        w.push_back(i);
    }
    sort(begin(w),end(w),[&](int i,int j)->bool{return x[i] < x[j] || (x[i] == x[j] && y[i] < y[j]);});
    v.push_back(w[0]);
    for (int i = 1; i < n; ++i) {
        int t = w[i];
        while (SZ(v) >= 2 && crx(vec(v[SZ(v)-2],v[SZ(v)-1]), vec(v[SZ(v)-2], t)) <= 0)
            v.pop_back();
        v.push_back(t);
    }
    int bn = SZ(v);
    for (int i = n - 2; i >= 0; --i) {
        int t = w[i];
        while (SZ(v) >= bn + 1 && crx(vec(v[SZ(v)-2],v[SZ(v)-1]), vec(v[SZ(v)-2], t)) <= 0)
            v.pop_back();
        v.push_back(t);
    }
    v.pop_back();
    for (int i : v) ok[i] = 1;
    int m = SZ(v);
    if (m == 2) {
        for (int i = 0; i < n; ++i)
            cout << (i == v[0] || i == v[1] ? 0.5 : 0) << endl;
        return 0;
    }
    for (int t = 0; t < m; ++t) {
        int i = v[t], up = v[(t-1+m)%m], dn = v[(t+1)%m];
        ll c = x[up] - x[i], d = y[up] - y[i],
        e = x[dn] - x[i], f = y[dn] - y[i];
        ans[i] = (rad(-f,e) - rad(d,-c)) / (2 * pi);
        if (ans[i] < 0)
            ans[i] += 1;
    }
    for (int i = 0; i < n; ++i)
        printf("%.15f\n", ans[i]);
}


Measured memory_bytes: 256