akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define num(a) a-'0'
#define maxself(a,b) if(b>a)a=b
#define minself(a,b) if(b<a)a=b;
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"	
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int n;
	cin>>n;
	vi a(n);
	set<int> s;
	rep(i,0,n){
		cin>>a[i];
		if(s.find(a[i])==s.end()){
			s.insert(a[i]);
		}
		else{
			cout<<"NO\n";
			return;
		}
	}
	cout<<"YES\n";
}

int main(){
	boost_io;
	solve();
	return 0;
}

Measured memory_bytes: 13496
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <unordered_map>
#include <list>
#include <unordered_set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#define INFI 987654321
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
ll cache[100005], M = 1000000007;
ll factorial(ll num)
{
    if(num == 1)
        return 1;
    if(!cache[num])
        cache[num] = (num * factorial(num - 1)) % M;
    return cache[num];
}
int main() {
    ios_base::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    if(b > a)
        swap(a, b);
    if(a - b > 1)
        cout << "0";
    else if(a - b == 1)
        cout << (factorial(a) * factorial(b)) % M;
    else
        cout << ((factorial(a) * factorial(b)) % M * 2) % M;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  if(n==1) {
    cout << "Hello World" << endl;
  } else {
    int a,b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace ABC_practice
{
    public class Program
    {

        #region templete

        private static void WL(string s) { WriteLine(s); }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        static long Gcd(long a, long b)
        {
            var v = new[] { a, b };
            while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
            return v[0];
        }
        /// <summary>
        /// 最小公約数
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }

        public static void Main(string[] args)
        {
            new Program().Solve();
            ReadLine();
        }

        #endregion

        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var m = cin.nextInt();
            var k = new int[n];
            var a = new int[n][];
            for (int i = 0; i < n; i++)
            {
                k[i] = cin.nextInt();
                a[i] = cin.ArrayInt(k[i]);
            }
            var ans = 0;
            for (int i = 0; i <= m; i++)
            {
                var cnt = 0;
                foreach (var item in a)
                {
                    if (item.Contains(i)) cnt++;
                }
                if (cnt == n) ans++;
            }
            WL($"{ans}");
        }

    }
}


#region console in

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

#endregion

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

template<class T>bool chmax(T &a,const T &b){
    if(a>b)return false;
    a=b;
    return true;
}
template<class T>bool chmin(T &a,const T &b){
    if(a<b)return false;
    a=b;
    return true;
}

const ll mod=1e9+7;
const ll inf=1ll<<60;

/*---------------------*/

struct Edge{ll from,to,cost;};

int l;
vector<Edge>v;

int main(){
    cin>>l;
    int n=0;
    while(l>>n)n++;
    FOR(i,1,n){
        v.push_back({i,i+1,0});
        v.push_back({i,i+1,1<<(i-1)});
    }
    for(int i=n-1;i>=1;i--)if((l>>i-1)&1){
        v.push_back({i,n,l-(1<<i-1)});
        l-=(1<<i-1);
    }
    cout<<n<<" "<<v.size()<<endl;
    rep(i,v.size()){
        cout<<v[i].from<<" "<<v[i].to<<" "<<v[i].cost<<endl;
    }
}

Measured memory_bytes: 256
# include "stdio.h"

int main(){
    int k,x;
    scanf("%d %d",&k,&x);
    for(int i=k-1;i>=1;i--)
        printf("%d ",x-i);
    printf("%d ",x);
    for(int i=1;i<k;i++)
        printf("%d ",x+i);
    printf("\n");
  
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			long []T = new long[N];
			for(int i = 0;i<N;i++)T[i] = scan.nextLong();
			long g = T[0];
			long l = T[0];
			for(int i = 1;i<N;i++) {
				g = lcm(g,T[i]);
				
			}
			
			System.out.println(g);

			
		}
		
		
	}
	
	
	private static long gcd(long A,long B){//最大公約数
		return B==0?A:gcd (B,A%B);
	}
	
	private  static long lcm(long A,long B) {//最小公倍数
		return A/gcd(A,B)*B;
	}
		

}


Measured memory_bytes: 23764
using System;

namespace test2 {

    public class Program {

        public static void Main(string[] args) {

            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            if(n % 2 == 0) {

                var s1 = s.Substring(0, n / 2);
                var s2 = s.Substring(n / 2, n / 2);

                if(s1 == s2) {

                  Console.WriteLine("Yes");
                  return;

                }

            }

            Console.WriteLine("No");

        }

    }

}

Measured memory_bytes: 27320
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>P;//Pre val
#define fi first
#define se second

const int SIZE=16777216;
int dat[SIZE*2-1];
const int INF=LLONG_MAX/100;
void update(int k,int x){
    k+=SIZE-1;
    dat[k]=x;
    while(k){
        k=(k-1)/2;
        dat[k]=max(dat[k*2+1],dat[k*2+2]);
    }
}

int getMax(int a,int b,int k=0,int l=0,int r=SIZE){
    if(a<=l&&b>=r)return dat[k];
    if(r<=a||b<=l)return -INF;

    int m=(l+r)/2;
    int vl=getMax(a,b,k*2+1,l,m);
    int vr=getMax(a,b,k*2+2,m,r);
    return max(vl,vr);
}

int N,D;
int X[30],Y[30];

vector<P>A,B;
void Latte(int cur,int last,int val,int pre,bool after){
    if(cur==last){
        if(after)B.push_back(P(pre,val));
        else A.push_back(P(pre,val));
        return;
    }

    Latte(cur+1,last,val+X[cur],pre+Y[cur],after);
    Latte(cur+1,last,val-X[cur],pre-Y[cur],after);
    Latte(cur+1,last,val,pre,after);
}


signed main(){
    cin>>N>>D;
    for(int i=0;i<N;i++)cin>>Y[i]>>X[i];

    Latte(0,N/2,0,0,false);
    Latte(N/2,N,0,0,true);

    sort(A.rbegin(),A.rend());
    sort(B.begin(),B.end());
    fill_n(dat,SIZE*2-1,-INF);
    for(int i=0;i<B.size();i++){
        update(i,B[i].second);
    }

    int ans=-INF;
    int lb=0,ub=0;
    for(int i=0;i<A.size();i++){
        while(lb<B.size()&&-D-A[i].fi>B[lb].fi)lb++;
        while(ub<B.size()&&D-A[i].fi>=B[ub].fi)ub++;
        ans=max(ans,A[i].se+getMax(lb,ub));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 714620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll md = 1000000007;

ll fact_mod(ll n){
  if(n==0) return 1;
  ll res = 1;
  while(n>0){
    res *= n--;
    res %= md;
  }
  return res;
}
    

int main(){
  int n,m;
  cin >> n >> m;
  
  ll ans;
  
  if(abs(n-m) > 1){
    cout << 0 << endl;
    return 0;
  }
  
  ans = fact_mod(n) * fact_mod(m);
  ans %= md;
  
  if(n==m){
    ans *= 2;
    ans %= md;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	int a,b,c;
	cin>>a>>b>>c;
	a=abs(a);
	a-=(b%2)*c; b=b/2; c*=2; a=abs(a);
	if (a/c>=b)  cout<<a-c*b;
	else  cout<<min( a%c , c-a%c );
	re 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;
	import java.util.ArrayList;
	import java.util.Arrays;
	public class Main {
		static Scanner scn = new Scanner(System.in);
		public static void main(String[] args) {
			// TODO Auto-generated method stub
			long n=scn.nextLong();
				System.out.println(n*(n-1)/2);
			
		}
	
	}


Measured memory_bytes: 23124
#include <math.h>
#include <iostream>
using namespace std;
int main() {
  int ene;
  while( cin >> ene && ene>0){
    int min = 1000000;
    for( int z=0; z<=100; z++) {
      int xy = ene - z*z*z;
      if( xy >= 0)
	for( int y=0; y<=10000; y++) {
	  int x = xy - y*y;
	  if( x>=0)
	    if( x+y+z<min) min = x+y+z;
	}
    }
    cout << min << endl;
  }
}
	

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>


typedef long long ll;
typedef long double ld;

using namespace std;


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




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int a[10000], b[10000];
  char op[10000];
  int counter =	10000;
  for (int i=0; i <= 10000; i++) {
    cin >> a[i] >> op[i] >> b[i];
    if (op[i] == '?') {
      counter =	i;
      break;
    }
  }
  for(int i=0; i <= counter; i++) {
    switch (op[i]) {
    case '+':
      cout << a[i]+b[i] << endl;
      break;
    case '-':
      cout << a[i]-b[i] << endl;
      break;
    case '*':
      cout << a[i]*b[i] << endl;
      break;
    case '/':
      cout << a[i]/b[i] << endl;
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <bitset>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
using ppp = pair<pair<int, int>, pair<int, int>>;
#define MOD 1000000007
#define INF 1LL << 59
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int S[200010], T[200010], X[200010];

int D[200010];

ll getval(ll b, ll n)
{
    if (n < b)
        return n;

    ll res = 0;
    res = getval(b, floor(n / b)) + n % b;

    return res;
}
int main()
{
    ll n, s;
    cin >> n >> s;

    if (n < s)
    {
        cout << -1 << endl;
        return 0;
    }
    if (n == s)
    {
        cout << n + 1 << endl;
        return 0;
    }

    ll t = n - s;

    set<ll> st;

    for (ll i = 1; i * i <= t; ++i)
    {
        if (t % i == 0)
        {
            st.insert(i);
            st.insert(t / i);
        }
    }

    for (auto e : st)
    {
        ll b = e + 1;
        if (getval(b, n) == s)
        {
            cout << b << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    struct Pair {
        public int P { get; set; }
        public int Y { get; set; }
    }

    public void Solve() {
        var N = sc.nextInt();
        var M = sc.nextInt();
        var pair = new Pair[M];
        for (int i = 0; i < M; i++) {
            pair[i] = new Pair {
                P = sc.nextInt(),
                Y = sc.nextInt()
            };
        }

        var dic = new Dictionary<int, List<int>>();
        for (int i = 0; i < M; i++) {
            if (!dic.ContainsKey(pair[i].P)) {
                dic.Add(pair[i].P, new List<int>());
            }
            dic[pair[i].P].Add(pair[i].Y);
        }

        var ans = new Dictionary<string, string>();
        foreach (var kvp in dic) {
            var tmp = kvp.Value.OrderBy(val => val).ToList();
            for (int i = 0; i < tmp.Count; i++) {
                ans.Add(kvp.Key.ToString().PadLeft(6, '0') + tmp[i].ToString().PadLeft(6, '0'), (i + 1).ToString().PadLeft(6, '0'));
            }
        }

        for (int i = 0; i < M; i++) {
            WriteLine(pair[i].P.ToString().PadLeft(6, '0') + ans[pair[i].P.ToString().PadLeft(6, '0') + pair[i].Y.ToString().PadLeft(6, '0')]);
        }

    }
}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 49164
#import sys

#input = sys.stdin.readline

#import heapq
import math
#import fractions

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True

def main():
#    h,w,a,b = map(int, input().split())
    a,b=map(int,input().split())
    m=4
    k=1
    count=0

    if a>b:
        a,b=b,a
    sosu={1}
#    a = fractions.gcd(a,b)
    if a%2==0:
        sosu.add(2)
        while a%2==0:
            a//=2
    if a%3==0:
        sosu.add(3)
        while a%3==0:
            a//=3
#    print(d)
    c=math.sqrt(a)+1
 #   print(c)
    while m<=c and m!=1:
        if a%m==0:
            sosu.add(m)
            while a%m==0:
                a//=m

        m+=1
#    print(sosu)
    if a!=1:
        sosu.add(a)
#    print(sosu)

    for i in sosu:
        if b%i==0:
            count+=1
    print(count)
#    for i in range(h):
#            print(aaa)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
n=int(input())
a=list(map(int, input().split()))
c1, c2 = 0, 0
s = 0
for i in range(len(a)):
    S = s+a[i]
    if i%2 == 0:
        if S > 0:
            s = S
        else:
            c1 += abs(S)+1
            s = 1
    else:
        if S < 0:
            s = S
        else:
            c1 += abs(S)+1
            s = -1
s=0
for i in range(len(a)):
    S = s+a[i]
    if i%2 != 0:
        if S > 0:
            s = S
        else:
            c2 += abs(S)+1
            s = 1
    else:
        if S < 0:
            s = S
        else:
            c2 += abs(S)+1
            s = -1
print(min(c1, c2))


Measured memory_bytes: 63216
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
    string S;
    cin >> S;
    
    bool flag = false;
    if(S[0]==S[1]){
      if(S[2]==S[3] && S[0]!=S[2]){
        flag = true;
      } 
    }else if(S[0]==S[2]){
      if(S[1]==S[3] && S[0]!=S[1]){
        flag = true;
      } 
    }else if(S[0]==S[3]){
      if(S[1]==S[2] && S[0]!=S[1]){
        flag = true;
      } 
    }

    if(flag) cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e5+5,LG=19,SM=600+5,inf=1e18+1;
ll mod=1e9+7;

ll par[M];
vll ch[M];
ll n;

ll dfs(ll x)
{
    //ER(x);
    vll s;
    ll res=0;
    for (ll y:ch[x])
    {
        s.PB(dfs(y));
    }
    sort(s.begin(),s.end());
    For(i,0,SZ(s))
    {
        //ER(i);ER(s[i]);
        smax(res,SZ(s)-i+s[i]);
    }
    //ER(res);ER(x);
    return res;
}

int main()
{
	ios::sync_with_stdio(0);
    cin >> n;
    For(i,1,n)
    {
        cin >> par[i];
        par[i]--;
        ch[par[i]].PB(i);
    }
    RET(dfs(0));
}    

Measured memory_bytes: 17280
#include <iostream>

int main() {
  int W, a, b;
  std::cin >> W >> a >> b;

  int d = 0;
  if ( a < b ) {
    if ( a + W < b )
      d = b - (a + W);
  } else if ( a > b ) {
    if ( a + W > b )
      d = a - (b + W);
  }
  std::cout << d << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    
    public static void main(String [] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int capacity = sc.nextInt();
        int[] weight = new int[n];
        int[] value = new int[n];

        for(int ind = 0; ind < n; ind++) {
            weight[ind] = sc.nextInt();
            value[ind] = sc.nextInt();
        }

        long[][] dp = new long[n + 1][capacity + 1];

        for(int row = 1; row <= n; row++) {

            for(int col = 1; col <= capacity; col++) {

                long maxValue = dp[row - 1][col];
                if(col - weight[row - 1] >= 0) {
                    maxValue = Math.max(maxValue, dp[row - 1][col - weight[row - 1]] + value[row - 1]);
                }
                dp[row][col] = maxValue;
            }
        }

        System.out.println(dp[n][capacity]);
    }
}


Measured memory_bytes: 138100
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		System.out.println(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ? "Possible" : "Impossible");
	}
}


Measured memory_bytes: 35464
#include <stdio.h>
#include <stdlib.h>

int main () {
    int N;
    scanf("%d", &N);
    for (int i = 1; i <= 9; i++) {
        if ((N / i) <= 9 && N % i == 0){
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");

    return 0;
}


Measured memory_bytes: 128
# C
if __name__=='__main__':
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    k = N-1
    x = 0
    for i in range(1,N):
        if A[i]>0:
            k = i
            break
    M = sum(A[k:])-sum(A[:k])
    print(M)
    x = A[k-1]
    for i in range(k,N-1):
        print('{} {}'.format(x,A[i]))
        x = x - A[i]
    print('{} {}'.format(A[N-1],x))
    x = A[N-1] - x
    for i in range(k-1):
        print('{} {}'.format(x,A[i]))
        x = x -A[i]

Measured memory_bytes: 14264
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
const long long MOD = 10e9 + 7;
typedef long long ll;

int main(){
	int H, W;
	cin >> H >> W;
	vector<vector<char>> pic(H, vector<char>(W));
	rep(i, H){
		rep(j, W){
			cin >> pic.at(i).at(j);
		}
	}
	rep(i, W + 2) cout << '#';
	cout << endl;
	rep(i, H){
		rep(j, W){
			if(j == 0){
				cout << '#';
			}
			cout << pic.at(i).at(j);
			if(j == W - 1){
				cout << '#' << endl;
			}
		}
	}
	rep(i, W + 2) cout << '#';
	cout << endl;
}

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

# 再帰で全探索, sは文字列とすると便利
def dfs( s ):
    # 現在の数字が N を越えたら終わり
    if int( s ) > N: return 0
    # s が七五三数なら +1, 他なら 0
    ans = 1 if all( s.count(c) > 0 for c in '753' ) else 0 
    # 最後尾に3,5,7を加えて新たな七五三数を作る
    for c in '753':
         ans += dfs(s + c)
    return ans

print( dfs('0') )

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

int main()
{
    long long int n,m,p,i,j;
    cin>>n>>m>>p;
    vector<long long int> v[n+1];
    vector<pair<long long int,pair<long long int,long long int> > > edges;

    for(i=0;i<m;i++)
    {
        long long int a,b,c;
        cin>>a>>b>>c;
        edges.push_back(make_pair(c-p,make_pair(a,b)));
        v[b].push_back(a);
    }

    long long int vis[n+1]={0};
    vis[n]=1;
    queue<long long int> q;
    q.push(n);
    while(!q.empty())
    {
        long long int top=q.front();
        q.pop();
        long long int si=v[top].size();
        for(i=0;i<si;i++)
        {
            if(vis[v[top][i]]==0)
            {
                q.push(v[top][i]);
                vis[v[top][i]]=1;
            }
        }
    }

    long long int dist[n+1];
    for(i=0;i<=n;i++)
        dist[i]=-1e14;

    dist[1]=0;

    for(i=0;i<n-1;i++)
    {
        for(j=0;j<m;j++)
        {
            if(dist[edges[j].second.first]==-1e14)
                continue;
            if(dist[edges[j].second.second]<dist[edges[j].second.first]+edges[j].first)
            {
                dist[edges[j].second.second]=dist[edges[j].second.first]+edges[j].first;
            }
        }
    }

    for(j=0;j<m;j++)
    {
        if(dist[edges[j].second.first]==-1e14)
            continue;
        if(dist[edges[j].second.second]<dist[edges[j].second.first]+edges[j].first&&vis[edges[j].second.second]==1)
        {
            cout<<-1;
            return 0;
            //dist[edges[j].second.second=dist[edges[j].second.first]+edges[j].first;
        }
    }

    cout<<max((long long int)0,dist[n]);
}


Measured memory_bytes: 768
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc090_a.cpp
 * time   : Thu Apr 30 18:09:28 2020
 * quest  : A - Diagonal String
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[1] << c[2] << "\n";
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum long mod = 10^^9 + 7;

void main() {
    int h, w, k;
    scan(h, w, k);
    k--;

    if (w == 1) {
        writeln(1);
        return;
    }

    auto m = new long[][](w, w);

    foreach (s ; 0 .. 1<<(w-1)) {
        auto a = iota(w).array;

        if (isCont(s)) {
            continue;
        }

        foreach (i ; 0 .. w - 1) {
            if (s & (1 << i)) {
                swap(a[i], a[i+1]);
            }
        }

        debug {
            writeln(a);
        }

        foreach (i ; 0 .. w) {
            foreach (j ; 0 .. w) {
                if (a[j] == i) {
                    m[i][j]++;
                }
            }
        }
    }

    debug {
        writefln("%(%(%s %)\n%)", m);
    }

    auto dp = new long[][](h + 1, w);
    dp[0][0] = 1;

    foreach (i ; 0 .. h) {
        foreach (j ; 0 .. w) {
            foreach (l ; 0 .. w) {
                dp[i+1][l] += m[j][l] * dp[i][j] % mod;
                dp[i+1][l] %= mod;
            }
        }
    }

    debug {
        writeln("dp");
        writefln("%(%(%s %)\n%)", dp);
    }

    long ans = dp[h][k];
    writeln(ans);
}


bool isCont(int x) {
    int p = 0;

    while (x > 0) {
        if (p == 0) {
            p = x & 1;
            x >>= 1;
        }
        else {
            if (x & 1) {
                return true;
            }
            p = 0;
            x >>= 1;
        }
    }

    return false;
}


unittest {
    //writeln(0b101);
    assert(isCont(0b101) == false);
    assert(isCont(0b0) == false);
    assert(isCont(0b011) == true);
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
A,B,C,X,Y = map(int,input().split())
ans = 0
if (A+B) >= (2*C):
    if (2*C) >= max(A,B):
        c = min(X,Y)
        ans += 2*C*c
        if c==X:
            d = Y - c
            ans += B*d
        else:
            d = X - c
            ans += A*d
    elif (2*C) < A and (2*C) < B:
        ans += 2*C*max(X,Y)
    elif (2*C) > min(A,B):
        c = min(A,B)
        if c==A:
            if X<=Y:
                ans += Y*2*C
            else:
                d = X - Y
                ans += Y*2*C
                ans += d*A
        else:
            if X>=Y:
                ans += 2*C*X
            else:
                d = Y - X
                ans += 2*C*X
                ans += B*d 

else:
    ans += A*X
    ans += B*Y

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
const double INF = 1e17;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> g[n];
  rep(i,m) {
    int s, t;
    cin >> s >> t;
    s--; t--;
    g[s].push_back(t);
  }
  double ans = INF;
  rep(i,n-1) {
    vector<double> dp(n,0);
    for(int j = n-2; j >= 0; j--) {
      if(g[j].size() == 1) {
        dp[j] = dp[g[j][0]] + 1.0;
      } else {
        double q = 0.0, m = 0.0;
        for(auto k : g[j]) {
          q += dp[k];
          if(m < dp[k]) m = dp[k];
        }
        if(j == i) dp[j] = 1.0 + (q-m)/(double)(g[j].size()-1);
        else dp[j] = 1.0 + q/(double)g[j].size();
      }
    }
    if(ans > dp[0]) ans = dp[0];
  }
  printf("%.9lf\n",ans);
  return 0;
}

Measured memory_bytes: 1408
def binom(n, r, mod):
    if n < r or n < 0 or r < 0: return 0
    
    if n - r < r: r = n - r
    if r == 0: return 1
    elif r == 1: return n

    numerator = [(n - r + 1 + k) % mod for k in range(r)]  # (n-r+1)*(n-r+2)*...*(n-1)*n
    denominator = [1 + k for k in range(r)]         # 1*2*...*(r-1)*r

    X = 1; Y = 1
    for k in range(r):
        X = (X * ((n - r + 1 + k) % mod)) % mod
        Y = (Y * ((1 + k) % mod)) % mod
    return X * pow(Y, mod-2, mod)

MOD = 10**9 + 7
n, a, b = map(int, input().split())
ans = (pow(2, n, MOD) - 1 - ((binom(n, a, MOD) + binom(n, b, MOD)) % MOD)) % MOD
print(ans)

Measured memory_bytes: 19252
n, m, k = map(int, input().split())
MOD = 998244353


class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod

        self.f = self._get_f()
        self.fi = self._get_fi()

    def __call__(self, k):
        if not 0 <= k <= self.n:
            return 0
        else:
            num = self.f[self.n]
            deninv = (self.fi[k] * self.fi[self.n - k]) % self.mod
            return (num * deninv) % self.mod

    def _get_f(self):
        f = 1
        lf = [1]

        for i in range(1, self.n + 1):
            f = (f * i) % self.mod
            lf.append(f)

        return lf

    def _get_fi(self):
        ii = 1
        lii = [0, 1]  # [i^-1 modulo mod for i in 0, ..., n]
        fi = 1
        lfi = [1, 1]

        for i in range(2, self.n + 1):
            ii = (-lii[self.mod % i] * (self.mod // i)) % self.mod
            lii.append(ii)

            fi = (fi * ii) % self.mod
            lfi.append(fi)

        return lfi


c = Combination(n - 1, MOD)


def n_pattern(i):
    result = m
    result *= c(i)
    result %= MOD
    result *= pow(m - 1, n - i - 1, MOD)
    result %= MOD
    return result


answer = sum(n_pattern(i) for i in range(k + 1)) % MOD
print(answer)


Measured memory_bytes: 32624
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var P = "rsp"

func up(d []int, t byte, points []int) {
	if t == P[1] {
		d[0] += points[0]
	}
	if t == P[2] {
		d[1] += points[1]
	}
	if t == P[0] {
		d[2] += points[2]
	}
}
func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	points := sc.NextIntArray()
	T := sc.NextLine()

	score := 0
	isPassed := make([]bool, N)
	for i := 0; i < N; i++ {
		if i >= K {
			if !isPassed[i-K] {
				if T[i] == T[i-K] {
					isPassed[i] = true
					continue
				}
			}
		}
		for k := 0; k < 3; k++ {
			if T[i] == P[(k+1)%3] {
				score += points[k]
			}
		}
		//fmt.Println(i, score)
	}
	fmt.Println(score)

}
func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main(){
    int n;
    scanf("%d", &n);
    std::vector<int> a(n);
    for(int i=0; i<n; i++){
        int tmp;
        scanf("%d", &tmp);
        a[tmp]++;
    }

    int ans = 1;
    for(int i=1; i<n; i++){
        if(n%2==i%2){
            if(a[i]) ans = 0;
        }else if(a[i]==2){
            ans *= 2;
            ans %= 1000000007;
        }else ans = 0;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 640
MOD = 10 ** 9 + 7
n = gets.to_s.to_i
a = gets.to_s.split.map { |v| v.to_i }
cnt = Array.new(60, 0)

a.each do |v|
  60.times do |i|
    cnt[i] += 1 if v[i] == 1
  end
end

ans = 0
cnt.each_with_index do |v, i|
  ans += v * (n - v) * 2 ** i
  ans %= MOD
end
puts ans


Measured memory_bytes: 37116
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  if (A>=K){
  cout << K;
  }
  else if (A+B>=K){
  cout << A;
  }
  else{
  cout << A-(K-A-B);
  }
}

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

int main() {
  int64_t N, K;
  cin >> N >> K;
  
  vector<vector <int64_t>> v (2005, vector<int64_t> (2005, 0));
  for (int i = 0; i < 2005; i++) {
    for (int j = 0; j < 2005; j++) {
      if ((j == 0) || (j == i + 1)) {
        v.at(i).at(j) = 1;
      } else if (0 < i && 0 < j && j < i + 1) {
        v.at(i).at(j) = (v.at(i - 1).at(j - 1) + v.at(i - 1).at(j)) % 1000000007;
      }
    }
  }
  
  int64_t M = 1000000007;
  if (0 < K) {
    cout << (N - K + 1) % M << endl;
  }
  if (1 < K) {
    cout << ((N - K + 1) * (N - K) / 2 * (K - 1)) % M << endl;
  }
  if (2 < K) {  
    int64_t ans = 0;  
    for (int i = 3; i < K + 1; i++) {
      ans = v.at(N - K + 1 - 1).at(i) * v.at(K - 1 - 1).at(i - 1);
      cout << ans % 1000000007 << endl;
    }
  }
}

Measured memory_bytes: 31744
#include <vector>
#include <iostream>
#include <algorithm>
#include <limits>
#include <string>
#include <stack>

#define INT_MAX 2147483647
#define INT_MIN -2147483647
using namespace std;


void print(vector<pair<char, int> > &data)
{
	for (int i = 0; i < data.size() - 1; ++i)
		cout << data[i].first << data[i].second << " ";

	cout << data.back().first << data.back().second << endl;
}


int main()
{
	string str;
	stack<int> s;
	while (cin >> str)
	{
		char c = str[0];
		if (c != '+' && c != '-' && c != '*' && c != '/')
		{
			s.push(stoi(str));
			continue;
		}
		int v1, v2;
		v2 = s.top(); s.pop();
		v1 = s.top(); s.pop();

		switch (c)
		{
		case '+': v1 += v2; break;
		case '-': v1 -= v2;	break; 
		case '*': v1 *= v2;	break;
		case '/': v1 /= v2;	break;
		}
		s.push(v1);
	}
	cout << s.top() << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  if(N/10%111==0) {
    cout << "Yes" ;
  }
  
  else if((N-1000)%111==0 && N-1000 < 1000) {
    cout << "Yes" ;
  }
  else if((N-2000)%111==0 && N-2000 < 1000) {
    cout << "Yes" ;
  }
  else if((N-3000)%111==0 && N-3000 < 1000) {
    cout << "Yes" ;
  }
  else if((N-4000)%111==0 && N-4000 < 1000) {
    cout << "Yes" ;
  }
  else if((N-5000)%111==0 && N-5000 < 1000) {
    cout << "Yes" ;
  }
  else if((N-6000)%111==0 && N-6000 < 1000) {
    cout << "Yes" ;
  }
  else if((N-7000)%111==0 && N-7000 < 1000) {
    cout << "Yes" ;
  }
  else if((N-8000)%111==0 && N-8000 < 1000) {
    cout << "Yes" ;
  }
  else if((N-9000)%111==0 && N-9000 < 1000) {
    cout << "Yes" ;
  }
  
  else {
    cout << "No" ;
  }
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    int x[5], t;

    for(int i=0; i<5; i++)
    {
        cin>> x[i];
        if(x[i]== 0)
            t=i+1;
    }

    cout<< t<< endl;



    return 0;
}





Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int h, w, sx, sy, ex, ey;
	cin >> h >> w >> sx >> sy >> ex >> ey;
	sx--, sy--, ex--, ey--;
	vector<string> g(h);
	for (int i = 0; i < h; i++) cin >> g[i];
	
	vector<vector<int>> ans(h, vector<int>(w, 1e9));
	ans[sx][sy] = 0;
	queue<vector<int>> q;
	q.push({sx, sy});
//	int a{1};
	while (!q.empty()) {
		vector<int> cur = q.front();
//		cout << a++ << endl;
//		cout << cur[0] << " " << cur[1] << endl;
		q.pop();
//		for (int i = cur[0] - 1; i <= cur[0] + 1; i++) {
//			for (int j = cur[1] - 1; j <= cur[1] + 1; j++) {
//				if (i < 0 || j < 0 || i >= h || j >= w || (abs(cur[0] - i) + abs(cur[1] - j) != 1)) continue;
//				if (g[i][j] != '#' && ans[i][j] > ans[cur[0]][cur[1]]) {
//					ans[i][j] = ans[cur[0]][cur[1]];
//					q.push({i, j});
//				}
//			}
//		}
		int x{cur[0] - 1}, y{cur[1]};
		while (x >= 0 && g[x][y] != '#' && ans[x][y] > ans[cur[0]][cur[1]]) {
			ans[x][y] = ans[cur[0]][cur[1]];
			q.push({x--, y});
		}
		x = cur[0] + 1;
		while (x < h && g[x][y] != '#' && ans[x][y] > ans[cur[0]][cur[1]]) {
			ans[x][y] = ans[cur[0]][cur[1]];
			q.push({x++, y});
		}
		x = cur[0], y = cur[1] - 1;
		while (y >= 0 && g[x][y] != '#' && ans[x][y] > ans[cur[0]][cur[1]]) {
			ans[x][y] = ans[cur[0]][cur[1]];
			q.push({x, y--});
		}
		y = cur[1] + 1;
		while (y < w && g[x][y] != '#' && ans[x][y] > ans[cur[0]][cur[1]]) {
			ans[x][y] = ans[cur[0]][cur[1]];
			q.push({x, y++});
		}
		for (int i = cur[0] - 2; i <= cur[0] + 2; i++) {
			for (int j = cur[1] - 2; j <= cur[1] + 2; j++) {
				if (i < 0 || j < 0 || i >= h || j >= w) continue;
				if (g[i][j] != '#' && ans[i][j] > ans[cur[0]][cur[1]] + 1) {
					q.push({i, j});
					ans[i][j] = ans[cur[0]][cur[1]] + 1;
				}
			}
		}
	}
	cout << (ans[ex][ey] == 1e9 ? -1 : ans[ex][ey]);
}

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

using namespace std;
using ll = long long int;

int main(void) {
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n;
    cin >> n;
    vector<ll> a(n);
    for(auto &e: a) cin >> e;

    ll r = 0;
    map<ll,ll> cnt;
    for(ll i=0; i<n; i++) {
        r += cnt[i-a[i]];
        cnt[a[i]+i]++;
    }
    cout <<r << endl;
}


Measured memory_bytes: 27308
class Acc2D:
    def __init__(self, a):
        h, w = len(a), len(a[0])
        self.acc2D = self._build(h, w, a)

    def _build(self, h, w, a):
        ret = [[0] * (w + 1) for _ in range(h + 1)]
        for r in range(h):
            for c in range(w):
                ret[r + 1][c + 1] = ret[r][c + 1] + ret[r + 1][c] - ret[r][c] + a[r][c]
                # 末項は必要に応じて改変すること
        return ret

    def get(self, r1, r2, c1, c2):
        # [r1,r2), [c1,c2) : 0-indexed
        acc2D = self.acc2D
        return acc2D[r2][c2] - acc2D[r1][c2] - acc2D[r2][c1] + acc2D[r1][c1]


def main():
    import sys

    input = sys.stdin.readline

    n, k = map(int, input().split())

    g = [[0] * (k * 2) for _ in range(k * 2)]
    for _ in range(n):
        x, y, c_ = input().split()
        x = int(x) % (k * 2)
        y = int(y) % (k * 2)
        if c_ == 'W':
            y = (y + k) % (k * 2)
            # すべて黒にする
        g[y][x] += 1  # WA頂点の存在の有無ではなく、頂点数を数えるので、=1ではなく、+=1

    acc2D = Acc2D(g)

    ret = 0
    # 中央にk*kの区画をとり、黒または白に塗る(条件を満たす個数:黒=s,白=n-s)
    # 4辺を伸ばして、2k*2kの区画を分割し、各区画を評価する
    for r in range(k):  # r+k < k*2
        for c in range(k):  # c+k < k*2
            s = (
                    acc2D.get(0, r, 0, c)
                    + acc2D.get(0, r, c + k, k * 2)
                    + acc2D.get(r, r + k, c, c + k)
                    + acc2D.get(r + k, k * 2, 0, c)
                    + acc2D.get(r + k, k * 2, c + k, k * 2)
            )
            ret = max(ret, s, n - s)

    print(ret)


if __name__ == '__main__':
    main()


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

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

int main(){
    ll n , m ;
    cin >> n >> m ;
    if( m - 2*n >= 0 ) cout << n + ( m - 2*n )/4 << endl ; 
    else cout << m/2 << endl;
}

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

int main(){
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  vector<vector<char>>A(H,vector<char>(W,'o'));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int l=0;l<W;l++){
        A.at(i).at(l)='x';
      }
      for(int k=0;k<H;k++){
        A.at(k).at(j)='x';
      }
    }
  }
  int cnt=0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(A.at(i).at(j)=='o')cnt++;
    }
  }
  cout<<cnt<<endl;
  
}

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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds; 
// #define ordered_set tree< pair<int, int> , null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)
#define losuj_real(a, b) uniform_real_distribution<long double>(a, b)(rng)

typedef long double             ld;
typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
 
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second
 
template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}
 
template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }
  
const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll N = 1e6+7;
const ll T = 1<<20;
const ll BIG_INF = 1e18 + 7;

ll n, m, k, q;

char tab[3000][3000];
int dp[1020][1314];

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

    cin >> n >> m;

    dp[1][1] = 1;

    for(int i = 1; i <= n; i++)
    	for(int j = 1; j <= m; j++){
    		cin >> tab[i][j];
    		if(tab[i][j] == '.')
    			dp[i][j] += dp[i-1][j] + dp[i][j-1];
    		dp[i][j] %= INF;
    	}
    cout << dp[n][m] << '\n';
}

Measured memory_bytes: 8448
S = input()
T = input()
N = len(S)
M = len(T)

if N < M:
    jdg = False
else:
    
    jdg = T in S
    
    if jdg==False:
        for i in range( N-M, -1, -1 ):
            jdg = True
            for j in range(M):
                if S[i+j] != T[j] and S[i+j] != '?':
                    jdg = False
                    break;
            if jdg:
                li = list(S)
                li[i:i+M] = T
                S = ''.join(li)
                break;

if jdg:
    ans = S.replace('?', 'a')
    print(ans)
else:
    print("UNRESTORABLE")


Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>

#define N 8

using namespace std;

int main(void){
	int n; cin >> n;
	string input; 
	while(n --){
		cin >> input;
		sort(input.begin(), input.end());
		int min = atoi(input.c_str());
		reverse(input.begin(), input.end());
		cout << atoi(input.c_str()) - min << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <cstdio>
#include <cstdlib>

int N;
int x[200010], y[200010];
int x2[200010], y2[200010];
int n2;
int idx[200010];
long long res = 2000000000;
long long r1, r2;

int cmp(const void *aa, const void *bb)
{
	int i1 = *((int *)aa);
	int i2 = *((int *)bb);
	if(x2[i1] > x2[i2])
		return 1;
	else if(x2[i1] < x2[i2])
		return -1;
	return 0;
}
	

void solve()
{
	int i;
	int mni = 0;
	int mn = x[0];
	for(i=0; i<N; i++){
		if(mn > x[i]){
			mn = x[i];
			mni = i;
		}
	}
	int mxi = 0;
	int mx = y[0];
	for(i=0; i<N; i++){
		if(mx < y[i]){
			mx = y[i];
			mxi = i;
		}
	}
	n2 = 0;
	for(i=0; i<N; i++){
		if(i != mni && i != mxi){
			x2[n2] = x[i];
			y2[n2] = y[i];
			n2 ++;
		}
	}
	for(i=0; i<n2; i++)
		idx[i] = i;
	qsort(idx, n2, sizeof(int), cmp);
	int rmn1, rmx1;
	int rmn2, rmx2;
	rmn1 = x[mni];
	rmx2 = y[mxi];
	rmx1 = x[mxi];
	rmn2 = y[mni];
	if(rmx1 < x2[idx[n2-1]])
		r1 = x2[idx[n2-1]] - rmn1;
	else
		r1 = rmx1 - rmn1;
	int mniy=0, mny=-1;
	for(i=0; i<n2; i++){
		if(mny==-1 || mny > y2[idx[i]]){
			mniy = i;
			mny = y2[idx[i]];
		}
	}
	if(mny!=-1 && mny < rmn2)
		r2 = rmx2 - mny;
	else
		r2 = rmx2 - rmn2;
	res = r1 * r2;
	if(mni != mxi){
		rmn1 = x[mni];
		rmx1 = y[mxi];
		if(x[mxi] < y[mni]){
			rmn2 = x[mxi];
			rmx2 = y[mni];
		}
		else{
			rmx2 = x[mxi];
			rmn2 = y[mni];
		}
		mny = -1;
		int mxy = -1;
		for(i=0; i<n2; i++){
			int rmn2_2 = rmn2;
			if(rmn2_2 > x2[idx[i]])
				rmn2_2 = x2[idx[i]];
			int rmx2_2 = rmx2;
			if(rmx2_2 < x2[idx[n2-1]])
				rmx2_2 = x2[idx[n2-1]];
			if(mny != -1 && rmn2_2 > mny)
				rmn2_2 = mny;
			if(mxy != -1 && rmx2_2 < mxy)
				rmx2_2 = mxy;
			if(mny == -1 || mny > y2[idx[i]])
				mny = y2[idx[i]];
			if(mxy == -1 || mxy < y2[idx[i]])
				mxy = y2[idx[i]];
			r1 = rmx1 - rmn1;
			r2 = rmx2_2 - rmn2_2;
			if(r1 * r2 < res)
				res = r1 * r2;
		}
	}
	printf("%lld\n", res);
}

int main()
{
	int i;
	scanf("%d", &N);
	for(i=0; i<N; i++){
		scanf("%d %d", &x[i], &y[i]);
		if(x[i] > y[i]){
			int tmp = x[i];
			x[i] = y[i];
			y[i] = tmp;
		}
	}
	solve();
	return 0;
}

Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int n,m;
  	cin >> n;
    for(int i=1;i<50001;i++){
      	m=i*1.08;
        if(m == n){
            cout << i << endl;
            return 0;
        }
    }

    cout << ":(" << endl;
}

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

ans=1000
i=0
while i<n:
    j=i
    mi=a[i]
    while j<n and mi>=a[j]:
        mi=min(mi,a[j])
        j+=1
    
    if j==n:
        break

    stock=ans//mi
    ans-=stock*mi
    ans+=a[j]*stock
    i=j

print(ans)

Measured memory_bytes: 61760