akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

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

  vector<int> cnt(N+1,0);
  for(int x=1;x<=100;x++){
    for(int y=1;y<=100;y++){
      for(int z=1;z<=100;z++){
        int n=x*x + y*y + z*z + x*y + y*z + z*x;
        if(n<=N)  cnt.at(n)++;
      }
    }
  }
  for(int i=1;i<=N;i++) cout << cnt.at(i) << endl;

  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
int n,m,ans;
vector<int>g[100005];
vector<int>o;
int s[100005];
bool vis[100005];
void dfs(int v){
    vis[v]=true;
    o.push_back(v);
    for(int i=0;i<g[v].size();i++){
        if(!vis[g[v][i]])dfs(g[v][i]);
    }
}
int main(void){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",s+i);
        
    }
    for(int i=0;i<m;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            o.clear();
            dfs(i);
            set<int>q;
            for(int i=0;i<o.size();i++)q.insert(o[i]);
            for(int i=0;i<o.size();i++)if(q.find(s[o[i]])!=q.end())ans++;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 13304
def rolling_hash(S, base, MOD):
    l = len(S)
    h = [0]*(l + 1)
    for i in range(l):
        h[i+1] = (h[i] * base + ord(S[i])) % MOD
    return h


C = open(0).read().split()
MOD = 358976445361682909
base = 31
for t in range(len(C)//2):
    S = C[2*t]; T = C[2*t+1]
    rhs = rolling_hash(S, base, MOD)
    rht = rolling_hash(T, base, MOD)
    L = len(S); M = len(T)
    def solve(l):
        v = pow(base, l, MOD)
        hs = set()
        for i in range(L-l+1):
            hs.add((rhs[i+l] - rhs[i]*v) % MOD)
        for i in range(M-l+1):
            if (rht[i+l] - rht[i]*v) % MOD in hs:
                return 1
        return 0
    left = 0; right = min(L, M)+1
    while left+1 < right:
        mid = (left + right) // 2
        if solve(mid):
            left = mid
        else:
            right = mid
    print(left)


Measured memory_bytes: 6184
import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    //This code is not meant for understanding, you have been warned.
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        String s = n();
        int a = Integer.parseInt(s.substring(0, 2)), b = Integer.parseInt(s.substring(2, 4));
        boolean b1 = 1<= a && a<= 12;
        boolean b2 = 1<= b && b<= 12;
        if(b1){
            if(b2)pn("AMBIGUOUS");
            else pn("MMYY");
        }else{
            if(b2)pn("YYMM");
            else pn("NA");
        }
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    long mod = (long)998244353, IINF = (long)1e18;
    final int INF = (int)1e9, MX = (int)5e5+1;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
    static boolean multipleTC = false, memory = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }  
            return str;
        }
    }
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

void kr(int i);

int n,a[10],ans;

signed main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    kr(0);
    cout << ans << endl;
}

void kr(int i) {
    int d[3]={-1,0,1};
    if (i == n) {
        int sum=1;
        rep(j,n) sum*=a[j];
        if (!(sum%2)) ans++;
        return;
    }
    rep(j,3) {
        a[i] += d[j];
        kr(i+1);
        a[i] -= d[j];
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; 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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  string s;
  cin >> s;
  if (count(s.begin(), s.end(), 'a') && count(s.begin(), s.end(), 'b') && count(s.begin(), s.end(), 'c'))
    cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC171
{
    class Program
    {
        static void Main(string[] args)
        {
            b();
        }

        public static void b()
        {
            int[] nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(p);
            int ans = 0;
            for(int i = 0; i < nk[1]; i++)
            {
                ans += p[i];
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28584
#include <iostream>
using namespace std;
int bubble_sort(int date[], int n){
	int count = 0;
	for(int i=0;i<n-1;i++){
		for(int j=n-1;j>i;j--){
			if(date[j]<date[j-1]){
				int tmp = date[j];
				date[j] = date[j-1];
				date[j-1] = tmp;
				count++;
			}
		}
	}
	return(count);
}
			

int main(void)
{
	int n;
	int date[100];
	while(cin>>n){
		if(!n) break;
		for(int i = 0; i < n; i++){
			cin >> date[i];
		}
		cout << bubble_sort(date,n) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
n, t = map(int, input().split())
 
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
 
a = []
b = []
for ai, bi in ab:
    a.append(ai)
    b.append(bi)
 
dp = [[0 for j in range(t)] for i in range(n+1)]
 
for i in range(n):
    for j in range(t):
        if j + a[i] <= t-1:
            if dp[i+1][j + a[i]] < dp[i][j] + b[i]:
                dp[i+1][j + a[i]] = dp[i][j] + b[i]
        if dp[i+1][j] < dp[i][j]:
            dp[i+1][j] = dp[i][j]
 
ans = 0
 
for i in range(n):
    ans = max(ans, dp[i][t-1] + b[i])
 
print(ans)


Measured memory_bytes: 124376
#include<iostream>
#include<math.h>
using namespace std;

int gcd(int& a,int& b){
  int r;
  if(a<b){
    return gcd(b,a);
  }else{
    while((r=a%b)){
      a=b;
      b=r;
    }
    return b;
  }
}


int main(void){
  int N,X;
  cin >>N>>X;
  int x[N];
  int n;
  for(int i=0;i<N;i++){
    cin >>x[i];
  }
  int a=x[0]-X;
  int b=x[N-1]-X;
  int D=gcd(a,b);
  for(int i=0;i<N;i++){
    int a=x[i]-X;
    D=gcd(a,D);
  }

  cout <<abs(D)<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    int a, n, poz = 1, nr, i;
    cin >> n;

    for(i = 1, nr = 0 ; i <= n ; i++)
    {
        cin >> a;
        (a != poz) ? nr++ : poz++;
    }

    (nr == n) ? cout << -1 : cout << nr;

    return 0;
}


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

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);
        int s=sc.nextInt();
        int w= sc.nextInt();
        if(s>w){
            System.out.println("safe");
        }else{
            System.out.println("unsafe");
        }
    }
}

Measured memory_bytes: 35768
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N, T;
    cin >> N >> T;
    vector<tuple<lint, lint>> tu(N);
    REP(i, N) {
        lint A, B;
        cin >> A >> B;
        tu[i] = make_tuple(A, B);
    }
    sort(tu.begin(), tu.end(),
       [](auto const &a, auto const &b) { return get<0>(a) < get<0>(b); });
    vector<vector<lint>> dp(N+1, vector<lint>(6001, 0));
    vector<vector<lint>> dp2(N+1, vector<lint>(6001, 0));
    REP(i, N) {
        REP(j, 6001) {
            if(j < get<0>(tu[i])) {
                dp[i+1][j] = dp[i][j];
                dp2[i+1][j] = dp2[i][j];
            } else {
                if(dp[i][j-get<0>(tu[i])]+get<1>(tu[i]) >= dp[i][j] && j-max(dp2[i][j], get<0>(tu[i])) < T) {
                    dp2[i+1][j] = max(dp2[i][j], get<0>(tu[i]));
                    dp[i+1][j] = dp[i][j-get<0>(tu[i])]+get<1>(tu[i]);
                } else {
                    dp2[i+1][j] = dp2[i][j];
                    dp[i+1][j] = dp[i][j];
                }
            }
        }
    }
    lint max = 0;
    REP(j, 6001) {
        if(dp[N][j] > max && j < dp2[N][j]+T) {
            //cout << j << dp[N][j]<< dp2[N][j] << endl;
            max = dp[N][j];
        }
    }
    cout << max << endl;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int n;
ll ans = 0;
vector<vi> g;
vector<bool> used;
void dfs(int v, int d) {
    if (d == n) {
        ++ans;
        return;
    }
    for (int to : g[v]) {
        if (used[to]) continue;
        used[to] = true;
        dfs(to, d+1);
        used[to] = false;
    }
}

int main(){
    int m;
    cin >> n >> m;
    used = vector<bool>(n);
    g = vector<vi>(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    used[0] = true;
    dfs(0, 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int ans = 0;
    if (a > b)
    {
        ans += b;
    }
    else
    {
        ans += a;
    }
    if (c > d)
    {
        ans += d;
    }
    else
    {
        ans += c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <complex>
#include <algorithm>
#include <iomanip>

using namespace std;

const double eps = 1e-10;
typedef complex<double> Point;

inline double cross(const Point&a, const Point& b){
    return imag(conj(a) * b);
}

typedef vector<Point> Polygon;

Point next(const Polygon& g, int x){
    return g[(x+1) % (int)g.size()];
}

double convexdiameter(const Polygon& ch){
    auto comp = [](const Point& a, const Point& b){
        return make_pair(imag(a), real(a)) < make_pair(imag(b), real(b));
    };
    int is = max_element(ch.begin(), ch.end(), comp) - ch.begin(),
        js = min_element(ch.begin(), ch.end(), comp) - ch.begin();
    double res = abs(ch[is] - ch[js]);
    int i = is, j = js, maxi = is, maxj = js;
    do{
        ((0 <= cross(next(ch, i) - ch[i], next(ch, j) - ch[j])? j: i) += 1) %= (int)ch.size();
        double d = abs(ch[i] - ch[j]);
        if(res + eps <= d)res = d, maxi = i, maxj = j;
    }while(i != is || j != js);
    return res;
}

int main(){
    int n;
    cin >> n;
    Polygon g;
    while(n--){
        double x, y;
        cin >> x >> y;
        g.emplace_back(x, y);
    }
    cout << fixed << setprecision(12) << convexdiameter(g) << '\n';
    return 0;
}

Measured memory_bytes: 3144
#include <stdio.h>
 
int main(void) {
	/*
    int a;
    int b;
    int c;
    scanf("%d%d%d",&a,&b,&c);
    //a,b,c?????????????????¨??¨??§3!=6??????????????§??????????????¨??¨????????°??????
    if(a<=b&&b<=c) printf("%d %d %d\n",a,b,c);
    else if(a<=c&&c<=b) printf("%d %d %d\n",a,c,b);
    else if(b<=a&&a<=c) printf("%d %d %d\n",b,a,c);
    else if(b<=c&&c<=a) printf("%d %d %d\n",b,c,a);
    else if(c<=a&&a<=b) printf("%d %d %d\n",c,a,b);
    else if(c<=b&&b<=a) printf("%d %d %d\n",c,b,a);
    */
    int a[3];
    int i,j;
    int t;
    for(i=0;i<3;i++){
    	scanf("%d",&a[i]);
    }
    for(i=0;i<3;i++){
    	for(j=0;j+1<3;j++){
    		if(a[j]>a[j+1]){
				t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;			
    		}
    	}
    }
    printf("%d %d %d\n",a[0],a[1],a[2]);
    return 0;
}

Measured memory_bytes: 596
N,M = map(int,input().split())
li = []
ans = 0
for i in range(N):
    AB = list(map(int,input().split()))	
    li.append(AB)
li.sort()
i=0
while M > 0:
    M -= li[i][1]
    ans += li[i][0]*li[i][1]
    if M < 0:
        ans -= abs(M)*li[i][0]
    i+=1
print(ans)

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

#define ll long long
int main()
{
    ll n;
    cin>>n;
    
    ll a[n];
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
    }
    
    ll ans=INT_MAX;
    ll sum1=0,sum2=0;
    for(ll i=0;i<n;i++)
    {
        sum1=sum1+a[i];
        sum2=sum-sum1;
        ans=min(ans,abs(sum2-sum1));
    }
    cout<<ans;
}
  

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int[] c;
    static int[][] dp;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        c = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = scan.nextInt();
        }

        long ret = 0;
        int rgt =0;
        int tmp = 0;
        for (int lft = 0; lft < n; lft++) {
            while(rgt < n && tmp + c[rgt] == (tmp ^ c[rgt])) {
                tmp += c[rgt];
                rgt++;
            }
            ret += rgt - lft;
            if(lft == rgt) {
                rgt++;
            }
            tmp -= c[lft];
        }

        System.out.println(ret);
    }
}


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



int main() {
    int x;
    cin >> x;
    
    int ans = -1;
    vector<int> prime;
    prime.push_back(2);
    
    if(x == 2)
        ans = 2;
    else {
        for(int i = 3; i < 1000000; i+=2) {
            bool tf = true;
            rep(j,prime.size()) {
                if(i % prime[j] == 0) {
                    tf = false;
                    break;
                }
            }
            if(tf) {
                prime.push_back(i);
                if(i >= x) {
                    ans = i;
                    break;
                }
            }
        }
    }
    
    cout << ans << endl;
    
    
    
    return 0;
}




Measured memory_bytes: 3700
n = int(input())
h = list(map(int, input().split()))

dp = [100000] * n

dp[0] = 0

for i in range(0, n):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(h[i-1] - h[i])
    else:
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])


Measured memory_bytes: 13908
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
using namespace::std;
int main(){

 int A;
  cin>>A;
   int *N=new int[A];
  for(int i=0;i<A+1;i++){
    cin>>N[i];
  }
  N[A]=N[0];
    long  int ans=0;

   int *M=new int[A];
   int c=A-2;
  int hoge=0;
  for(int i=0;i<A-1;i++){
    M[c]=hoge+2*(N[c]-N[c+1]);
    hoge=M[c];
    if(c==1){
      c=A+1;
    }
    c=c-2;
  }
  long long int sumM=0;
  long long int sumN=0;
  for(int i=0;i<A;i++){
    sumM=sumM+M[i];
    sumN=sumN+N[i];
  }
  ans=(sumN-sumM)/A;
  cout<<ans;
  for(int i=1;i<A;i++){
    cout<<" "<<ans+M[i];
  }
    
  
  
}


Measured memory_bytes: 2048
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(A: int, B: int, C: int, D: int):
    def doit(N):
        a = A
        if a % N != 0:
            a += (N - A % N)
        return (B - a) // N + 1
    cs = doit(C)
    ds = doit(D)

    E = (C * D) // gcd(C, D)
    es = doit(E)

    return (B - A + 1) - cs - ds + es


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    result = solve(A, B, C, D)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5252
import java.util.*;

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

        int ret = 0;

        while (X <= Y) {
            ret++;
            X *= 2;
        }

        System.out.println(ret);
    }
}

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

void swap(int *a, int *b){
    int temp = *a;
    *a = *b;
    *b = temp;
}
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    swap(&a,&b);
    swap(&a,&c);
    cout << a << " " << b << " " << c;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int n,m,cnt[100005];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int x,y; scanf("%d%d",&x,&y);
        cnt[x]++; cnt[y]++;
    }
    for(int i=1;i<=n;i++)
        if(cnt[i]%2!=0){printf("NO");return 0;}
    printf("YES"); return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
    

int main() {
    int A,B;
    cin >> A >> B;
    if(A <= 9 && B <= 9){
        cout << A * B <<endl;
    }
    else{
        cout << -1 <<endl;
    }
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=101000;
int n;
PII p[N],q1[N],q2[N];
ll s1[N],s2[N];
ll cross(PII p,PII q) {
	return (ll)p.fi*q.se-(ll)p.se*q.fi;
}
bool cmp0(PII p,PII q,PII r) {
	q.fi-=p.fi; q.se-=p.se;
	r.fi-=p.fi; r.se-=p.se;
	if (q.fi==r.fi) return r.se<q.se;
	else return (ll)q.fi*r.se<=(ll)q.se*r.fi;
}

bool cmp1(PII p,PII q,PII r) {
	q.fi-=p.fi; q.se-=p.se;
	r.fi-=p.fi; r.se-=p.se;
	if (q.fi==r.fi) return r.se>q.se;
	else return (ll)q.fi*r.se>=(ll)q.se*r.fi;
}

void gao(ll *s) {
//	sort(p,p+n);
	s[0]=s[1]=0;
	int h1=0,t1=1,h2=0,t2=1;
	ll S=0;
	q1[0]=p[0]; q2[0]=p[0];
	rep(i,1,n) {
		while (h1+1<t1&&cmp0(q1[t1-2],q1[t1-1],p[i])) {
			S-=cross(q1[t1-2],q1[t1-1]);
			--t1;
		}
		q1[t1++]=p[i];
		S+=cross(q1[t1-2],q1[t1-1]);
		while (h2+1<t2&&cmp1(q2[t2-2],q2[t2-1],p[i])) {
			S-=cross(q2[t2-1],q2[t2-2]);
			--t2;
		}
		q2[t2++]=p[i];
		S+=cross(q2[t2-1],q2[t2-2]);
		s[i+1]=S;
	}
//	rep(i,0,n) printf("%d %d %lld\n",p[i].fi,p[i].se,s[i+1]);
}
int main() {
	scanf("%d",&n);
	rep(i,0,n) scanf("%d%d",&p[i].fi,&p[i].se);
	sort(p,p+n);
	gao(s1);
	rep(i,0,n) p[i].fi=-p[i].fi;
	reverse(p,p+n);
	gao(s2);
	rep(i,0,n) p[i].fi=-p[i].fi;
	reverse(p,p+n);
	reverse(s2,s2+n+1);
	ll ret=min(s1[n],s2[0]);
	rep(i,0,n-1) if (p[i].fi!=p[i+1].fi) {
		ret=min(ret,s1[i+1]+s2[i+1]);
	}
	printf("%lld\n",(ret+1)/2);
}

Measured memory_bytes: 6640
n,k = map(int, input().split())
mod = 10**9+7

def inv(a,mod):
    r = [1,0,a]
    w = [0,1,mod]
    while w[2]!=1:
        q = r[2]//w[2]
        r_new = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = w
        w = r_new
    x,y = w[0],w[1]    # a*x+y*mod = 1
    return (mod+x%mod)%mod

max_num = 2*10**5+1
fact = [0 for _ in range(max_num)]
ifact = [0 for _ in range(max_num)]

fact[0] = fact[1] = 1
ifact[0] = ifact[1] = 1

for i in range(2,max_num):
    fact[i] = fact[i-1] * i % mod
    ifact[i] = ifact[i-1] * inv(i,mod) % mod

def comb(x,y):
    return fact[x] * ifact[y] * ifact[x-y] % mod

ans = 1

ff = min(k+1,n)

for i in range(1,ff):
    ans += comb(n,i) * comb(n-1,i)
    ans %= mod

print(ans)






Measured memory_bytes: 55372
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;
int w, h;

const int INF = 1 << 29;
typedef pair<int, int> P;

int dp[102][102];
int n;
int compress(vector<int>& vec1, vector<int>& vec2, int size)
{
	vector<int> compressed;
	for (int i = 0; i < n; i++)
	{
		for (int j = -1; j <= 1; j++)
		{
			int n1 = vec1[i] + j, n2 = vec2[i] + j;
			if(0 <= n1 && n1 < size) compressed.push_back(n1);
			if(0 <= n2 && n2 < size) compressed.push_back(n2);
		}
	}

	sort(compressed.begin(), compressed.end());
	compressed.erase(unique(compressed.begin(), compressed.end()), compressed.end());

	for (int i = 0; i < n; i++)
	{
		vec1[i] = find(compressed.begin(), compressed.end(), vec1[i]) - compressed.begin();
		vec2[i] = find(compressed.begin(), compressed.end(), vec2[i]) - compressed.begin();
	}

	return compressed.size();
}

int main(void)
{
	while(cin >> w >> h && w && h)
	{
		vector<int> x1, x2, y1, y2;
		cin >> n;
		x1.resize(n); x2.resize(n); y1.resize(n); y2.resize(n);
		for (int i = 0; i < n; i++)
		{
			cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		}
		w = compress(x1, x2, w);
		h = compress(y1, y2, h);

		vector<vector<bool> > fid;
		fid.resize(h);
		for (int i = 0; i < h; i++)
		{
			fid[i].resize(w);
		}

		for (int i = 0; i < n; i++)
		{
			for (int y = y1[i]; y < y2[i]; y++)
			{
				for (int x = x1[i]; x < x2[i]; x++)
				{
					fid[y][x] = true;
				}
			}
		}

		int ans = 0;
		int dx[] = {-1, 0, 1, 0};
		int dy[] = {0, -1, 0, 1};
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if(fid[i][j]) continue;
				ans++;

				queue<P> que;
				que.push(P(j, i));
				while (!que.empty())
				{
					int sx = que.front().first, sy = que.front().second;
					que.pop();
					for (int i = 0; i < 4; i++)
					{
						int nx = sx + dx[i], ny = sy + dy[i];
						if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
						if(fid[ny][nx]) continue;
						que.push(P(nx, ny));
						fid[ny][nx] = true;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  int n;
  cin >> n;
  int a=0,b=0,time=0;
  rep(i,n){
    int t,x,y;
    cin >> t >> x >> y;
    int dis = abs(x-a)+abs(y-b);
    //cout << dis << endl;
    if(dis <= (t -time) and (t - time - dis)%2 == 0){
      time = t;
      a = x;
      b = y;
    }else{
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}


Measured memory_bytes: 256
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> P;
P A[100],j=sqrt(-1),p,p0;
double a,b,d;
int n;
int f(int m){
	int i,s1=2,s2=2;
	d=acos(a/2);
	P p3=polar(1.0,b+d)+p,p4=polar(1.0,b-d)+p;
	for(i=0;i<n;i++){
		if(A[i]==p||A[i]==p0)continue;
		if(abs(A[i]-p3)-1<1e-6)s1++;
		if(abs(A[i]-p4)-1<1e-6)s2++;
	}
	if(m<s1)m=s1;
	if(m<s2)m=s2;
	return m;
}
int main(){
	int m,i,i1;
	char c;
	while(cin>>n,n!=0){
		for(i=0;i<n;i++){
			cin>>a>>c>>b;A[i]=P(a,b);
		}
		m=1;
		for(i=0;i<n;i++){
			p=A[i];
			for(i1=i+1;i1<n;i1++){
				p0=A[i1];a=abs(p0-p);b=arg(p0-p);
				if(a<=2)m=f(m);
			}
		}
		cout<<m<<endl;
	}
}

Measured memory_bytes: 1348
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll n;

    cin >> n;

    cout << setprecision(10) << (double)(n - n / 2) / n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int l, w = 0, num = 0;
    ll ans = 0;
    string S;
    cin >> S;
    l = S.length();

    for(int i=0;i<l;i++){
        if(S[i] == 'W'){
            ans += i - num;
            num++;
        }
    }
   
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i

count = 0
(a + 1).times do |i|
	(b+1).times do |j|
		(c+1).times do |k|
			count += 1 if i * 500 + j * 100 + k * 50 == x
			end
		end
	end
puts count


Measured memory_bytes: 1788
# ARC076C - Reconciled?
from math import factorial


def main():
    n, m = list(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    n, m = min(n, m), max(n, m)
    dif = m - n
    if dif > 1:  # must be ...DDM...
        print(0)
    else:
        if dif == 0:  # start with either D or M (DM..., MD...)
            ans = (factorial(n) ** 2 * 2) % MOD  # n == m -> (n!)^2 * 2
        else:  # sandwich (DMD or MDM)
            ans = (factorial(n) ** 2 * m) % MOD  # n + 1 == m -> (n!)^2 * m
        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 4740
const inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
const num = Number(inp)
if (num < 1000){
    console.log(1000-num)
} else if (num % 1000 === 0){
    console.log(0)
} else {
    console.log(1000-(num % 1000))
}


Measured memory_bytes: 29692
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val s = br.readLine()!!

    val eSumsFromLeft = IntArray(n + 1)
    for (i in 0 until n) {
        eSumsFromLeft[i + 1] = eSumsFromLeft[i] + if (s[i] == 'E') 1 else 0
    }

    var ans = Int.MAX_VALUE
    for (i in 0 until n) {
        val turnRight = i - eSumsFromLeft[i]
        val turnLeft = eSumsFromLeft[n] - eSumsFromLeft[i + 1]
        ans = min(ans, turnRight + turnLeft)
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 39384
N = int(input())

stations = [tuple(map(int, input().split(' '))) for _ in range(N - 1)]

for i in range(N - 1):
    t = 0
    for j in range(i, N - 1):
        c, s, f = stations[j]
        t = max(t, s)
        if t % f != 0:
            t += f - t % f
        t += c
    print(t)
print(0)


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

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream& operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template <typename T>
inline void printV(vector<T>& a, int n) { for(int i=0; i<n; i++) { cerr<<a[i]<<" "; } cerr<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a) { for(int i=0; i<sz(a); i++) { cerr<<a[i]<<"\n"; } cerr<<"\n"; }
template <typename T>
inline void clearVV(vector<vector<T>>& a) { for(auto &x : a) { x.clear(); } a.clear(); }
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val) { for(int i=0; i<sz(a); i++) { a[i].assign(sz(a[i]), val); } }
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	int n;
	cin>>n;
	vector<pii> a;
	for(int i=0; i<n; i++) {
		int x, y;
		cin>>x>>y;
		a.push_back(MP(y, x));
	}
	sort(all(a));
	int sum = 0;
	bool flag = 1;
	for(int i=0; i<n; i++) {
		sum += a[i].second;
		if(sum > a[i].first) {
			flag = 0;
			break;
		}
	}
	cout<<(flag?"Yes\n":"No\n");
    return 0;
}



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

typedef vector<int> vec;

int main() {
    int t; cin >> t;
    vec times(t), timee(t), count(t);
    for(int i = 0; i < t; i++) {
        int h1, m1, h2, m2;
        char c;
        cin >> h1 >> c >> m1 >> c >> h2 >> c >> m2;
        times[i] = h1 * 60 + m1;
        timee[i] = h2 * 60 + m2;
    }

    int n; cin >> n;
    for(int i = 0; i < n; i++) {
        int s; cin >> s;
        for(int k = 0; k < s; k++) {
            int h1, m1, h2, m2;
            char c;
            cin >> h1 >> c >> m1 >> c >> h2 >> c >> m2;
            int teachers = h1 * 60 + m1;
            int teachere = h2 * 60 + m2;
            for(int j = 0; j < t; j++) {
                if(teachers <= times[j] && timee[j] <= teachere) {
                    count[j]++;
                }
            }
        }
    }

    int m; cin >> m;
    int res = 0;
    for(int i = 0; i < m; i++) {
        int s; cin >> s;
        for(int k = 0; k < s; k++) {
            int h1, m1, h2, m2;
            char c;
            cin >> h1 >> c >> m1 >> c >> h2 >> c >> m2;
            int students = h1 * 60 + m1;
            int studente = h2 * 60 + m2;
            for(int j = 0; j < t; j++) {
                if(students <= times[j] && timee[j] <= studente) {
                    if(count[j]) res++, count[j]--;
                }
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1196
// https://atcoder.jp/contests/abc153/tasks/abc153_b
import java.lang.Math.*
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val H = scn.nextInt()
    val N = scn.nextInt()

    var A = 0
    for(a in 1..N){
        A += scn.nextInt()
    }

    if(A >= H) {
        println("Yes")
    }else{
        println("No")
    }
}

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

using namespace std;
vector<int> left(vector<int> a,vector<int> l);
vector<int> right(vector<int> a,vector<int> r);
int n;

int main(){
    cin>>n;
    vector<int> a(n);
    vector<int> l(n+1);
    vector<int> r(n+1);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0;
    l=left(a,l);
    r=right(a,r);
    for(int i=1;i<n-1;i++){
        //cout<<l[i]<<" "<<r[i+1]<<endl;
        ans=max(ans,__gcd(l[i-1],r[i+1]));
    }
    ans=max(ans,r[1]);
    ans=max(ans,l[n-2]);
    cout<<ans<<endl;
    return 0;
}
vector<int> left(vector<int> a,vector<int> l){
    l[0]=a[0];
    for(int j=1;j<n;j++){
        l[j]=__gcd(l[j-1],a[j]);
    }
    return l;
}
vector<int> right(vector<int> a,vector<int> r){
    r[n]=a[n-1];
    for(int j=n-1;j>=0;j--){
        r[j]=__gcd(r[j+1],a[j]);
        //cout<<r[j-1]<<endl;
    }
    return r;
}


Measured memory_bytes: 2560
def calc(A, B, C, X):
    result = 0
    for i in range(A + 1):
        for j in range(B + 1):
            res = X - 500 * i - 100 * j
            if res >= 0 and res / 50 <= C:
                result += 1

    return result


if __name__ == '__main__':
    A = int(input())  # 500 yen coin
    B = int(input())  # 100 yen coin
    C = int(input())  # 50 yen coin
    X = int(input())

    print(calc(A, B, C, X))


Measured memory_bytes: 2940
#include<stdio.h>
int Value[1001];
int Treasure[1000][2];
int max(int a, int b) {
  if (a >= b) return a;
  else return b;
}
int solve(int W) {
  int i, j;
  for (i = 0; i < 1000; i ++) {
    for (j = 1000; j >= Treasure[i][1]; j --) {
      Value[j] = max(Value[j - Treasure[i][1]] + Treasure[i][0], Value[j]);
    }
  }
  return Value[W];
}
int main() {
  int i, j, W, N, A;
  j = 0;
  while (1) {
    scanf("%d", &W);
    if (!W) break;
    printf("Case %d:\n", ++j);
    for (i = 0; i < 1001; i ++) Value[i] = 0;
    for (i = 0; i < 1000; i ++) {
      Treasure[i][0] = 0; Treasure[i][1] = 0;
    }
    scanf("%d", &N);
    for (i = 0; i < N; i ++) scanf("%d,%d", &Treasure[i][0], &Treasure[i][1]);
    A = solve(W);
    printf("%d\n", A);
    for (i = 0; Value[i] != A; i ++);
    printf("%d\n", i);
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define fast ios::sync_with_stdio(false), cout.tie(), cin.tie();
#define sz(s) int(s.size())

int main(){
	char c;
	cin >> c;
	cout << char(c + 1);
}


Measured memory_bytes: 256
#!/usr/bin/perl
my ($n,$m) = map {$_ - 0} split(/\s+/o,<STDIN>);
my @a = map {$_ - 0} split(/\s+/o,<STDIN>);
my %b = ('0'=>1);
my $tot = 0;
for(my $i=0;$i<=$#a;$i++){
  $tot = ( $tot + $a[$i] ) % $m;
  $b{'' . $tot} ++;
}
$tot=0;
foreach my $k ( keys %b ){
  my $v = $b{$k};
  if( $v >= 2 ){
    $tot += ( $v * ($v - 1) ) / 2;
  }
}
print "$tot\n";


Measured memory_bytes: 21612
//ABC148 A

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = s; i < (int)(n); i++)
const lint mod = 1000000007;


lint ans = 0;
lint a,b;
lint r,s,p;
string t;

int main() {
  cin >> a >> b;
  
  if(a != 1 && b != 1){
    ans = 1;
  }
  else if(a != 2 && b != 2){
    ans = 2;
  }
  else ans = 3;
  printf("%lld\n",ans);
}


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

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	ll n, a, b;
	cin >> n >> a >> b;
	if(a > b || (n == 1 && a != b)){
		cout << 0 << endl;
		return 0;
	}
	const ll minval = a * (n - 1) + b;
	const ll maxval = a + b * (n - 1);
	cout << (maxval - minval + 1) << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
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;}

int main() {
    ll a, b;
    cin >> a >> b;
    if (b % a == 0) cout << a + b << endl;
    else cout << b - a << endl;
}

Measured memory_bytes: 256
class SegT():
    def __init__(self, size):
        self.size = 1
        while self.size < size: self.size *= 2
        self.data = [0] * (self.size * 2 - 1)
    
    def update(self, i, x):
        i += (self.size - 1)
        self.data[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.data[i] = self.data[i*2+1] | self.data[i*2+2]
        
    def get(self, a, b, node=0, l=0, r=-1):
        if r < 0: r = self.size
        if r <= a or b <= l: return 0
        if a <= l and r <= b: return self.data[node]
        vl = self.get(a, b, node*2+1, l, (l+r)//2)
        vr = self.get(a, b, node*2+2, (l+r)//2, r)
        return vl | vr

N = int(input())
S = input()
Q = int(input())

segt = SegT(N)
for i in range(N):
    x = ord(S[i]) - ord('a')
    segt.update(i, (1<<x))

for i in range(Q):
    t, l, r = input().split()
    if t == "1":
        x = ord(r) - ord('a')
        segt.update(int(l)-1, (1<<x))
    else:
        x = segt.get(int(l)-1,int(r))
        ans = 0
        for i in range(26):
            if x>>i&1: ans += 1
        print(ans)


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

inline string toString(int a){
  stringstream ss;
  ss << a;
  return ss.str();
}

inline int toInt(string s){
  stringstream ss(s);
  int res;
  ss >> res;
  return res;
}

inline bool is_prime(int a){
  if(a<=1)return false;
  for(int i=2;i*i<=a;i++){
    if(a%i==0)return false;
  }
  return true;
}

int rec(int d, int n, string s, string c){
  if(n>4)return -1;
  if(d==n){
    string pal = s + c;
    reverse(s.begin(),s.end());
    pal += s;
    int p = toInt(pal);
    return is_prime(p)?p:-1;
  }

  int res = -1;
  for(int i=0;i<10;i++){
    if(d==0 && (i%2==0 || i%5==0))continue;
    res = max( res, rec(d+1, n, s + toString(i), c) );
  }
  return res;
}

int main(){
  int n,c;
  cin >> n >> c;
  string center = (c<0)?"":toString(c);
  int res = rec(0,n,"",center);

  if(res<0){
    for(int i=0;i<n;i++)cout << "9";
    cout << center;
    for(int i=0;i<n;i++)cout << "9";
    cout << endl;
  }else{
    cout << res << endl;
  }
}

Measured memory_bytes: 1232
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x!=y:
            if self.parents[x]>self.parents[y]:
                x,y=y,x

            self.parents[x]+=self.parents[y]
            self.parents[y]=x

    def same(self,x,y):
        return self.find(x)==self.find(y)

n,q=map(int,input().split())
UF=UnionFind(n)
for i in range(q):
    com,x,y=map(int,input().split())
    if com==0:
        UF.unite(x,y)
    elif com==1:
        if UF.same(x,y):
            print(1)
        else:
            print(0)



Measured memory_bytes: 5720
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  long long n,p[110];
  cin>>n;
  for(int i=0;i<n;i++) cin>>p[i];
  sort(p,p +n);
  cout<<abs(p[0]-p[n-1])<<'\n';
  return 0;
}

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

void ans(bool b) {
    cout << (b ? "Possible" : "Impossible") << endl;
    exit(0);
}

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> a(N);
    for (int64_t& A : a) {
        cin >> A;
    }

    int64_t one_num = count(a.begin(), a.end(), 1);
    if (one_num == 1) {
        //1のものが中心のスターグラフじゃないとダメ
        //1以外のものは全て2じゃないとおかしい
        //逆にそうであれば構築可能
        int64_t two_num = count(a.begin(), a.end(), 2);
        ans(two_num == N - 1);
    } else if (one_num >= 2) {
        ans(N == 2);
    }

    int64_t max_value = *max_element(a.begin(), a.end());
    int64_t max_num = count(a.begin(), a.end(), max_value);

    if (max_num == 1) {
        ans(false);
    }

    //maxを両端にして一列に並べるようなものを考える
    int64_t min_value;

    if (max_value % 2 == 0) {
        min_value = max_value / 2;

        //min_valueは1個でないといけない
        int64_t min_num = count(a.begin(), a.end(), min_value);
        if (min_num != 1) {
            ans(false);
        }
    } else {
        min_value = max_value / 2 + 1;

        //min_valueは2個でないといけない
        int64_t min_num = count(a.begin(), a.end(), min_value);
        if (min_num != 2) {
            ans(false);
        }
    }

    //min_value未満のものがあったらダメ
    int64_t ng_num = count_if(a.begin(), a.end(), [min_value](int64_t v) { return v < min_value; });
    if (ng_num > 0) {
        ans(false);
    }

    for (int64_t i = min_value + 1; i <= max_value; i++) {
        int64_t num = count(a.begin(), a.end(), i);
        if (num <= 1) {
            ans(false);
        }
    }

    ans(true);
}

Measured memory_bytes: 3544
#include <stdio.h>

int main(void)
{
  int a, b, sum, i;

  while(scanf("%d %d", &a, &b) != EOF){
    sum = a + b;
    for(i = 0; sum != 0; i++){
      sum /= 10;
    }
    printf("%d\n", i);
  }

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <vector>
#include <cmath>
#include <cstdint>
#include <string>
#include <climits>
#include <queue>

using namespace std;

struct Node {
  Node* prev;
  Node* next;
  int value;
  Node(Node* prev, Node* next, int value) : prev(prev), next(next), value(value) {}
};

class List {
  Node* begin = new Node(nullptr, nullptr, -1);
  Node* end = new Node(nullptr, nullptr, -1);
public:
  List() {
    begin->next = end;
    end->prev = begin;
  }

  void insert(int value) {
    auto next = begin->next;
    auto n = new Node(begin, next, value);
    next->prev = n;
    begin->next = n;
  }
  void deleteNode(int value) {
    auto node = begin;
    for (node = begin->next; node != end; node = node->next) {
      if (node->value == value) {
        node->prev->next = node->next;
        node->next->prev = node->prev;
        return;
      }
    }
  }
  void deleteFirst() {
    auto old = begin->next;
    auto next = old->next;
    begin->next = next;
    next->prev = begin;
    delete old;
  }
  void deleteLast() {
    auto old = end->prev;
    auto prev = old->prev;
    prev->next = end;
    end->prev = prev;
    delete old;
  }

  void print() {
    for (auto node = begin->next; node != end; node = node->next) {
      cout << node->value;
      if (node != end->prev) {
        cout << " ";
      }
    }
    cout << endl;
  }
};

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

  int n;
  cin >> n;
  List list;
  for (int i = 0; i < n; ++i) {
    string command;
    cin >> command;
    if (command == "deleteFirst") {
      list.deleteFirst();
    } else if (command == "deleteLast") {
      list.deleteLast();
    } else if (command == "insert") {
      int value;
      cin >> value;
      list.insert(value);
    } else if (command == "delete") {
      int value;
      cin >> value;
      list.deleteNode(value);
    }
  }
  list.print();
}



Measured memory_bytes: 34436