akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> S(M), C(M), K(N);

    if (M == 0)
    {
        if (N == 1)
        {
            cout << 0 << endl;
            return 0;
        }
        else
        {
            cout << pow(10, N - 1) << endl;
            return 0;
        }
    }

    for (int i = 0; i < M; i++)
    {
        cin >> S[i] >> C[i];
    }

    int start;
    if (N == 1)
    {
        start = 0;
    }
    else if (N == 2)
    {
        start = 10;
    }
    else
    {
        start = 100;
    }

    for (int i = start; i < pow(10, N); i++)
    {
        for (int j = 0; j < N; j++)
        {
            int denom = pow(10, j);
            K[j] = (i / denom) % 10;
        }

        reverse(K.begin(), K.end());

        bool b = true;
        for (int j = 0; j < M; j++)
        {
            if (K[S[j] - 1] != C[j])
            {
                b = false;
            }
        }

        if (b)
        {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

ll dp[210][210]={};
void init(){
  rep(i,210)rep(j,210)if(i!=j)dp[i][j]=INF;
}

signed main(){
  int n,m,r;cin>>n>>m>>r;
  ll ans=INF;
  init();

  vector<int> togo(r); rep(i,r){cin>>togo[i];togo[i]--;}
  sort(all(togo));

  rep(i,m){
    ll a,b,c;cin>>a>>b>>c;
    dp[a-1][b-1]=c;
    dp[b-1][a-1]=c;
  }

  for(int k=0;k < n;k++)
  {
    for(int i=0;i < n;i++)
    {
      for(int j=0;j < n;j++)
      {
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
        //cout<<i<<":"<<j<<":"<<dp[i][j]<<endl;
      }
    }
  }


  do{
    ll res=0;
    for(int i=1;i < r;i++)
    {
      ll pre=togo[i-1],now=togo[i];
      res+=dp[pre][now];
    }
    ans=min(ans,res);

  }while(next_permutation(all(togo)));

  cout<<ans<<endl;
}


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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    string s,s1;
    cin>>s>>s1;
    string ans="";
    for(int i=0;i<n;++i){
        ans+=s[i];
        ans+=s1[i];
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int high ,width;
  char* image;
  
  scanf("%d %d",&high,&width);
  int i;
  image = malloc(sizeof(char)*width);
  for(i=0;i<high;i++){
    scanf("%s",image);
    printf("%s\n"
	   "%s\n",image,image);
  }
  return 0;
}


Measured memory_bytes: 128
n = int(input())
txy = [[0,0,0]] + [list(map(int, input().split())) for _ in range(n)]
for i in range(1,n+1):
  dist = abs(txy[i][1] - txy[i-1][1]) + abs(txy[i][2] - txy[i-1][2]) 
  diffTime = txy[i][0] - txy[i-1][0]
  if not (diffTime >= dist and abs(diffTime - dist) % 2 == 0):
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 28068
use std::cmp::min;
use std::io;
use std::io::prelude::*;

fn main() {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_to_string(&mut buf);
    let mut iter = buf.split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    let c: Vec<usize> = iter.map(|s| s.parse().unwrap()).collect();

    let mut dp = vec![std::usize::MAX; n + 1];
    dp[0] = 0;

    while dp[n] == std::usize::MAX {
        for i in 0..n {
            for c_i in c.iter() {
                if i + c_i <= n && dp[i] < std::usize::MAX {
                    dp[i+c_i] = min(dp[i+c_i], dp[i] + 1);
                }
            }
        }
    }

    println!("{}", dp[n]);
}



Measured memory_bytes: 5040
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        boolean ju[] = new boolean[100001];
        int pe[] = new int[100001];
        int wa=0;
        int ac=0;
        
        for(int i=0; i<b; i++){
            int n = sc.nextInt();
            String res = sc.next();
            
            if(res.equals("WA") && ju[n-1] != true){
                pe[n-1]++;
            }
            
            if(res.equals("AC")){
                ju[n-1] = true;
            }
        }
        
        for(int i=0; i<a ; i++){
            if(ju[i]){
                ac++;
                wa += pe[i];
            }
        }
        
        System.out.println(""+ac+" "+wa);
   }
}


Measured memory_bytes: 60052
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int cnt[5];

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

	map<char, int> cmap = { {'M',0},{'A',1} ,{'R',2},{'C',3},{'H',4} };

	int N;
	string s;
	cin >> N;
	rep(i, 0, N)
	{
		cin >> s;
		if (cmap.find(s[0]) != cmap.end())
		{
			cnt[cmap[s[0]]]++;
		}
	}

	int ans = 0;
	rep(i, 0, 5)rep(j, i + 1, 5)rep(k, j + 1, 5)
	{
		ans += cnt[i] * cnt[j] * cnt[k];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	long cnt = 0;
	long a = 0;
	long b = 0;
	long ab = 0;
	for(int i = 0; i<n; i++) {
	    String s = sc.next();
	    cnt += (s.length() - s.replace("AB","").length()) / 2;
	    if(s.charAt(0) == 'B' && s.charAt(s.length()-1) == 'A') ab++;
	    else if(s.charAt(0) == 'B') b++;
	    else if(s.charAt(s.length()-1) == 'A') a++;
	    //	    System.out.println(cnt + " " + ab +" " +a+" " + b);
	}

	long ans = Math.min(a,b) + ab +cnt;


	long min = (long)Math.min(a,b);
	if(min >= ab) ans = min+ab+cnt;
	else ans = cnt + min*2 +(ab-min);
	if(a==0&& b==0 && ab>0) ans = ab -1 +cnt;
	if(ab == n) ans = ab -1 +cnt;

	System.out.println(ans);

    }
}

Measured memory_bytes: 38804
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var v = Console.ReadLine().Split(' ')
            .Select(x => double.Parse(x))
            .OrderBy(x => x).ToArray();
        var tmp = (v[0] + v[1]) / 2;
        for (var i = 2; n > i; i++)
        {
            tmp = (tmp + v[i]) / 2;
        }
        Console.WriteLine(tmp);
    }
}


Measured memory_bytes: 28296
N = int(input())
A = list(map(int,input().split(' ')))
L = []
for i in A:
  if i % 2 != 0:
    L.append(0)
  elif i % 4 == 0:
    L.append(2)
  else:
    L.append(1)
if L.count(1) == 0:
  if L.count(0) -1  <= L.count(2):
    print('Yes')
  else:
    print('No')
else:
  if L.count(0) <= L.count(2):
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 14252
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<cstdlib>
using namespace std;

int main() {
  int a;
  double ans = 0;
  for(int i = 0; i < 5; i++) {
    cin >> a;
    ans += a < 40 ? 40 : a;
  }
  cout << ans / 5 << endl;
}

Measured memory_bytes: 3264
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = sum(B)
for i in range(N-1):
    if A[i+1] == A[i]+1:
        ans += C[A[i]-1]
print(ans)

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

int n,a,b,c;
vector<int> arr(9);

int sol(int x,int y, int z,int idx){
 if(idx == n){
   return min(min(x,y),z) > 0 ? abs(x-a)+abs(y-b)+abs(z-c)-30 : 1e9;
   
 } 
  int r1 = sol(x,y,z,idx+1);
  int r2 = sol(x+arr[idx],y,z,idx+1)+10;
  int r3 = sol(x,y+arr[idx],z,idx+1)+10;
  int r4 = sol(x,y,z+arr[idx],idx+1)+10;
  int m1 = min(r1,r2);
  int m2 = min(r3,r4);
  return min(m1,m2);
}

int main(){
  cin>>n>>a>>b>>c;
	
  for(int i = 0; i < n; i++) cin>>arr[i];
 cout<<sol(0,0,0,0);  

}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
if n%2==0:
  a = l[1::2][::-1]
  b = l[::2]
  for i in a:
    print(i,end=' ')
  for j in b:
    print(j,end=' ')
  
else:
  a = l[0::2][::-1]
  b = l[1::2]
  for i in a:
    print(i,end=' ')
  for j in b:
    print(j,end=' ')

Measured memory_bytes: 26180
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	if (x<0 && y>0)
	{
		printf("Zero\n");
		return 0;
	}
	if (x<0 && y<0)
	{
		if ((y-x)%2==1)
		 printf("Positive\n");
		 else printf("Negative\n");
		return 0;
	}
	if (x==0 || y==0)
	{
		printf("Zero\n");
		return 0;
	}
	else printf("Positive\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, M; string S; 
	cin >> N >> M >> S; 
	int dp[3010][3010] = {};
	int mod = 1000000007; 
	string T = S; 
	string U = S; 
	for(int i = 0; i < M; i++){
		int l, r; cin >> l >> r; l--; 
		sort(T.begin() + l, T.begin() + r); 
		sort(U.begin() + l, U.begin() + r, greater<char>()); 
	}
	int low[3010] = {}; int high[3010] = {}; 
	for(int i = 0; i < N; i++){
		if(U.at(i) == '1') high[i+1] = high[i] + 1; 
		else high[i+1] = high[i]; 
		if(T.at(i) == '1') low[i+1] = low[i] + 1; 
		else low[i+1] = low[i]; 
	}
	dp[0][0] = 1; 
	for(int i = 1; i <= N; i++){
		for(int j = low[i]; j <= high[i]; j++){
			if(j > 0) dp[i][j] += dp[i-1][j-1]; 
			dp[i][j] += dp[i-1][j];
			if(dp[i][j] >= mod) dp[i][j] -= mod; 
		}
	}
	cout << dp[N][high[N]] << "\n"; 
}

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

int main(){
    int n; cin >> n;
    vector<int> t(n); rep(i,n) cin >> t[i];
    int m; cin >> m;
    vector<int> p(m), x(m); rep(i,m) cin >> p[i] >> x[i];

    int sum = accumulate(t.begin(),t.end(),0);

    rep(i,m){
        cout << sum - (t[p[i]-1] - x[i]) << endl;;
    }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //足場の数
		
		int[] h = new int[n];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		dp[1] = Math.abs(h[1]-h[0]);
		
		for(int i = 1; i < n-1; i++) {
			dp[i+1] = Math.min(dp[i]+Math.abs(h[i+1]-h[i]), dp[i-1]+Math.abs(h[i+1]-h[i-1]));
		}
		
		System.out.println(dp[n-1]);
		
	}
	
	
	
}


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

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> vec(H, vector<char> (W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      char mark;
      cin >> mark;
      vec.at(i).at(j) = mark;
      }
    }

  int count = 0, ans = 0;
  for(int i = 0; i < (1 << H); i++){
    for(int j = 0; j < (1 << W); j++){
      count = 0;
      for(int k = 0; k < H; k++){
          for(int l = 0; l < W; l++){
            if(((i >> k) & 1) == 0 && ((j >> l) & 1) == 0 && (vec.at(k).at(l) == '#')){
              count++;
            }
          }
        }
      if(K == count){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#define MAX 100001
#define NIL -1

typedef struct{
  int parent;
  int left;
  int right;
}node;

node tree[MAX];
int D[MAX];

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",tree[u].parent);
  printf("depth = %d, ",D[u]);
  if(tree[u].parent == NIL)printf("root,");
  else if(tree[u].left == NIL)printf("leaf,");
  else printf("internal node,");
  printf(" [");
  i=0;
  for(c=tree[u].left;c != NIL ;c = tree[c].right){
    if(i)printf(", ");
    printf("%d",c);
    i++;
}
  printf("]\n");
}

int rec(int u,int p){
  D[u] = p;
  if(tree[u].right != NIL)rec(tree[u].right,p);
  if(tree[u].left != NIL)rec(tree[u].left,p+1);
}

int main(){
  int i,j,d,v,c,left,right,datanum;
  scanf("%d",&datanum);
  for(i=0;i<datanum;i++)tree[i].left = tree[i].right = tree[i].parent = NIL;

  for(i=0;i<datanum;i++){
    scanf(" %d %d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)tree[v].left = c;
      else tree[left].right = c;
      left  = c;
      tree[c].parent = v;
}
}
  for(i=0;i<datanum;i++){
    if(tree[i].parent == NIL)right = i;
}
  rec(right,0);
  for(i=0;i<datanum;i++)print(i);

  return 0;
    }



Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();
#define par(x) (n+x-2)/n

    int n, q; cin >> n >> q;
    while (q--) {
        int a, b; cin >> a >> b;
        if (n == 1)print(min(a, b));
        else {
            while (a != b) {
                if (a > b)a = par(a);
                else b = par(b);
            }
            print(a);
        }
    }

    return 0;
}

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

using namespace std;


int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0;i < n;i++){
        cin >> h[i];
    }
    
    int ans = 0;
    for(int i = 0;i < n;i++){
        if(h[i] >= k){
            ans++;
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
	string a, b;
	vector<int> ans;
	int n, num, ai, bi, c=0;
	bool flag;

	cin >> n;
	
	for(int i=0 ; i<n ; i++){
		cin >> a >> b;
		flag = false;
		
		for(int j=0 ; j<100 ; j++){
			num = 0;
			ai = a.size()-j-1;
			bi = b.size()-j-1;
			if( ai<0 && bi<0 && c==0) break;
			
			if(ai>=0)num += a[ ai ] - 48;
			if(bi>=0)num += b[ bi ] - 48;
			ans.push_back( (num+c)%10 );
			if(num+c >= 10) c = 1;
			else c = 0;
		}
		if(ans.size()>80){
			flag = true;
		}
		if(flag){
			printf("overflow");
		}else{
			for(int j=ans.size()-1 ; j>=0 ; --j){
				printf("%d", ans[j]);
			}
		}
		printf("\n");
		ans.clear();
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
void line(int n, char c){
    while(n--){
        printf("%c", c);
    }
}
int main(){
    int a, b, i;
    while(1){
        scanf("%d %d", &a, &b);
        if(a == 0 && b == 0) break;
        line(b, '#');
        printf("\n");
        while(a-->2){
            printf("#");
            line(b-2, '.');
            printf("#\n");
        }
        line(b, '#');
        printf("\n\n");
    }
return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using ll=long long int;

int main() {
    int n, k;
    cin >> n >> k;

    if ((n+1)/2 >= k) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 18;
char cn[cm], * ci = cn, ct;
const int dm = 1 << 16;
char dn[dm], * di = dn;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	fread(cn, 1, cm, stdin);
	int K = getint(), Q = getint();
	int D[5000];
	rep(i, K) D[i] = getint();

	rep(i, Q) {
		int N = getint(), X = getint(), M = getint();
		N--;
		X %= M;

		int N2 = N / K;
		N %= K;

		ll kosuu = 0, kosuu2 = 0;
		ll kazu = 0, kazu2 = 0;
		rep(i, N) {
			int kari = D[i] - int(double(D[i]) / M) * M;
			if (kari) {
				kosuu++;
				kazu += kari;
			}
		}
		for (int i = N; i < K; i++) {
			int kari = D[i] - int(double(D[i]) / M) * M;
			if (kari) {
				kosuu2++;
				kazu2 += kari;
			}
		}
		kosuu *= N2 + 1;
		kazu *= N2 + 1;
		kosuu2 *= N2;
		kazu2 *= N2;
		kosuu += kosuu2;
		kazu += kazu2 + X;

		kosuu -= kazu / M;

		putint(kosuu);
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repi(i, a, b) for(int i=(a); i>(b); i--)
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define gcd __gcd
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue
#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld", &a)
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007
#define MOD 1000000007
#define N 300005
using namespace std;

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;

//All indexing is 0-based
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
       tree_order_statistics_node_update> ordered_set;
//methods: find_by_order(k); & order_of_key(k);
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar.

//a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod){ int c = a + b; if(c >= p) c -= p; return c;}
inline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c;}
inline int mul(int a, int b, int p = mod){ return (a * 1ll * b) % p;}

int n, m;
string s;
vi adj[N];
int ar[N][2];
bitset<N> exists;

void remove_vertex(int v) {
  exists[v] = 0;
  ar[v][0] = ar[v][1] = 0;
  for(int w : adj[v]) {
    if(exists[w]) {
      ar[w][s[v] - 'a']--;
      if(ar[w][s[v] - 'a'] == 0) {
        remove_vertex(w);
      }
    }
  }
}

int main()
{ 
  #ifdef CP
    freopen("/home/tarun/Desktop/input.txt", "r", stdin);
    //freopen("/home/tarun/Desktop/output.txt", "w", stdout);
  #endif
  sync;
  clock_t clk = clock();
  cerr << "I will return...\n";

  cin >> n >> m >> s;
  for(char &c : s) c = tolower(c);
  rep(i, 0, n) exists[i] = 1;
  rep(i, 0, m) {
    int u, v; cin >> u >> v;
    u--, v--;
    adj[u].pb(v);
    adj[v].pb(u);
    ar[u][s[v] - 'a']++;
    ar[v][s[u] - 'a']++;
  }

  rep(i, 0, n) {
    if(ar[i][0] == 0 || ar[i][1] == 0) {
      if(!exists[i]) continue;
      remove_vertex(i);
    }
  }

  rep(i, 0, n) {
    if(exists[i]) {
      cout << "Yes\n";
      return 0;
    }
  }

  cout << "No\n";
 
  cerr << "...don't you ever hang your head.\n";
  cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << '\n';
}

//Compile using:
//g++ -o filename.exe --std=c++11 filename.cpp
//Use -D CP for defining a macro CP in the local environment







Measured memory_bytes: 19408
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n =  read int
    let xss = Array.init n (fun _ -> reada int)

    let dp = Array.init n (fun _ -> Array.create 3 0)
    for i = 0 to 2 do dp.[0].[i] <- xss.[0].[i]
    for i = 1 to n - 1 do
        for j = 0 to 2 do
            seq {
                for k = 0 to 2 do
                if j <> k then yield dp.[i-1].[k] + xss.[i].[j]
            }
            |> Seq.max
            |> fun x -> dp.[i].[j] <- x

    printfn "%i" (Array.max dp.[n-1])
    0

Measured memory_bytes: 31336
#include <iostream>
#include <stdio.h>
#include <string>
#include <cctype>
using namespace std;

int main() {
    string word, s;
    int count = 0;
    cin >> word;
    for (int i = 0; i < word.size(); i++) {
        if (isupper(word[i])){
            word[i] = tolower(word[i]);
        }
    }
    while(1) {
        cin >> s;
        if (s == "END_OF_TEXT") {
            cout << count << endl;
            break;
        }
        for (int i = 0; i < s.size(); i++) {
            s[i] = tolower(s[i]);
        }
        if (word == s) {
            count++;
        }
    }
    return 0;
}

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

const long long md=1000000007;
const int maxn=300100;
long long fac[maxn],inv[maxn];
long long powd(long long x,long long y){
	long long res=1;
	while(y){
		if(y&1) res=res*x%md;
		x=x*x%md;
		y>>=1;
	}
	return res;
}
void csh(){
	fac[0]=1;
	for(int i=1;i<=300000;i++)
		fac[i]=fac[i-1]*i%md;
	inv[300000]=powd(fac[300000],md-2);
	for(int i=300000;i>=1;i--)
		inv[i-1]=inv[i]*i%md;
}
long long C(int x,int y){
  if (x < y) return 0;
	else return fac[x]*inv[y]%md*inv[x-y]%md;
}

int main(){
  csh();
  int n;
  cin >> n;
  vector<int> a(n+1);
  for (int i=0; i<n+1; i++) cin >> a[i];
  set<int> check;
  int target = 0;
  for (int i=0; i<n+1; i++){
    if (check.find(a[i]) != check.end()) {target = a[i]; break;}
    else check.insert(a[i]);
  }

  int f = -1, b = -1;
  for (int i=0; i<n+1; i++){
    if (a[i] == target){
      if (f == -1) f = i;
      else b = i;
    }
  }

  for (int k=1; k<=n+1; k++){
    long long ans = 0;
    ans = (C(n+1,k) - C(n-b+f,k-1) + md)%md;
    cout << ans << endl;
  }
}

Measured memory_bytes: 11008
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int N;
	cin>>N;
	vector<int> A(N);

	for(int i=0; i<N; i++)
	{
		cin>>A[i];
	}

	vector<int> B(N);
	B = A;
	sort(B.begin(),B.end(),greater<int>());
	int max = B[0];
	for(int i=0; i<N; i++)
	{
		if(A[i]==B[0])
		{
			cout<<B[1]<<endl;
		}
		else
		{
			cout<<max<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <climits>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long ll;


int main(void) {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int count = 0;
  for (int r = 0; R * r <= N; r++) {
    for (int g = 0; G * g <= N - R * r; g++) {
      if ((N - R * r - G * g) % B == 0) {
      // for (int b = 0; B * b <= N - R * r - G * g; b++) {
        // if (r * R + g * G + b * B == N) {
          count++;
        // }
      }
    }
  }
  cout << count << endl;
}


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

using namespace std;

#define int long long

bool isPrime[300000];
int sum[300000];

signed main()
{
	fill_n(isPrime, 300000, true);
	isPrime[0] = isPrime[1] = false;
	int s = sqrt(300000);
	for (int i = 2; i < s; i++)
	{
		if (!isPrime[i]) continue;
		for (int j = 2; i * j < 300000; j++)
		{
			isPrime[i * j] = false;
		}
	}
	
	for (int i = 1; i < 300000; i++)
	{
		sum[i] = sum[i - 1] + isPrime[i];
	}

	int N;
	while (cin >> N, N)
	{
		printf("%lld\n", sum[2 * N] - sum[N]);
	}
	return 0;
}

Measured memory_bytes: 3784
#include <stdio.h>
int gcd(int ,int);
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int max = 1;
  int i;
  max = gcd(a,b);
  printf("%d\n",max);
  return 0;
}
int gcd(int m,int n){
  int rest;
  int x = (m > n) ? m:n;
  int y = (x == m)? n:m;
  while(1){
    rest = x%y;
    if(rest ==0) return y;
    x = y;
    y = rest;
  }
}

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



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    ll x;
//    x=1ll << 59;
//    ll y=(1ll << 59) - 1ll;
//    cout<<((double)(x)==(double)(x-1))<<endl;
    ll n;
    cin>>n;
    ll l1[n+1],l2[n+1],sl1[n+1],sl2[n+1];
    sl1[0]=0;
    sl2[0]=0;
    for(int i=1;i<=n;i++){
        cin>>l1[i];
    }
    sort(l1+1,l1+n+1,greater<int>());
    ll s=0;
    for(int i=1;i<=n;i++){
        if(i&1)s+=l1[i];
        else s-=l1[i];
    }
    cout<<s<<endl;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string x;
cin>>x;
int _x=0;

if(x.size()>=3){
    //下2桁を取得
    int under_2digit=stoi(x.substr(x.size()-2,2));
    int div=5;
    map<int,int> div_num;
    while(under_2digit>0){
        div_num[div]=under_2digit/div;
        under_2digit%=div;
        div--;
    }
    for(auto v:div_num){
        _x+=(100+v.first)*v.second;
    }
}
else{
    _x=100;
}
if(_x<=stoi(x))cout<<1<<endl;
else cout<<0<<endl;
return 0;
}

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

int main()
{
    int numa, numb, numc, numd;
    cin >> numa >> numb >> numc >> numd;

    if(numa*numb>numc*numd){
        cout << numa * numb;
    }else{
        cout << numc * numd;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 760
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;
import java.util.*;
 
public class Main {
    Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
    	new Main(); 
    }
 
    public Main() {
    	while(sc.hasNext()){
    		new aoj0076().doIt();
    	}
    }
    class aoj0076{
    	int set[][] = {{1,4,1,4,1,2,1,2},
    			{2,1,4,1,4,1,2,1},
    			{1,2,1,4,1,4,1,2},
    			{2,1,2,1,4,1,4,1},
    			{1,2,1,2,1,4,1,4},
    			{4,1,2,1,2,1,4,1},
    			{1,4,1,2,1,2,1,4},
    			{4,1,4,1,2,1,2,1}};
    	int set2[] = {14141212,21414121,12141412,21214141,12121414,41212141,14121214,41412121};
    	void doIt(){
    		int a[] = new int [8];
    		for(int i = 0;i < 8;i++)a[i] = sc.nextInt();
    		int ans = 0;int num = Integer.MAX_VALUE;
    		for(int i = 0;i < 8;i++){
    			int num2 = 0;
    			for(int j = 0;j < 8;j++){
    				if(a[j] - set[i][j] > 0)num2 += a[j] - set[i][j];
    			}
    			if(num > num2){
    				num = num2;
					ans = i;
				}else if(num == num2){
					if(set2[ans] > set2[i]){
    					num = num2;
						ans = i;
    				}
				}
    		}
    		for(int i = 0;i < 7;i++){
    			System.out.print(set[ans][i]+" ");
    		}
    		System.out.println(set[ans][7]);
    	}
    }
}

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

int N;
vector<double> p;
vector<vector<double>> dp;

double rec(int c, int h) {
	if (c == N) {
		if (h >= (N + 1) / 2) {
			return 1;
		}
		return 0;
	}
	if (dp[c][h] != -1.0) {
		return dp[c][h];
	}
	return dp[c][h] = p[c] * rec(c + 1, h + 1) + (1.0 - p[c]) * rec(c + 1, h);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N;
	p.resize(N);
	dp.resize(N, vector<double> (N, -1.0));
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}
	double ans = rec(0, 0);
	cout << fixed << setprecision(12) << ans;
	
	return 0;
}


Measured memory_bytes: 73956
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define test(t) int t ; cin>>t ; while(t--)
#define mod 1000000007




int n,m;
int main(){
	cin>>n;
	if(n>=1 && n<=999){
		cout<<"ABC";
	}
	else{
		cout<<"ABD";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

int main(){

    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    // if((a[0] == a[1]) || (a[0] && a[2]) || (a[1]== a[2])){

    //     if(!(a[0] == a[1] &&a[1] == a[2]))cout << "Yes" << endl;
    //     if((a[0] == a[1] &&a[1] == a[2]) || ) cout << "No" << endl;
    // }else{
    //     cout << "No" << endl;
    // }
    const int num = 3;
    int cnt =0;
    for(int i=0;i < num-1;i++){
        for(int j = i+1;j < num;j++){
            if(a[i] == a[j]) cnt++;


        }
    }

    if(cnt == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}

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

int main() 
{
  int n, k;
  string s;
  cin >> n >> k >> s;
  if (s.at(k - 1) == 'A') s.at(k - 1) = 'a';
  if (s.at(k - 1) == 'B') s.at(k - 1) = 'b';
  if (s.at(k - 1) == 'C') s.at(k - 1) = 'c';
  cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

#define INF 20000000
typedef struct Edge edge;

struct Edge{
  int src,dst,weight;
  Edge(int start,int end,int cost) :
	src(start),dst(end),weight(cost) {}
};

bool operator < (const edge &e,const edge &f){
  return (e.weight != f.weight) ? (e.weight > f.weight) : (e.src != f.src) ? (e.src < f.src) : (e.dst < f.dst);
}

typedef vector<edge> Edges;

vector<int> dijkstra(Edges,int);

int main(int argc,char* argv[]){
  int n,v,k,dst,weight;
  Edges es;
  vector<int> vec;

  cin >> n;
  for(int i = 0;i < n;i++){
	cin>> v >> k;
	vec.push_back(v);
	for(int j = 0;j < k;j++){
	  cin >> dst >> weight;
	  edge e(i,dst,weight);
	  es.push_back(e);
	}
  }

  vector<int> dist = dijkstra(es,n);

  for(int i = 0;i < n;i++)
	printf("%d %d\n",vec[i],dist[i]);
  return 0;
}

vector<int> dijkstra(Edges es,int n){
  vector<int> dist(n);
  priority_queue<edge> que;
  Edges l[n];
  dist.assign(n,INF);
  dist[0] = 0;

  for(int i = 0;i < (int)es.size();i++){
	edge e = es[i];
	l[e.src].push_back(e);
  }

  for(int i = 0;i < (int)l[0].size();i++)
	que.push(l[0][i]);

  while(!que.empty()){
	edge e = que.top();
	que.pop();
	if(dist[e.dst] > dist[e.src] + e.weight){
	  dist[e.dst] = dist[e.src] + e.weight;

	  for(int i = 0;i < (int)l[e.dst].size();i++)
		que.push(l[e.dst][i]);
	}
  }

  return dist;
}

Measured memory_bytes: 46048
#!/usr/bin/env python3
X, Y, A, B, C = [int(str) for str in input().strip().split()]
ps = [int(str) for str in input().strip().split()]
qs = [int(str) for str in input().strip().split()]
rs = [int(str) for str in input().strip().split()]

def sums(li):
    ret = [0]
    for i in range(len(li)):
        ret.append(ret[-1] + li[i])
    return ret

def f(n):
    return red_and_green_sums[X + Y - n] + r_sums[n]

ps.sort(reverse=True)
qs.sort(reverse=True)
rs.sort(reverse=True)

r_sums = sums(rs)

red_and_green = ps[:X] + qs[:Y]
red_and_green.sort(reverse=True)
red_and_green_sums = sums(red_and_green)

# print([f(i) for i in range(C)])
print(max([f(i) for i in range(min(X + Y, C) + 1)]))

Measured memory_bytes: 34636
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if(a == b){
        cout <<"Yes";
    }
    else
    {
        cout << "No";
    }
    
    
    cout << endl;
}


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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;
ll sumx[100001], sumy[100001];

int main(int argc, char const* argv[])
{
  int n, m;
  cin >> n >> m;
  vector<ll> x, y;
  for(int i = 0; i < n; i++){
    ll a;
    cin >> a;
    x.pb(a);
    if(i == 0)sumx[0] = a;
    else sumx[i] = (sumx[i - 1] + a) % mod;
  }
  for(int i = 0; i < m; i++){
    ll b;
    cin >> b;
    y.pb(b);
    if(i == 0)sumy[0] = b;
    else sumy[i] = (sumy[i - 1] + b) % mod;
  }
  ll resx = 0, resy = 0;
  for(int i = 0; i < n; i++){
    resx = (((((resx + sumx[n - 1]) % mod)- sumx[i]) % mod) - (n - i - 1) * x[i] % mod) % mod;
  }
  for(int i = 0; i < m; i++){
    resy = (((((resy + sumy[m - 1]) % mod)- sumy[i]) % mod) - (m - i - 1) * y[i] % mod) % mod;
  }
  if(resx < 0)resx += mod;
  if(resy < 0)resy += mod;
  cout << resx * resy % mod << endl;
	return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(void){
    int N, K, pbuf;
    vector<int> p;
    int psum=0;
    int psummax=0;
    cin >> N >> K;
    for(int i=0; i<N; i++){
        cin >> pbuf;
        p.push_back(pbuf);
        if(i<K){
            psum+=1+pbuf;
            psummax+=1+pbuf;
        }else{
            psum=psum-p[i-K]+p[i];
            psummax = max(psummax, psum);
        }
    }

    cout << setprecision(10) << (double)psummax/2.0 << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
using ll=long long;

int main(){
    int n;cin>>n;
    ll ab[2][100010];
    ll ans=0;
    for(int i=0;i<n;++i){
        cin>>ab[0][i]>>ab[1][i];
    }
    for(int i=n-1;i>=0;--i){
        ab[0][i]+=ans;
        if(ab[0][i]%ab[1][i]==0)continue;
        ans+=ab[1][i]-(ab[0][i])%ab[1][i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int nums[11][11];
int main(){
  int n;
  cin >> n;

  for (int i = 1;i <= n;i++){
    string s;
    s = to_string(i);
    int top,last;
    top = stoi(s.substr(0,1));
    last = stoi(s.substr(s.size()-1,1));
    nums[top][last]++;
  }
  ll ans = 0LL;
  for (int i = 1;i <= 9;i++){
    for (int j = 1; j <= 9;j++){
      ans += nums[i][j]*nums[j][i];
    }
  }
  cout << ans << endl;
   
  return 0; 
}



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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> dist(n,0);
    vector<vector<int>> edges(n);
    
    for (int i = 0;i < m;++i) {
        int u,v;
        scanf("%d%d",&u,&v);
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    ll a = 0,b = 0,c = 0,ans = 0;
    for (int i = 0;i < n;++i) if (dist[i] == 0) {
        if (edges[i].size() == 0) {
            c++;
            continue;
        }
        queue<int> que;
        que.push(i);
        bool nibu = true;
        while (!que.empty()) {
            int t = que.front();que.pop();
            for (int j : edges[t]) {
                if (dist[j]) {
                    if (dist[j]%2 == dist[t]%2) nibu = false;
                } else {
                    dist[j] = dist[t]+1;
                    que.push(j);
                }
            }
        }
        if (nibu) a++;
        else b++;
    }
    ans += a*a*2+b*b+b*a*2+(2*n*c-c*c);
    cout << ans << endl;
}

Measured memory_bytes: 7296
S = input()
S=str(S)

if S[0]==S[1]:
  if S[2]==S[3]:
    if S[0] != S[2]:
      print('Yes')
    else:
      print('No')
  else:
  	print('No')
elif S[0]==S[2]:
  if S[1]==S[3]:
    if S[0] != S[1]:
      print('Yes')
    else:
      print('No')
  else:
  	print('No')
elif S[0]==S[3]:
  if S[1]==S[2]:
    if S[0] != S[1]:
      print('Yes')
    else:
      print('No')
  else:
  	print('No')
else:
	print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
int main(){
  ll n; string s; cin >> n >> s;
  if(n%2!=0){
    cout << "No"; 
    return 0;
  }
  rep(i,n/2){
    if(s[i]!=s[i+n/2]){
      cout << "No"; 
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if((100 * a + 10 * b + c) % 4 == 0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        h: usize, w: usize,
        a: [Chars; h],
    }

    println!("{}", vec!['#'; w + 2].iter().join(""));
    for a in a {
        println!("#{}#", a.iter().join(""));
    }
    println!("{}", vec!['#'; w + 2].iter().join(""));
}


Measured memory_bytes: 2196
n , k = map(int, input().split())

trees = []

for i in range(n):
    trees.append(int(input()))

trees.sort()
min_diff = 10**10
for j in range(n-k+1):
    diff = abs(trees[j] - trees[j+k-1])
    if diff < min_diff:
        min_diff = diff

print(min_diff)

Measured memory_bytes: 7492
n=int(input())
x=[]
u=[]
for i in range(n):
    X,U = input().split()
    x.append(float(X))
    u.append(U)
ans = 0
for i in range(n):
    if u[i] == 'JPY':
        ans += x[i]
    else:
        ans += x[i]*380000
print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include <stdlib.h>
int main(){
  int N;
  int distance;

  scanf("%d",&N);
  int A[100010],result[100010];
  A[0]=0;
  A[N+1]=0;

  for(int i=1;i<=N;i++){
    scanf("%d", &A[i]);
  }

  for(int i=1;i<=N+1;i++){
    distance+=abs(A[i]-A[i-1]);
  }

  for(int i=1;i<=N;i++){
    result[i]=distance-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]);
  }

  for(int i=1;i<=N;i++){
    printf("%d\n",result[i]);
  }
  return 0;
}


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


int main(void)
{

    int A,B,tmp,a,b,d,e,cnt = 0;

    cin >> A >> B;

    for(int i = A;i <= B;i++){
        tmp = i;
        a = tmp%10;
        b = (tmp /= 10)%10;
        tmp /= 10;
        d = (tmp /= 10)%10;
        e = (tmp /= 10)%10;

        if(a == e && b== d)
            cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3624
n, m = map(int, input().split())
vertices = {i: [] for i in range(n)}
for _ in range(m):
    l, r, d = map(int, input().split())
    vertices[l - 1].append((r - 1, d))
    vertices[r - 1].append((l - 1, -d))


def answer():
    x = [None] * n

    for i in range(n):
        if x[i] is not None:
            continue
        x[i] = 0
        queue = [i]

        while queue:
            i0 = queue.pop()
            for i1, d in vertices[i0]:
                # print(i0, i1, x[i0], x[i1], d)
                if x[i1] is None:
                    x[i1] = x[i0] + d
                    queue.append(i1)
                elif x[i1] != x[i0] + d:
                    return False

    return True


if answer():
    print('Yes')
else:
    print('No')





Measured memory_bytes: 77344
m, d = gets.split.map(&:to_i)
count = 0
for mm in 1..m do
  for dd in 22..d do
    d1 = dd % 10
    d10 = dd / 10
    if d1 > 1 && d1 * d10 == mm
      count += 1
#      puts "#{mm}m #{dd}d"
    end
  end
end
puts count


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d; cin >> a >> b >> c >> d;
    int flg = 0;
    if (abs(a - c) <= d) flg = 1;
    if (abs(a - b) <= d && abs(b - c) <= d) flg = 1;
    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


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

#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
#define NMAX 50

using namespace std;
bool MAP[NMAX][NMAX];
bool alr[NMAX][NMAX];

int dx[3] = {-1,0,1};
int dy[3] = {-1,0,1};
int w,h;

void DFS(int y,int x){
	alr[y][x] = true;
	rep(i,0,9){
		if(0<=y+dy[i/3] && y+dy[i/3]<h && 0<=x+dx[i%3] && x+dx[i%3]<w && MAP[y+dy[i/3]][x+dx[i%3]] && !alr[y+dy[i/3]][x+dx[i%3]]){
			DFS(y+dy[i/3],x+dx[i%3]);
		}
	}
}

int main(){
	while(true){
	int count=0;
	cin >> w >> h;
	if(w == 0 && h == 0){ break; }
	rep(i,0,h){
		rep(j,0,w){
			alr[i][j] = false;
			cin >> MAP[i][j];
		}
	}
	rep(i,0,h){
		rep(j,0,w){
			if(MAP[i][j] && !alr[i][j]){
				DFS(i,j);
				count++;
			}
		}
	}
	cout << count << endl;
	}
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  char a,b;
  cin >> a >> b;
  if(a==b){
    cout << "H" << endl;
  }else{
    cout << "D" << endl;
  }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
//////////////

void solve() {
	int A, B, C;
	cin >> A >> B >> C;
	int res = B / A;
	int ans = min(res, C);
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256