akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int n = sc.nextInt();
            int L = sc.nextInt();
            if (n == 0 && L == 0) break;
            
            int newNum;
            int count = 0;
            
            HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
            hm.put(n, 0);
            
            while (true) {
                count++;
                newNum = getNewNum(n, L);
                if (hm.containsKey(newNum)) {
                    break;
                }
                hm.put(newNum, count);
                n = newNum;
            }
            
            System.out.println(hm.get(newNum) + " " + newNum + " " + (count - hm.get(newNum)));
        }
    }
    
    public static String padZero(int n, int L) {
        String str = n + "";
        while (str.length() < L) {
            str += "0";
        }
        return str;
    }
    
    public static int getNewNum(int n, int L) {
        String str = padZero(n, L);
        char[] charArray = str.toCharArray();
        Arrays.sort(charArray);
        
        String small = new String(charArray);
        String big = new StringBuilder(small).reverse().toString();
        
        return Integer.parseInt(big, 10) - Integer.parseInt(small, 10);
    }
    
}




Measured memory_bytes: 27844
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N, K = MAP()
p = LIST()
p.sort()

print(sum(p[:K]))

Measured memory_bytes: 10060
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 200007
using namespace std;
int main() {
  fastio;
  ll n = 0;
  cin >> n;
  vector<ll>ar(n), dp(n, INF);
  for (ll i = 0; i < n; ++i)
    cin >> ar[i];
  dp[0] = 0;
  dp[1] = abs(ar[1] - ar[0]);
  for (ll i = 2; i < n; ++i)
    dp[i] = min(dp[i - 2] + abs(ar[i] - ar[i - 2]), dp[i - 1] + abs(ar[i] - ar[i - 1]));
  cout << dp[n - 1];
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


ll dp[4][4][4], np[4][4][4];

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	memset(dp, 0, sizeof dp);
	dp[3][3][3] =1; 
	// AGC, GAC, ACG, AxGC, AGxC
	
	rep(i, n){
		memset(np, 0, sizeof np);
		rep(x, 4) rep(y, 4) rep(z, 4) rep(d, 4){
			if(y==0 && z==1 && d==2) continue;
			if(y==1 && z==0 && d==2) continue;
			if(y==0 && z==2 && d==1) continue;
			if(x==0 && z==1 && d==2) continue;
			if(x==0 && y==1 && d==2) continue;
			(np[y][z][d] += dp[x][y][z])%=MD;
		}
		swap(dp, np);
	}
	ll ans =0;
	rep(x, 4) rep(y, 4) rep(z, 4) (ans += dp[x][y][z]) %=MD;
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	

	void solve(){
		


		ini(n);
		
		ini(n1);
		int tmp = 0;
		FOR(i,0,n){
			ini(x,x1);
			if(x*x+x1*x1<=n1*n1)tmp++;
		}
		out(tmp);

			
			
			


				
		


		
		
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 3644
arr_1 = input().split(" ")

n=int(arr_1[0])
k=int(arr_1[1])

okashimochi=list()

for num in range(0,k):
    input()
    child = list(input().split(" "))
    okashimochi.extend(child)

result = list(set(okashimochi))
print(n-len(result))

Measured memory_bytes: 9348
#include <iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
int main(void){
    // Your code here!
   string vec;
    cin>>vec;
   
   int ans=0;
   for(int i=0;i<(1<<3);i++){
       ans=vec[0]-'0';
       string out;
       out+=vec[0];
       for(int j=0;j<3;j++){
           if(1<<j & i){
             ans+=vec[j+1]-'0';
             out+='+';
             out+=vec[j+1];
           }else{
               ans-=vec[j+1]-'0';
               out+='-';
               out+=vec[j+1];
           }
       }
       if(ans==7)
       {
           out+="=7";
        cout<<out;  
        break;
       }
   }
}


Measured memory_bytes: 3040
#include<iostream>

int main(){
  int n, original, reverse = 0;
  std::cin >> n;
  original = n;

  while(n > 0){
    reverse = reverse * 10 + n % 10;
    n /= 10;
  }
  if(original == reverse) std::cout << "Yes";
  else std::cout << "No";

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    string s; cin >> s;
    vector<vector<long long>> dp(100005, vector<long long>(13));
    dp[0][0] = 1;
    int len = (int)s.length();
    for (int i = 1; i <= len; i++) {
        if (s[i-1] == '?') {
            for (int k = 0; k <= 9; k++) {
                for (int j = 0; j < 13; j++) {
                    int tmp = j*10 + k;
                    tmp %= 13;
                    dp[i][tmp] += dp[i-1][j];
                    dp[i][tmp] %= MOD;
                }
            }
        } else {
            for (int j = 0; j < 13; j++) {
                int num = s[i-1] - '0';
                int tmp = j*10 + num;
                tmp %= 13;
                dp[i][tmp] += dp[i-1][j];
                dp[i][tmp] %= MOD;
            }
        }
    }
    cout << dp[len][5] << endl;
}

Measured memory_bytes: 13696
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9 + 5;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
using namespace std;

int n,m,u,v;
int memo[110000];
bool fl[110000];
vector<int> eg[110000];


int dp(int v){
    if(fl[v]){
        return memo[v];
    }
    int ans = 0;
    for(int to: eg[v]){
        ans = max(ans, dp(to) + 1);
    }
    fl[v] = true;
    memo[v] = ans;
    return ans;
}
using namespace std;
int main(){
   

    int n;
    cin >>n;
    ll ans = 0;
    int c = n-1;
    for(int i = 1;i<=c;i++){
        ans += c/i;
    }
    cout << ans <<endl;
}





Measured memory_bytes: 6200
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,count,a[];
		while(true){
			n=sc.nextInt();
			if(n==0) break;
			count=0;
			a=new int[n];
			for(int i=0;i<n;i++){
				a[i]=sc.nextInt();
			}
			for(int i=n;0<i;i--){
				for(int j=0;j+1<i;j++){
					if(a[j+1]<a[j]){
						int temp=a[j];
						a[j]=a[j+1];
						a[j+1]=temp;
						count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

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

using namespace std;

int main(){
    int a, b;
    int h, m;
    double h_ang, m_ang;
    double ang;
    double ans;

    cin >> a >> b >> h >> m;
    m_ang = m * 6;
    h_ang = h * 30 + m * 0.5;
    ang = abs(m_ang - h_ang);

    if (ang == 0){
        cout << abs(a-b) << endl;
    } else if (ang == 180) {
        cout << a + b << endl;
    } else {
        ans = a * a + b * b - 2.0 * b * a * cos(ang*M_PI/180.0);
        cout << setprecision(21) << sqrt(ans) << endl;
    }

    return 0;
}



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

const int N = 3e3 + 5, inf = INT_MAX, mod = 1e9 + 7;

int n, dp[22][(1 << 22)], a[22][22];

int solve(int i, int mask)
{
    if (i == n)
        return 1;
    if (dp[i][mask] != -1)
        return dp[i][mask];
    int ans = 0;
    for (int j = 0; j < n; j++)
    {
        if (a[i][j] == 1 && ((1 << j) & mask) == 0)
            ans = (ans + solve(i + 1, ((1 << j) | mask))) % mod;
    }
    return dp[i][mask] = ans;
}

int main()
{
    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
    memset(dp, -1, sizeof dp);
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
    cout << solve(0, 0);
    return 0;
}

Measured memory_bytes: 364080
#include<bits/stdc++.h>
using namespace std;
const int SIZE=200005;
int i,n,m,a,b;
int A[SIZE],B[SIZE],c[SIZE];
int main(){
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>A[i]>>B[i];
	}
	for(i=0;i<m;i++){
		if(A[i]==1) c[B[i]]=1;
	}
	bool ans=false;
	for(i=0;i<m;i++){
		if(B[i]==n&&c[A[i]]==1) ans=true;
		if(ans) break;
	}	
	if(!ans) cout<<"IMPOSSIBLE";
	else cout<<"POSSIBLE";
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    ll ans = 1;
    REP(i,N){
        ll t; cin >> t;
        ans = (t/__gcd(ans,t))*ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define mp(i) get<1>(cost_mp_atk.at(i))
#define atk(i) get<2>(cost_mp_atk.at(i))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
    int hp, n;
    cin >> hp >> n;
    vector<tuple<double, int, int>> cost_mp_atk(n);
    int max_atk = 0;
    rep(i, n) {
        int atk, mp;
        cin >> atk >> mp;
        cost_mp_atk.at(i) = make_tuple((double)mp / atk, mp, atk);
        if (atk > max_atk) max_atk = atk;
    }
    //atkあたりのmp消費昇順、続いてmp順にソート
    sort(cost_mp_atk.begin(), cost_mp_atk.end());
    
    //与えるダメージに対する消費魔力の最小値DP
    vector<int> a(hp + max_atk, 0);
    rep(i, n) {
        rep(j, hp) {
            //j = 0の時は考えなければいけない。その他のjに対しては要素がある時に処理
            if (j == 0 || a.at(j) != 0) {
                if (a.at(j + atk(i)) == 0) {
                    //要素が0ならば上書き
                    a.at(j + atk(i)) = a.at(j) + mp(i);
                }
                else {
                    //そうでないなら小さいほうを代入
                    a.at(j + atk(i)) = min(a.at(j + atk(i)), a.at(j) + mp(i));
                }
            }
        }
    }

    rep (i, hp) a.at(i) = 0;
    sort(a.begin(), a.end());

    int k = 0;
    while (a.at(k) == 0) k++;
    cout << a.at(k) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
vector<int> v(100000000, 0);
int cnt = 0;
void f(int n)
{
    if(v[n] > 0) return;
    v[n]++;
    cnt++;
    if(n % 2 == 0) f(n / 2);
    else f(3 * n + 1); 
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s; cin >> s;
    f(s);
    cout << cnt + 1<< endl;
    return 0;
}



Measured memory_bytes: 390912
from heapq import heapify, heappop, heappush

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

r = [-x for x in r]

p.sort()
q.sort()
r.sort()

p = p[-x:]
q = q[-y:]

heapify(p)
heapify(q)
heapify(r)

while r:
    pp = heappop(p)
    qq = heappop(q)
    rr = heappop(r)
    rr *= -1

    if pp >= rr and qq >= rr:
        heappush(p, pp)
        heappush(q, qq)
        break

    elif pp <= qq:
        heappush(q, qq)
        if pp < rr:
            heappush(p, rr)
    else:
        heappush(p, pp)
        if qq < rr:
            heappush(q, rr)

print(sum(p) + sum(q))

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

int main() {
 string s,t;
 cin >> s >> t;
 int x = stoi(s+t);
 for(int i = 1; i < 1000; i++){
   if(i*i == x){
     cout << "Yes" << endl;
     return 0;
   }
 }
 cout << "No" << endl;
 } 

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
string s;
long long rec(int i, long long cur, long long sum) {
	if(i == s.size()) {
		return sum;
	}
	int d = s[i] - '0';
	long long res = 0;
	if(i + 1 != s.size())
		res += rec(i + 1, cur * 10 + d, sum);
	res += rec(i + 1, 0, sum + cur * 10 + d);
	return res;
}
 
int main() {
	cin >> s;
	cout<<rec(0, 0, 0)<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
from copy import deepcopy
import math
import itertools
from collections import Counter
from functools import reduce
from fractions import gcd


def gcd_list(numbers):
    return reduce(gcd, numbers)


N, P = map(int,input().split())
X = list(map(int,input().split()))

distance = [X[i]-P for i in range(N)]

ans = gcd_list(distance)
print(abs(ans))







Measured memory_bytes: 24952
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>

using namespace std;

struct BIT{
    vector<LL> dat;
    int n;
    BIT(int _n){
        n=_n;
        dat.resize(n+1);
    }

    LL add(int x,int w){ for(int i=x;i<=n;i+=i&-i)dat[i]+=w; }
    LL get_sum(int l,int r){ return get_sum(r)-get_sum(l-1); }
    LL get_sum(int x){
        LL res=0;
        for(int i=x;i>0;i-=i&-i){
            res+=dat[i];
        }
        return res;
    }

};

int main(){

    int N,K;cin>>N>>K;
    LL a[N];
    REP(i,N)cin>>a[i];
    REP(i,N)a[i]-=K;
    LL sum[N];sum[0]=a[0];
    REP(i,N-1)sum[i+1]=sum[i]+a[i+1];
    map<LL,LL>zipped;
    LL _sum[N+1];REP(i,N)_sum[i]=sum[i];
    _sum[N]=0;
    sort(_sum,_sum+N+1);
    REP(i,N+1)zipped[_sum[i]]=i+1;

    BIT bit(N+1);
    LL ans=0;
    bit.add(zipped[0],1);
    REP(i,N){
        ans += bit.get_sum(zipped[sum[i]]);
        bit.add(zipped[sum[i]],1);
    }



    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 18944
/*
CODED BY               
**************
DARSHAN JAIN
darshanjain31
**************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
int main()
{
	fast;
	ll x,n;
	cin>>x>>n;
	ll dp[100000]={0};
	for (int i = 0; i < n; ++i)
	{
		ll p;
		cin>>p;
		dp[p]=1;
	}
	ll mn=100000;
	ll ans=0;
	ll i;
	for (i = -200;i<=200; ++i)
	{
		if(i<0)
		{
			ll mid=abs(i-x);
			if(mn>mid)
			{
				mn=abs(i-x);
				ans=i;
			}
		}
		else if(dp[i]==0)
		{
			ll mid=abs(i-x);
			if(mn>mid)
			{
				mn=abs(i-x);
				ans=i;
			}
		}

	}
	cout<<ans<<endl;

}






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

class Program
{
    static void Main()
    {
        int[] l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int r = l[0], c = l[1];
        int[] cans = new int[c + 1];
        StringBuilder ans = new StringBuilder();

        for (int i = 0; i < r; i++)
        {
            int[] o = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = 0;

            for (int j = 0; j < c; j++)
            {
                cans[j] += o[j];
                ans.Append(o[j] + " ");
                a += o[j];
            }

            cans[c] += a;
            ans.Append(a);
            ans.AppendLine();
        }
        for (int i = 0; i < c; i++)
        {
            ans.Append(cans[i] + " ");
        }
        ans.Append(cans[c]);

        Console.WriteLine(ans);
    }
}

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

vector <int> treeEdges[100100], degOut;
set <pair<int,int>> flipped;

int visit(int x, int par)
{
  int shouldFlip = 0;
  for (int y : treeEdges[x])
    if (y != par)
      if (visit(y, x))
      {
        flipped.insert({x, y});
        shouldFlip ^= 1;
      }
  return shouldFlip ^ degOut[x];
}

int main()
{
  int n, m, x, y;
  vector <pair<int,int>> edges;
  cin >> n >> m;
  if (m % 2)
  {
    cout << -1 << endl;
    return 0;
  }

  vector <int> ds(n);
  degOut = vector <int>(n, 0);
  for (int i = 0; i < n; i++)
    ds[i] = i;

  function<int(int)> get = [&](int x)
  {
    return x == ds[x] ? x : ds[x] = get(ds[x]);
  };

while (m--)
  {
    cin >> x >> y;
    edges.push_back({--x, --y});
    degOut[x] ^= 1;
    int dx = get(x), dy = get(y);
    if (dx != dy)
    {
      ds[dx] = dy;
      treeEdges[x].push_back(y);
      treeEdges[y].push_back(x);
    }
  }

  visit(0, -1);

  for (auto e : edges)
  {
    if (flipped.count({e.first, e.second}) || flipped.count({e.second, e.first}))
      swap(e.first, e.second);
    cout << e.first + 1 << ' ' << e.second + 1 << '\n';
  }
}


Measured memory_bytes: 18676
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

vector<int> cards;

int MAX = 0;
int cont = 0;
int flg = false;
int use = false;

void saiki(int now_card);

int main()
{
	for(;;){
		int n, k, temp;
		int cont = 0;
		cards.clear();
		
		cin >> n;
		cin >> k;
		
		if(n == 0 && k == 0){
			break;
		}
		
		for(int i = 0; i < k; i++){
			cin >> temp;
			cards.push_back(temp);
		}
		
		//\[g
		sort(cards.begin(), cards.end());
		
		//J[h³µÅTõ
		for(int i = 0; i < k; i++){
	//		cout << cards[i] <<"ÌJ[hðTõ"<< endl;
			if(cards[i] == 0){
				//tOª§Á½º
	//			printf("flg >> on\n");
				flg = true;
			}
			else{
				saiki(i);
			}
		}
		
		//J[hAÅTõ
		if(flg == true){
			use = true;
			for(int i = 1; i < k; i++){
	//			cout <<"à¤êñ"<< cards[i] <<"ÌJ[hðTõ"<< endl;
				saiki(i);
				use = true;
			}
		}
		
		cout << MAX << endl;
	}
}


void saiki(int now_card)					//zñÌY¦
{
//	printf("¡ÌJ[h¨%d        ÌJ[h¨%d\n",cards[now_card],cards[now_card+1]);
	if(cards[now_card]+1 == cards[now_card+1]){
	//	printf("ÌJ[hÖ\n");
		cont++;
		saiki(now_card+1);
	}
	else{
		if(use == true && cards[now_card]+2 == cards[now_card+1]){
	//		printf("úßñÈæI\n");
			cont+=2;
			use = false;
			//cards[now_card]+1 == cards[now_card+1]Å éÆ·é
			saiki(now_card+1);
		}
		
	//	printf("****I¹:%dXebv****\n",cont+1);
		if(cont+1 > MAX){
			MAX = cont+1;
		}
		cont = 0;
	}
}

Measured memory_bytes: 1484
#include<iostream>
#include<string>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int cnt(string s){
	int cnt=0;
	rep(i,s.size()){
		if(s.substr(i,4)=="west"){
			cnt++;
			i+=3;
		}else if(s.substr(i,5)=="north"){
			cnt++;
			i+=4;
		}
	}
	return cnt;
}

double dir(string s){
	if(s=="west")return 90.0;
	if(s=="north")return 0.0;
	if(s.substr(0,4)=="west"){
		return dir(s.substr(4))+90.0/pow(2,cnt(s.substr(4)));
	}else{
		return dir(s.substr(5))-90.0/pow(2,cnt(s.substr(5)));
	}
}

int main(){
	string s;
	while(cin>>s,s!="#"){
		double num=dir(s);
		rep(i,20){
			double diff=num*pow(2,i)-(int)(num*pow(2,i));
			if(abs(diff)<1e-6){
				if(i==0)cout<<(int)(num*pow(2,i))<<endl;
				else cout<<(int)(num*pow(2,i))<<"/"<<(int)pow(2,i)<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>

int main(void){
  int a , b , k;
  int max;
  scanf("%d %d %d",&a,&b,&k);
  
  for(int i = 0;i < k;i ++){
    printf("%d\n",a+i);
    max = a+i;
    if(max>=b){
      break;
    }
  }
  
  if(max>=b-k){
      int temp = k;
    k = temp - (max) + (b-k);
  }

  
  for(int i = k-1;i>=0;i --){
    printf("%d\n",b-i);
  }
  
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int H=0;
vector<long long> A;
void maxHeapify(long long i){
  int l,r,largest;
      l= 2*i+1;
      r = 2*i+2;
      // 左の子、自分、右の子で値が最大のノードを選ぶ
      if (l <= H && A[l] > A[i]){
          largest = l;
        }
      else{
          largest = i;
        }
      if (r <= H && A[r] > A[largest]){
         largest = r;
       }

     if (largest != i){
         swap(A[i],A[largest]); //を交換
         maxHeapify(largest); // 再帰的に呼び出し
       }
     }
void pushHeap() {
	long long p = H - 1;
	while (p && A[p] > A[(p - 1) / 2]) {
		swap(A[p], A[(p - 1) / 2]);
		p = (p - 1) / 2;
	}
}
int main(){
long long num;
string str;
while(1){
  cin>>str;
  if(str=="insert"){
    cin>>num;
    A.push_back(num);
    H++;
    pushHeap();
  }
  else if(str=="extract"){
    cout<<A[0]<<endl;
			A[0] = A[A.size() - 1];
			A.pop_back();
    H--;
    maxHeapify(0);
  }
    else break;
}
}


Measured memory_bytes: 11324
import java.util.*;
import java.io.*;

class Main {
  public static void main(String[] args) throws Exception{
    try (Scanner sc = new Scanner(System.in)){
      int N = sc.nextInt();
      if (N == 1) {
        System.out.println("Hello World");
      } else {
        int A = sc.nextInt();
        int B = sc.nextInt();
        System.out.println(A+B);
      }
    }
  }
}


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

int digit_sum(ll x){
    int res = 0;
    while(x){
        res += x%10;
        x /= 10;
    }
    return res;
}

using P = pair<double,ll>;

int main(void){
    int k;
    cin>>k;
    vector<P> v;
    rep(d,15){
        ll pow10 = pow(10,d);
        rep(i,1000){
            ll a = i*pow10;
            if(pow10-1 >= LLONG_MAX - a) break;
            ll x = pow10-1 + a;
            v.push_back({(double)x/digit_sum(x), x});
        }
    }
    sort(all(v));
    ll max = 0;
    int cnt = 0;
    for(P p : v){
        ll x = p.second;
        if(max >= x) continue;
        max = x;
        cout<<x<<endl;
        cnt++;
        if(cnt == k)break;
    }

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=5005;
int n,k,a[max_n];
int dp[max_n];
void add(int x){
    for(int i=k;i>=x;i--)dp[i]+=dp[i-x];
}
void del(int x){
    for(int i=x;i<=k;i++)dp[i]-=dp[i-x];
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    dp[0]=1;
    for(int i=1;i<=n;i++)add(a[i]);
    int ans=0;
    for(int i=1;i<=n;i++){
        del(a[i]);
        bool f=false;
        for(int j=max(k-a[i],0);j<k;j++)if(dp[j])f=true;
        if(!f)ans++;
        add(a[i]);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!
    println(if (s.startsWith("A") && s.substring(2, s.length - 1).count { it == 'C' } == 1 && s.count { it.isLowerCase() } == s.length - 2) {
        "AC"
    } else {
        "WA"
    })
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

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

    ll N;
    cin >> N;
    vector<int> A(N);
    REP(i,N){ cin >> A[i]; }

    vector<int> B = A;
    sort(A.begin(),A.end());
    int m1 = *A.rbegin();
    int m2 = *(A.rbegin()+1);


    for(int i = 1; i <= N; i++ ){
        if( B[i-1] == m1 ){
           cout << m2 << endl;
        }else{
           cout << m1 << endl;
        }
    }
}


Measured memory_bytes: 3200
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int N =fsc.nextInt();
        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        
        for(int i=0;i<N;i++) {
        	String S = fsc.next();
        	if (S.equals("AC"))ac++;
        	if (S.equals("WA"))wa++;
        	if (S.equals("TLE"))tle++;
        	if (S.equals("RE"))re++;
        	
        }
        fsc.close();
        System.out.println("AC x "+ac);	
        System.out.println("WA x "+wa);
        System.out.println("TLE x "+tle);
        System.out.println("RE x "+re);
        
    }
        

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


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

using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
int main() {
	vector<int>a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
	

	return 0;

}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    map<int,string> m;
    for(int x: {2,4,5,7,9})
        m[x] = "hon";
    for(int x: {0,1,6,8})
        m[x] = "pon";
    m[3] = "bon";

    int n; cin>>n;
    int l = n%10;
    cout<<m[l]<<endl;
    return 0;
}



Measured memory_bytes: 3604
from bisect import bisect_left
n,m=map(int,input().split())
ls=[[] for i in range(n)]
py=[]
for i in range(m):
  p,y=map(int,input().split())
  ls[p-1].append(y)
  py.append([p,y])
ls=list(map(lambda x:sorted(x),ls))
for i in range(m):
  p,y=py[i]
  index= bisect_left(ls[p-1],y)
  print(str(p).zfill(6)+str(index+1).zfill(6))


Measured memory_bytes: 43160
n = int(input())

##１からnの合計値
sum = 0
for i in range(1, n + 1):
	sum = sum + i

##まずは3の倍数を引く
i3 = n // 3
for i in range(1, i3 + 1):
	sum = sum - 3 * i

##次に5の倍数を引く。15の倍数は引かなくていい
i5 = n // 5
for i in range(1, i5 + 1):
	if (i % 3 != 0):
		sum = sum - 5 * i

print(sum)


Measured memory_bytes: 9088
n = int(input())
S = list(map(int, input().split(' ')))
q = int(input())
T = list(map(int, input().split(' ')))
r = 0


def linear_search(S, t):
    for s in S:
        if s == t:
            return True
    return False


for t in T:
    if linear_search(S, t):
        r += 1

print(r)



Measured memory_bytes: 6548
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;


vll par(MAX),siz(MAX);

//par[i]=iならiは根（はじめは全て根）
void init(ll n){
  rep(i,0,n){
    par[i]=i;siz[i]=1LL;
  }
  return;
}
//xの根
ll root(ll x){
  return (par[x]==x)?x:par[x]=root(par[x]);
}
//xが根の木とyが根の木を繋げる
void unite(ll x,ll y){
  x=root(x);y=root(y);
  if(x==y){return;}
  if(siz[x]<siz[y]){swap(x,y);}
  siz[x]+=siz[y];
  par[y]=x;
}
//根が同じかどうか
bool same(ll x,ll y){
  return root(x)==root(y);
}
int main(){
  ll n,m;cin>>n>>m;
  init(n+m);
  
  rep(i,0,n){
    ll k;cin>>k;
    
    rep(j,0,k){
      ll l;cin>>l;
      unite(i,l+n-1);
    }
  }
  rep(i,1,n){
    if(!same(0,i)){
      cout<<"NO"<<endl;return 0;
    }
  }
  cout<<"YES"<<endl;
  
}



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

int gcd(int a,int b){
  int temp;
  while(b!=0){
    temp=a%b;
    a=b;
    b=temp;
  }
  return a;
}

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  bool pc=true;
  vector<bool> d(1e6+1,false);
  int n,a;
  sort(A.begin(),A.end());
  for(int i=0;i<N;i++){
    if(A.at(i)==1){
      continue;
    }
    if(d.at(A.at(i))){
      pc=false;
      break;
    }
    n=A.at(i);
    a=2;
    while(a*a<=n){
      if(n%a==0){
        n/=a;
        if(!d.at(a)){
          for(int j=a;j<d.size();j+=a){
            d.at(j)=true;
          }
        }
      }else{
        a++;
      }
    }
    if(!d.at(n)){
      for(int j=n;j<d.size();j+=n){
        d.at(j)=true;
      }
    }
    if(!pc){
      break;
    }
  }
  if(pc){
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g=gcd(A.at(0),A.at(1));
  for(int i=2;i<N;i++){
    g=gcd(A.at(i),g);
  }
  if(g!=1){
    cout << "not coprime" << endl;
  }else{
    cout << "setwise coprime" << endl;
  }
  return 0;
}


Measured memory_bytes: 7140
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;
import std.typecons;
 
alias Tuple!(int, "x", int, "y") Point;
 
auto move = [[-1, 0], [0, 1], [1, 0], [0, -1]];

void main(){
    string input;
    Point[200] points;
    points[0] = Point(0, 0);
    while((input = readln.chomp) != "0"){
        int n = input.to!int;
        if(n == 1){
            "1 1".writeln;
            continue;
        }
        points[1..n] = Point.init;
        foreach(i; 1..n){
            auto line = readln.split;
            int base = line[0].to!int;
            int dir = line[1].to!int;
            points[i] = Point(points[base].x + move[dir][0], points[base].y + move[dir][1]);
        }
        auto result = reduce!(q{max(a, b.x)}, q{min(a, b.x)}, q{max(a, b.y)}, q{min(a, b.y)})(tuple(0, 0, 0, 0), points[0..n]);
        writeln(result[0] - result[1] + 1, " ", result[2] - result[3] + 1);
    }
}

Measured memory_bytes: 1548
x1 , y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x3 - (x2 - x1)
y4 = y3 - (y2 - y1) 
print(x3, y3, x4, y4, sep = " ")

Measured memory_bytes: 3060
import java.awt.Event;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.channels.FileChannel;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.IntStream;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
//		new TestA().doIt();
		new TestB().doIt();
	}
	class TestA{
		void doIt() {
			String str = sc.next();
			if(str.equals("AAA") || str.equals("BBB")) {
				System.out.println("No");
			}else {
				System.out.println("Yes");
			}
		}
	}
	class TestB{
		void doIt() {
			long N = Long.parseLong(sc.next());
			long A = Long.parseLong(sc.next());
			long B = Long.parseLong(sc.next());
			long Loop = N / (A + B);
			N = N % (A + B);
			
			long Acount = Loop * A;
			if(N < A)Acount += N;
			else if(N >= A)Acount += A;
			
			System.out.println(Acount);
		}
	}
}


Measured memory_bytes: 23892
//
//  main.cpp
//  zhandui
//
//  Created by 贾皓翔 on 2019/1/21.
//  Copyright © 2019 贾皓翔. All rights reserved.
//
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#define ll long long
using namespace std;

pair<ll, ll> gainClosestFactor(ll n)
{
    ll i;
    ll integral_part = (ll)sqrt(n);
    if(n % integral_part == 0)
        return make_pair(integral_part, n / integral_part);
    else
    {
        ll flag;
        ll low = pow(integral_part, 2);
        ll high = pow(integral_part + 1, 2);
        if((n - low) >= (high - n))
            flag = integral_part + 1;
        else
            flag = integral_part;
        for(i = flag - 1; i > 0; i--)
        {
            if(n % i == 0)
                break;
        }
        return make_pair(i, n / i);
    }
}


int main(){
    ll a;
    cin>>a;
    auto i=gainClosestFactor(a);
    cout<<(i.first+i.second-2)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
signed main(){
	int n,a;
	int odd=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a%2==1)odd++;
	}
	if(odd%2==0)puts("YES");
	else puts("NO");
	return 0;
}



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

int main() {
	long long x, y;
	cin >> x >> y;
  	int i=x;
	if (x%y == 0)cout << -1;
	else while (1) {
		if (i%x == 0 && i%y != 0) {
			cout << i;
			break;
		}
      	i++;
	}
}

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

#define all(x) (x).begin(),(x).end()
#define init() \
  ios::sync_with_stdio(false); \
  cin.tie(0)

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
  return a == 0 ? b
    : b == 0 ? a
    : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

int main() {
  init();

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

  vector<pair<int, int>> ps(m);

  int ac = 0;
  int wa = 0;
  bool acd[100005] = {};
  int mwa[100005] = {};
  for (int i = 0; i < m; i++)
  {
    int p;
    string ss;
    cin >> p >> ss;

    if (!acd[p]) {
      if (ss == "WA") {
        mwa[p]++;
      } else {
        ac++;
        wa += mwa[p];
        acd[p] = true;
      }
    }
  }

  cout << ac << ' ' << wa << '\n';

  return 0;
}


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

using namespace std;

typedef long long int ll;

const int mod = 1e9 + 7;

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

  int n, m;
  cin >> n >> m;
  vector < ll > x(n + 1), y(m + 1),py(m + 1, 0), px(n + 1, 0);
  for(int i = 1; i <= n; i++){
    cin >> x[i];
    px[i] = px[i - 1] + x[i];
    px[i] %= mod;
  }
  for(int i = 1; i <= m; i++){
    cin >> y[i];
    py[i] = py[i - 1] + y[i];
    py[i] %= mod;
  }

  ll a = 0, b = 0;
  for(int i = 2; i <= m; i++){
    a = (a + (i - 1) * y[i] - py[i - 1] + mod) % mod;
  }
  for(int i = 2; i <= n; i++){
    b = (b + (i - 1) * x[i] - px[i - 1] + mod) % mod;
  }

  ll ans = (a * b) % mod;
  cout << ans << '\n';
}


Measured memory_bytes: 3456
import fractions
n,x=map(int,input().split())
a=list(map(int,input().split()))
a[0]=abs(a[0]-x)
g=a[0]
for i in range(1,n):
  a[i]=abs(a[i]-x)
  g=fractions.gcd(g,a[i])
print(g)

Measured memory_bytes: 16296
while True:
    s=raw_input()
    if s==".":break
    ST=[]
    flag=True
    for i in s:
        if i=="(" or i=="[":
            ST.append(i)
        elif i==")":
            if len(ST)>0 and ST[-1]=="(":
                ST.pop()
            else:
                flag=False
                break
        elif i=="]":
            if len(ST)>0 and ST[-1]=="[":
                ST.pop()
            else:
                flag=False
                break
    print "yes" if flag and len(ST)==0 else "no"

Measured memory_bytes: 4244
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int N,M;
int A[1<<17];
int B[1<<17];
vector<pair<int,int> >G[1<<17];
bool used[2<<17];
bool vis[1<<17];
bool dfs(int u)
{
	vis[u]=true;
	for(pair<int,int>e:G[u])
	{
		int v=e.first;
		if(vis[v])continue;
		if(dfs(v))
		{
			B[v]++;
			B[u]++;
			used[e.second]=true;
		}
	}
	return B[u]%=2;
}
main()
{
	cin>>N>>M;
	vector<pair<int,int> >AB(N);
	for(int i=0;i<N;i++)
	{
		cin>>AB[i].first>>AB[i].second;
	}
	sort(AB.begin(),AB.end());
	for(int i=0;i<N;i++)A[i]=AB[i].first;
	for(int i=0;i<=N;i++)B[i]=(i==N?0:AB[i].second)!=(i==0?0:AB[i-1].second);
	for(int i=0;i<M;i++)
	{
		int L,R;cin>>L>>R;
		L=lower_bound(A,A+N,L)-A;
		R=upper_bound(A,A+N,R)-A;
		G[L].push_back(make_pair(R,i));
		G[R].push_back(make_pair(L,i));
	}
	for(int i=0;i<=N;i++)
	{
		if(!vis[i]&&dfs(i))
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	int anscnt=0;
	for(int i=0;i<M;i++)anscnt+=used[i];
	cout<<anscnt<<endl;
	for(int i=0;i<M;i++)
	{
		if(used[i])
		{
			anscnt--;
			cout<<i+1<<(anscnt==0?"\n":" ");
		}
	}
}


Measured memory_bytes: 15232
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string  S;
	cin >> S;

	if (S[0] == S[1] || S[1] == S[2] || S[3] == S[2]) {
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}

	return 0;
}



Measured memory_bytes: 384
N = int(input())
s = str(input())
types = []
for i in range(len(s)-1):
    x = list(s[:i+1])
    y = list(s[i+1:])
    x.sort()
    y.sort()
    x_str = []
    y_str = []
    count = 0
    for j in range(len(x)):
        if j == 0:
            x_str.append(x[0])
        else:
            if x[j-1] != x[j]:
                x_str.append(x[j])
    for j in range(len(y)):
        if j == 0:
            y_str.append(y[0])
        else:
            if y[j-1] != y[j]:
                y_str.append(y[j])
    for j in range(len(x_str)):
        if x_str[j] in y_str:
            count += 1
    types.append(count)
print(max(types))

Measured memory_bytes: 3064
#include<stdio.h>

int geshu(int ai, int day)
{
	int i;
	int  flag = 0;

	for (i = 1; i <= day; i=i+ai)
	{
		flag++;
	}

	return flag;
}


int main()
{
	int n;
	int a[100];
	int day;
	int rest;
	int i;
	int zgeshu;


	scanf("%d%d%d",&n,&day,&rest);
	zgeshu = rest;
	for (i = 0; i < n; i++)
	{
		scanf("%d",&a[i]);
		zgeshu = zgeshu + geshu(a[i], day);
	}
	
	printf("%d", zgeshu);

    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			int n=sc.nextInt(), m=sc.nextInt(), s=sc.nextInt(), g1=sc.nextInt(), g2=sc.nextInt();
			if(n == 0) break;

			int[][] map = new int[n+1][n+1];
			while(m-- > 0){
				map[sc.nextInt()][sc.nextInt()] = sc.nextInt();
			}

			int min = Integer.MAX_VALUE;
			for(int i=1;i<=n;i++){
				int c1=minCost(i,g1,map);
				int c2=minCost(i,g2,map);
				int c3=minCost(s,i,map);

				if(c1==-1 || c2==-1 || c3==-1) continue;
				min = Math.min(min, c1+c2+c3);
			}
			System.out.println(min);
		}
	}

	public static int minCost(int s,int g,int[][] map){
		Queue<State> open = new PriorityQueue<State>();
		Set<State> closed = new HashSet<State>();

		State st = null, ans = null;
		open.add(new State(0,s));
		while(!open.isEmpty()){
			st = open.poll();
			if(closed.contains(st)) continue;
			closed.add(st);
			if(st.n == g){
				ans = st;
				break;
			}
			open.addAll(st.nexts(map));
		}

		if(ans == null) return -1;
		return ans.cost;
	}
}

class State implements Comparable<State>{
	int cost,n;

	State(int cost, int n){
		this.cost = cost;
		this.n = n;
	}

	List<State> nexts(int[][] map){
		List<State> sts = new ArrayList<State>();

		for(int i=1;i<map.length;i++){
			if(n == i) continue;
			if(map[n][i] > 0) sts.add(new State(cost+map[n][i],i));
		}

		return sts;
	}

	public int compareTo(State st){
		return this.cost - st.cost;
	}

	public boolean equals(Object o){
		State st = (State)o;
		return this.n == st.n;
	}

	public int hashCode(){
		return n;
	}
}

Measured memory_bytes: 15000
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 99999999999999;
const ll MOD = 998244353;
ll a, b, c, d, e, f, p, t, x, y,z, q, m, n, r, h, k, ans = 0, w;

vl A;
void input() {
	cin >> n;
	inputv(A, n);
}

void solve() {
	sort(all(A));
	rep(i, n) {
		rep(j, i) {
			a = A[i] + A[j];
			ans += lower_bound(all(A), a) - A.begin() - i - 1;
		}
	}

	cout << ans << endl;
}

int main() {
	input();
	solve();
}

Measured memory_bytes: 256