akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int main () {
  int N; cin >> N;
  vi A(N), B(N), C(N);
  REP(i,N) cin >> A[i];
  REP(i,N) cin >> B[i];
  REP(i,N) cin >> C[i];

  SORT(A);
  SORT(B);
  SORT(C);

  ll ans = 0;
  REP(i,N) {
    auto ai = lower_bound(ALL(A),B[i])-1;
    auto ci = upper_bound(ALL(C),B[i]);
    ans += (ai+1-A.begin())*(C.end()-ci);
  }

  cout << ans << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

int main(void) {
  int n;
  string s,str1,str2;
  string s1, s2;
  set<string> S;
  cin >> n;

  for (int i = 0; i < n; i++) {
	S.clear();
	cin >> s;
	for (int j = 1; j < s.length(); j++) {
	  str1 = s.substr(0, j);
	  str2 = s.substr(j, s.length());
	  s1 = "";
	  s2 = "";
	  for (int k = str1.length() - 1; k >= 0; k--) {
		s1 += str1[k];
	  }
	  for (int k = str2.length() - 1; k >= 0; k--) {
		s2 += str2[k];
	  }
	  S.insert(str1 + str2);
	  S.insert(s1 + str2);
	  S.insert(str1 + s2);
	  S.insert(s1 + s2);
	  S.insert(str2 + str1);
	  S.insert(s2 + str1);
	  S.insert(str2 + s1);
	  S.insert(s2+ s1);
	}
	cout << S.size() << endl;
  }
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back
#define FOR for(int i=1; i<=n; ++i)

int main() {

    int n, x, t;
    sc("%d %d %d", &n, &x, &t);

    int y = ceil((double) n/x);

    printf("%d\n", y*t);
}



Measured memory_bytes: 3816
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};
typedef vector<vector<Edge>> Graph;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}


signed main(void) {
	int n, ans = 0;
	int minR = 1000000009, maxL = 0;
	pair<pii, int>  Rid = { {1000000009, 0}, 0 }, Lid = { { 0, 1000000009 },0 };
	cin >> n;
	vector<pii> e(n);
	REP(i, n) {
		cin >> e[i].first >> e[i].second;
		ans = max(ans, e[i].second - e[i].first + 1);

		if (minR > e[i].second)
			minR = e[i].second;
		if (maxL < e[i].first)
			maxL = e[i].first;

		Rid = min(Rid, { {e[i].second, -e[i].first}, i });
		Lid = max(Lid, { {e[i].first, -e[i].second}, i });
	}

	sort(ALL(e));
	int rinR = 1000000009, raxL = 0;

	for (int i = n - 1; 1 <= i; i--) {
		rinR = min(rinR, e[i].second);
		raxL = max(raxL, e[i].first);

		int cl = max(0,minR - e[i-1].first + 1);
		int cr = max(0,rinR - raxL + 1);
		ans = max(ans, cl + cr);
		if (e[i].second == minR) break;
	}



	REP(i, n) {
		if (i == Rid.second || i == Lid.second) continue;

		ans = max(ans, e[i].second - e[i].first + 1 + (minR - maxL + 1));
	}

	cout << ans << endl;

	return 0;
}
 

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

//Road Construction
public class Main{

	class E{
		int t, d, c;
		public E(int t, int d, int c) {
			this.t = t;
			this.d = d;
			this.c = c;
		}
	}
	
	int INF = 1<<29;
	int[] dist;
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		dist = new int[10001];
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			List<E>[] adj = new List[n+1];
			for(int i=0;i<=n;i++)adj[i]=new ArrayList<E>();
			while(m--!=0){
				int s = sc.nextInt(), t = sc.nextInt(), D = sc.nextInt(), C = sc.nextInt();
				adj[s].add(new E(t, D, C)); adj[t].add(new E(s, D, C));
			}
			Arrays.fill(dist, INF);
			dist[1] = 0;
			PriorityQueue<Integer> q = new PriorityQueue<Integer>(n, new Comparator<Integer>() {
				public int compare(Integer o1, Integer o2) {
					return dist[o1]-dist[o2];
				}
			});
			q.add(1);
			while(!q.isEmpty()){
				int v = q.poll();
				for(E e:adj[v]){
					int w = dist[v]+e.d;
					if(w<dist[e.t]){
						dist[e.t] = w; q.add(e.t);
					}
				}
			}
			int res = 0;
			for(int i=2;i<=n;i++){
				E edge = null;
				for(E e:adj[i]){
					if(dist[e.t]+e.d!=dist[i])continue;
					if(edge==null)edge = e;
					else if(e.c<edge.c)edge = e;
				}
				res+=edge.c;
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main() {
  string s, t;
  cin >> s >> t;
  bool ok = false;
  rep(i, s.size()) {
    string u = s[s.size() - 1] + s.substr(0, s.size() - 1);
    if (u == t) {
      ok = true;
    }
    s = u;
  }
  if (ok) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int n;

int main(){
	while(cin>>n){
		if(n==0)return 0;
		n=1000-n;
		cout<<n/500+n%500/100+n%100/50+n%50/10+n%10/5+n%5/1<<endl;
	}
}

Measured memory_bytes: 0
A,B=map(int,input().split())
S=input()
if S[A]=="-":
  for i in range(A):
    if S[i]=="-":
      print("No")
      break
  else:
    for j in range(B):
      if S[-j-1]=="-":
        print("No")
        break
    else:
      print("Yes")
else:
  print("No")

Measured memory_bytes: 9124
#include<bits/stdc++.h>
using namespace std;
int main()
{
  
      int n,a,cnt = 0;
    cin >> n;
    vector<int>v;
    for(int i =1; i <= n; i++)
    {
        cin >> a;
        v.push_back(a);
    }
    for(int i = 0; i < v.size() ; i=i+2)
    {

        if(v[i]%2==1)
        {
            cnt++;
        }
    }
    cout << cnt << "\n";







}


Measured memory_bytes: 3520
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

m = sum(B) - sum(A)
if m <= -1:
    print("No")
else:
    # print("m",m)
    M = [m, m]
    for i in range(n):
        di = B[i] - A[i]
        if di > 0:
            if di % 2 == 1:
                di += 1
                M[1] -= 1
            M[0] -= di//2
        else:
            M[1] -= -di
    # print(M)
    if M[0] >= 0 and M[1] >= 0 and M[0]*2 == M[1]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 40432
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");
    const x = Number(input[0])
    let s = new Set()
    for(let i = 1; i<input.length;i++){
        s.add(input[i])
    }

    console.log(s.size)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

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

using namespace std;

int main() {
	string S;
	cin >> S;

	int x = 0;
	for (int i = 0; i < S.size(); i++) {

		if (S[i] == '1') {
			x++;
		}
	}
	cout << x << endl;

}

Measured memory_bytes: 3616
#include <vector> // vectorを使うためにインクルードする
#include <iostream>
using namespace std;
int main() {
	vector<int> vc; // <T>でT型のvector
	int n;
	cin >> n;
    int count = n;
    int out = 0;
	while(n--) {
		int x;
		cin >> x;
		vc.push_back(x);
	}
  for(int i = 0; i < count; i++){
    for(int j = i + 1; j < count; j++){
      out += vc[i] * vc[j];
    }
  }
  cout << out << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];

    sort(all(a), greater<int>());

    lint res = a[0];

    int cnt = 2;
    int i = 1;

    while (cnt < n) {
        res += a[i];
        cnt++;
        if (cnt == n) break;

        res += a[i];
        cnt++;
        i++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3992
a,b=map(int,input().split())

def lcm(x, y):
 
   #  获取最大的数
   if x > y:
       lower = y
   else:
       lower = x
 
   while(True):
       if((x % lower == 0) and (y % lower == 0)):
           lcm = x*y//lower
           break 
       lower -= 1
 
   return lcm
print(lcm(a,b))

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

#define mod 1000000007

// F_mod 上でのべき乗, 蟻本p115
ll modPow(ll x, ll n) {
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

// Fermat の小定理を用いた F_mod 上での逆元計算x^(mod-2)
ll Inverse(ll x){
    return modPow(x, mod - 2);
}

// iの階乗 = fact[i], main内の階乗計算をする必要がある
#define MAX_FACT 200001
ll fact[MAX_FACT];

ll nCk(int n, int k){
    //　n_C_kの計算, Inverseの中身にもmodを入れないとオーバーフローするので注意, 蟻本p.263
    ll ans = fact[n] * Inverse(fact[k] * fact[n-k] % mod);
    ans %= mod;
    return ans;
}

int main() {
    ll N, A, B, C;
    cin >> N >> A >> B >> C;

    ll inv_ab = Inverse(A+B);

    // 階乗計算
    fact[0]=1;
    for(int i = 1; i < MAX_FACT; ++i) {
        fact[i] = fact[i-1] * i % mod;
    }

    // 引き分け無視して後で 100/(A+B) を掛ければいい
    vector<ll>tk_win(N);
    vector<ll>ao_win(N);
    ll aa = A * inv_ab % mod;
    ll bb = B * inv_ab % mod;
    ll aN = modPow(aa, N);
    ll bN = modPow(bb, N);
    ll ac = 1;
    ll bc = 1;
    for (int i = 0; i < N; ++i) {
        tk_win[i] = aN * bc % mod;
        tk_win[i] = tk_win[i] * nCk(N+i-1, i) % mod;
        bc = bc * bb % mod;
        ao_win[i] = bN * ac % mod;
        ao_win[i] = ao_win[i] * nCk(N+i-1, i) % mod;
        ac = ac * aa % mod;
    }
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += tk_win[i] * (N+i);
        ans += ao_win[i] * (N+i);
        ans %= mod;
    }
    ans = ans * 100 % mod;
    ans = ans * inv_ab % mod;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

int selectSort(int A[], int N)
{
  int t,j, i=0, sw=0,mini;

  for ( i = 0; i < N; i++ ){
    mini = i;
    for ( j = i; j < N; j++ ){
      if ( A[j] < A[mini] ) mini = j;
    }
    if ( i != mini ) {
      sw++;
      t = A[i]; A[i] = A[mini]; A[mini] = t;
    }
  }
  return sw;
}


void print(int A[], int N, int sw){
  int i;
  for ( i = 0; i < N; i++ ){
    if (i) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", sw);
}

int main( void )
{
  int A[100], n, i, sw=0;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  sw=selectSort(A,n);

  print(A,n,sw);
  
  return 0;
}



Measured memory_bytes: 2680
#include <iostream>

using namespace std;

inline long long int gcd(long long int a, long long int b) {
    return b == 0LL ? a : gcd(b, a%b);
}

inline long long lcm(long long int a, long long int b) {
    return (long long int)(((a)/gcd(a,b))*b);
}

int main() {
    int N;
    long long int T, ans;
    ans = 1LL;
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> T;
        ans = lcm(ans,T);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N,H = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]
maxa = 0
bs = []
for a,b in src:
    maxa = max(maxa, a)
    bs.append(b)
bs.sort()

ans = 0
while bs:
    b = bs.pop()
    if b <= maxa: break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()

ans += -(-H//maxa)
print(ans)

Measured memory_bytes: 17700
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Cryptography;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        checked {
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
        }
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var r = int.Parse(spl[0]);
        var g = int.Parse(spl[1]);
        var b = int.Parse(spl[2]);
        var n = int.Parse(spl[3]);

        long co = 0;
        for(int i=0; i <= n; i++) {
            for(int j=0; j <= n; j++) {
                var len = r * i + g * j;
                if (len > n) continue;
                if((n-len) % b == 0) co++;
            }
        }

        return co;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
double ed(pair<int,int> a,pair<int,int> b)
{
  return sqrt(double((a.first-b.first)*(a.first-b.first) + (a.second-b.second)*(a.second-b.second)));
}
double dist(vector<pair<int,int>> &v,vector<int> &p)
{
  double sum=0.0;
  for(int i=0;i<p.size()-1;i++)
    sum += ed(v[p[i]],v[p[i+1]]);
  return sum;
}
int main()
{
  int n;
  vector<int> p;
  cin>>n;
  vector<pair<int,int>> v(n);
  for(auto &i:v)
    cin>>i.first>>i.second;
  p.resize(n);
  for(int i=0;i<n;i++)
    p[i]=i;
  double k=0.0,sum=0.0;
  do
  {
    sum += dist(v,p);
    k+=1.0;
  }while(next_permutation(p.begin(),p.end()));
  cout.precision(17);
  cout<<fixed<<(sum)/(k)<<"\n";       
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
    S.append(input())
T = {}
for i in range(N):
  if S[i] in T:
    T[S[i]] += 1
  else:
    T.setdefault(S[i],1)
A = max(T.values())

keys = [k for k, v in T.items() if v == A]
U =sorted(keys)

for i in range(len(U)):
  print(U[i])

Measured memory_bytes: 35220
#include<bits/stdc++.h>
using namespace std;
double a=0;
int n,k;
double ll(int x)
{
	double b=1;
	int c=1;
	while(c<x)
	{
		c*=2;
		b/=2;
	}
	return b;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
	//	cout<<b<<endl;
		a+=ll((k+i-1)/i);
		//cout<<a<<endl;
	}
	printf("%.12lf\n", a/n);
	return 0;
}


Measured memory_bytes: 256
s = input()
flag = [0] * 4
for i in range(len(s)):
  if s[i] == "N":
    flag[0] = 1
  elif s[i] == "S":
    flag[1] = 1
  elif s[i] == "W":
    flag[2] = 1
  else:
    flag[3] = 1
if flag[0] == flag[1] and flag[2] == flag[3]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 8988
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N, M = map(int, input().split())
keys = []
for _ in range(M):
    a, _ = map(int, input().split())
    key_set = set(map(int, input().split()))
    key_bin = 0
    for c in key_set:
        key_bin += (2**(c-1))
    keys.append([a, key_bin])


N_bin = 2**N
# i番目までのkeyで
dp = [[float('inf')]*N_bin for _ in range(2)]
dp[0][0] = 0
for key in range(M):  # 新加えるkey
    key_val, key_set = keys[key]
    for bit in range(N_bin):  # 加える前の状態
        dp[(key+1) % 2][bit] = min(dp[(key+1) %
                                      2][bit], dp[key % 2][bit])  # くわえない
        dp[(key+1) % 2][bit | key_set] = min(dp[(key+1) % 2][bit | key_set],
                                             dp[key % 2][bit]+key_val)  # 加える
ans = float('inf')
for c in range(2):
    ans = min(ans, dp[c][-1])
if ans == float("inf"):
    ans = -1
print(ans)


Measured memory_bytes: 49884
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

struct segtree{
    vector<int> d;
    int n;
    segtree(int n_){
        n=1;
        while(n<n_)n*=2;
        d.resize(2*n-1,0);
    }
    //k番目をaにアップデート
    void update(int k,int a){
        k += n-1;
        d[k] = a;
        while(k>0){
            k = (k-1)/2;
            d[k] = max(d[k*2+1],d[k*2+2]);
        }
    };
    int query(int a, int b,int k,int l,int r){
        if(r<=a||b<=l) return 0;
        if(a<=l&&r<=b) return d[k];
        else{
            int vl = query(a,b,k*2+1,l,(l+r)/2);
            int vr = query(a,b,k*2+2,(l+r)/2,r);
            return max(vl,vr);
        }
    };
    int sgmax(int a,int b){
        return query(a,b,0,0,n);
    };
};

int main(){
    int n,k;
    cin >> n >> k;
    segtree st(500010);
    rep(i,n){
        int a;
        cin >> a;
        int b = st.sgmax(max(0,a-k), min(a+k+1,500010));
        st.update(a, b+1);
    }
    int ans = st.sgmax(0,500010);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7496
#include<stdio.h>

int main(){
	int i,j;
	int w,n,a,b,temp;
	int num[100];
	
	scanf("%d %d",&w,&n);
	
	for(i=1;i<w+1;i++){
		num[i]=i;
	}

	for(i=0;i<n;i++){
		scanf("%d,%d",&a,&b);
		temp = num[a];
		num[a] = num[b];
		num[b] = temp;
	}
	
	for(i=1;i<w+1;i++){
		printf("%d\n",num[i]);
	}

	return 0;
}

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

using namespace std;

int main(){
    
    int n;
    while(cin >> n && n)
    {
    	int data[100000]={};
    	for(int i=0;i<n;i++)cin >> data[i];

    	for(int i=0;i<n;i++)
    	{
    		for(int j=i;j<n;j++)
    		{
    			if(data[i]>data[j])
    				swap(data[i],data[j]);
    		}
    	}

    	unsigned long long sum=0;
    	int set=n-1;
    	for(int i=0;i<n-1;i++,set--)
    	{	
    		sum+=set*data[i];
    	}

    	cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1548
#include<bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
ll fast_pow( ll a , ll b , ll m )
{
 
    ll res=1;
    while(b>0)
    {
        if(b&1) res =  (res*a)%m;
        a=(a*a)%m;
        b=b/2;
    }
    return res;
}
 
template <typename T,typename U>                                                   
std::pair<T,U> operator-(const std::pair<T,U> & l,const std::pair<T,U> & r) {   
    return {l.first-r.first,l.second-r.second};                                    
} 
 
template <typename T,typename U>                                                   
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {   
    return {l.first+r.first,l.second+r.second};                                    
} 
 
const ll maxn = 1000000;
const int inf = 0x3f3f3f;
const ll MOD = 1e9+7LL;
int ns;

ll lcm(ll a , ll b)
{
    return (a*b)/__gcd(a ,b);
}

/*
    java implementation of highestOneBit and NumberOfTrailingZeroes
*/

ll highestOnebit(ll x)
{
    x |= (x>>1);
    x |= (x>>2);
    x |= (x>>4);
    x |= (x>>8);
    x |= (x>>16);
    x |= (x>>32);
    
    return x-((unsigned ll)x>>1);
}   

int numberOfTrailingZeros(ll i)
{
    if (i == 0) return 64;
    ll x = i;
    ll y;
    int n = 63;
    y = x << 32; if (y != 0) { n -= 32; x = y; }
    y = x << 16; if (y != 0) { n -= 16; x = y; }
    y = x <<  8; if (y != 0) { n -=  8; x = y; }
    y = x <<  4; if (y != 0) { n -=  4; x = y; }
    y = x <<  2; if (y != 0) { n -=  2; x = y; }
    return (int) (n - ((unsigned ll)(x << 1) >> 63));
}


vector<int> parent;
vector<int> depth;
vector<vector<int>> adj;
vector<bool> vis;
vector<int> tin;
vector<int> tout;
int T = 0;

void dfs(int u , int d)
{
    tin[u] = T++;
    depth[u]=d;
    vis[u]=true;
    for(auto v : adj[u])
    {
        if(!vis[v])
        {
            dfs(v , d+1);
            parent[v]=u;
        }
    }    
    tout[u]=T++;
}


int main()
{
    // freopen( "input.txt" , "w" , stdout );
    
    
 
    srand(time(0));
    // Using time point and system_clock 
    std::chrono::time_point<std::chrono::system_clock> start, end; 
  
    start = std::chrono::system_clock::now(); 
 
 
    //------- INPUT GENERATION ------
 
    // cout<<200000<<endl;
 
    //------- /INPUT GENERATION ------

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

    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
          


    

   
    // cout<<endl;
    // end = std::chrono::system_clock::now(); 
  
    // std::chrono::duration<double> elapsed_seconds = end - start; 
    // std::time_t end_time = std::chrono::system_clock::to_time_t(end); 
  
    // std::cout << "finished computation at " << std::ctime(&end_time) 
    //           << "elapsed time: " << elapsed_seconds.count() << "s\n"; 
 
 
 
 
}

Measured memory_bytes: 256
def cmb(n, r):#コンビネーション(mod)の高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 5*10**5 #Nの最大値
g1 = [0]*(N+1) #元テーブル(p(n,r))
g1[0] = g1[1] = 1
g2 = [0]*(N+1) #逆元テーブル
g2[0] = g2[1] = 1
inverse = [0]*(N+1) #逆元テーブル計算用テーブル
inverse[0],inverse[1] = 0,1
for i in range(2,N+1):
    g1[i] = (g1[i-1] * i) % mod
    inverse[i] = (-inverse[mod % i] * (mod//i)) % mod
    g2[i] = (g2[i-1] * inverse[i]) % mod

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

# 0の数がi個の場合の数
dp = [0]*(n+1)
# 残りn-i種類にi個を割り振る　×　0がi個の場合の数 -> n-1Ci * nCi
for i in range(n+1):
    dp[i] = cmb(n-1,i) * cmb(n,i) % mod

if k == 1:
    ans = dp[1]
else:
    k = min(n,k)
    ans = 0
    for i in range(k+1):
        ans += dp[i]
        ans %= mod
print(ans)

Measured memory_bytes: 100784
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<functional>
#include<climits>

//  scan & print

#define sf scanf
#define pf printf
#define sf1(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c);


#define pro printf("1\n")
#define pcase(kase) printf("Case %d: ",kase)

// constants

#define infinity 9999999

using namespace std;

int kase=1;

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

int ddx[]={1,1,0,-1,-1,-1,0,1};
int ddy[]={0,1,1,1,0,-1,-1,-1};

int GCD(int A,int B)
{
    if(!B)
        return A;
    return GCD(B,A%B);
}

int main()
{
    int  n;
    sf1(n);
    int ara[n+5];
    for(int i=0;i<n;i++)
    {
        sf1(ara[i]);
    }
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        int mini=i;
        for(int j=i;j<n;j++)
        {
            if(ara[j]<ara[mini])
            {
                mini=j;
            }
        }
        if(i!=mini)
        {
            swap(ara[i],ara[mini]);
            cnt++;
        }
    }
    pf("%d",ara[0]);
    for(int i=1;i<n;i++)
    {
        pf(" %d",ara[i]);
    }
    pf("\n");
    pf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(ll arg_num,ll arg_count,ll arg_min_mult,ll arg_max_mult){
		num = arg_num;
		count = arg_count; //N個の数のうち、いくつの数が持っているか
		min_mult = arg_min_mult;
		max_mult = arg_max_mult;
	}
	ll num,count,min_mult,max_mult;
};

ll N,M;
vector<Info> A,B;


int main(){

	ll tmp;

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

	A.push_back(Info(1,N,1,1)); //1はAの共通約数の1つ
	B.push_back(Info(1,M,1,1));

	ll loc,tmp_count;

	//★★A:公約数が知りたいので、N個すべてに共通する素因数を求める★★
	for(int i = 0; i < N; i++){

		scanf("%lld",&tmp);

		for(ll k = 2; k*k <= tmp; k++){ //入力を素因数に分解する

			if(tmp%k != 0)continue;

			loc = -1;

			for(int a = 0; a < A.size(); a++){ //既出の数か調べる

				if(A[a].num == k){
					A[a].count += 1;
					loc = a;
					break;
				}
			}

			//次数を数える
			tmp_count = 0;

			while(tmp%k == 0){
				tmp /= k;
				tmp_count++;
			}

			if(loc == -1 && i == 0){ //初出現かつ、最初の数字

				A.push_back(Info(k,1,tmp_count,0));

			}else if(loc != -1){

				A[loc].min_mult = min(A[loc].min_mult,tmp_count); //次数のminを取る

			}else{

				//N個全部に共通する素因数でなければ意味がないのでDo nothing
			}
		}

		if(tmp == 1)continue;

		//1にならなかった場合
		loc = -1;

		for(int a = 0; a < A.size(); a++){ //既出の数か調べる

			if(A[a].num == tmp){
				A[a].count += 1;
				loc = a;
				break;
			}
		}

		if(loc != -1 || i != 0)continue;

		A.push_back(Info(tmp,1,1,1));
	}

	//★★B:最小公倍数が知りたいので、少なくとも1つに出現する素因数を洗い出し、次数のmaxを取る★★
	for(int i = 0; i < M; i++){

		scanf("%lld",&tmp);

		for(ll k = 2; k*k <= tmp; k++){ //入力を素因数に分解する

			if(tmp%k != 0)continue;

			loc = -1;

			for(int b = 0; b < B.size(); b++){ //既出の数か調べる

				if(B[b].num == k){
					loc = b;
					break;
				}
			}

			//次数を数える
			tmp_count = 0;

			while(tmp%k == 0){
				tmp /= k;
				tmp_count++;
			}

			if(loc == -1){ //初出現

				B.push_back(Info(k,1,0,tmp_count));

			}else{ //既出

				B[loc].max_mult = max(B[loc].max_mult,tmp_count); //次数のmaxを取る

			}
		}

		if(tmp == 1)continue;

		//1にならなかった場合
		loc = -1;

		for(int b = 0; b < B.size(); b++){ //既出の数か調べる

			if(B[b].num == tmp){
				loc = b;
				break;
			}
		}

		if(loc != -1)continue;

		B.push_back(Info(tmp,1,1,1));

	}

	ll ans = 1;
	bool FLG;

	//少なくともxは、Bの全ての素因数を持ち、かつ各々の次数がmax以上
	for(int i = 0; i < B.size(); i++){ //Bの少なくとも1つ出現した素因数を全探索

		FLG = false;

		for(int k = 0; k < A.size(); k++){ //Aを全探索

			if(A[k].num == B[i].num && A[k].count == N && A[k].min_mult >= B[i].max_mult){

				ans *= (A[k].min_mult-B[i].max_mult+1);

				FLG = true;
				break;
			}
		}

		if(!FLG){

			printf("0\n");
			return 0;
		}
	}

	//Aのみにあり、Bにない素因数を探す
	for(int i = 0; i < A.size(); i++){

		if(A[i].count < N)continue;

		FLG = false;

		for(int k = 0; k < B.size(); k++){

			if(B[k].num == A[i].num){

				FLG = true;
				break;
			}
		}

		if(FLG)continue;

		ans *= (A[i].min_mult+1);
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

ll n,m;
vector<pair<ll, ll>> ab;

void input(){
    cin >> n >> m;
    ab.resize(n);
    for(int i=0;i<n;i++){
        ll x, y;
        cin >> x >> y;
        ab[i] = make_pair(x, y);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    sort(ab.begin(), ab.end(), [](const auto& x, const auto& y){return x.first < y.first;});
    ll cnt = 0; //bの合計
    ll ans = 0; //aの合計
    int i = 0;
    while(cnt < m){
        ans += ab[i].first * ab[i].second;
        cnt += ab[i].second;
        i++;
    }
    ll tmp = cnt - m;
    ans -= (tmp * ab[i-1].first);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int hour1 = sc.nextInt() * 60 + sc.nextInt(); //Time From
    	int hour2 = sc.nextInt() * 60 + sc.nextInt(); //Time To
      	int study = sc.nextInt(); //Study Time
      
      	//起きている時間
      	int time = hour2 - hour1;
      
      	//Study Time 
      	if (time - study >= 0) {
      		System.out.println(time - study);
        }
      	else {
      		System.out.println(0);
        }
    }
}

Measured memory_bytes: 35772
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  																						   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;	
const int mod = 1e9+7;																							   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra																													   																				   list<int>::iterator it;																								   
																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS//////////////////////////////////////////////////////


///////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int a, b;
	cin >> a >> b;
	cout << a + (b / 2) << endl;
	
	

						
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    ll N, K; cin >> N >> K;
    vector<ll> accum(N+1, 0);

    for(int i=1; i<=N; i++){
        ll a; cin >> a;
        accum[i] = accum[i-1] + a;
    }

    ll ans = 0;
    ll t = 1LL;
    for(int i=0; i<40; i++) t *= 2;

    for(int i=0; i<41; i++){
        ll cnt = 0;

        for(int j=1; j<=N; j++){
            for(int k=j; k<=N; k++){
                ll btf = accum[k]-accum[j-1];
                if(((ans + t)&btf) == (ans + t)) cnt++;
            }
        }

        if(cnt >= K) ans += t;
        t /= 2;
    }

    cout << ans << endl;
}

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

int a,b;
int main()
{
cin>>a>>b;
if(a==0 && b==0) 
{
	cout<<0;
	return 0;
}
else
{
	a--;
	b--;
}
    cout<<a*b;
	
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            if(S == "Sunny")
            {
                Console.WriteLine("Cloudy");
            }
            else if (S == "Cloudy")
            {
                Console.WriteLine("Rainy");
            }
            else
            {
                Console.WriteLine("Sunny");
            }
        }
    }
}


Measured memory_bytes: 25728
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int N;

int main() {
  cin >> N;

  for (int i = 0; i <= (N/4); ++i) {
    for (int j = 0; j <= (N/7); ++j) 
      if (N == i*4+ j*7)  {
        cout << "Yes" << endl;
        return 0;
      }
  }

  cout << "No" << endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++){
    cin >> L.at(i);
  }
  sort(L.begin(), L.end());
  reverse(L.begin(), L.end());
  int count = 0;
  for (int i = 1; i < N; i++){
    count += L.at(i);
  }
  if ( L.at(0) < count) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

x, y, a, b, c = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
p = sorted(p, reverse=True)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)

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

p_and_q = p + q

import heapq

heapq.heapify(p_and_q)

while r:
    temp = max(heapq.heappop(p_and_q), r.pop())
    heapq.heappush(p_and_q, temp)

print(sum(p_and_q))
    

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  vector<int> p(13);
  p[0] = 12;
  for(int i = 1; i < 13; i++){
    p[i] = i-1;
  }

  int a, b;
  cin >> a >> b;
  a--;
  b--;
  if(p[a] < p[b]){
    cout << "Bob" << endl;
  }else if(p[a] > p[b]){
    cout << "Alice" << endl;
  }else{
    cout << "Draw" <<endl;
  }

  return 0;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    F = [list(map(int, input().split())) for _ in range(N)]
    P = [list(map(int, input().split())) for _ in range(N)]
    
    ans = -10 ** 9
    for s in range(1, 1 << 10):
        benefit = 0
        for i in range(N):
            cnt = 0
            for j in range(10):
                if s >> j & 1 and F[i][j] == 1:
                    cnt += 1
            benefit += P[i][cnt]
        ans = max(ans, benefit)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 40944
N, A = map(int, input().split())
x = list(map(int, input().split()))
dp = [[[0 for i in range(N*A+1)] for j in range(N+1)] for k in range(N+1)]
dp[0][0][0] = 1


for i in range(N):
    for j in range(N*A+1):
        for k in range(N):
 #i個の整数のうちk個使ってjにする場合の数
            if x[i] > j:
                dp[k][i+1][j] = dp[k][i][j]
            else:
                dp[k+1][i+1][j] = dp[k][i][j - x[i]] + dp[k+1][i][j]

ans = 0
for i in range(1, N + 1):
    ans += dp[i][N][A * i]
print(ans)


Measured memory_bytes: 95964
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.Stack;

public class Main {

     static Scanner scanner;

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

         int N=gi();
         long[] L=new long[N];
         for(int i=0; i<N; i++) {
        	 L[i]=gl();
         }

         Arrays.parallelSort(L);

         Stack<Long> l=new Stack<Long>();
         for (int i=1; i<N; i++) {
        	 for(int j=0; j<i; j++) {
        		 l.add(L[i]+L[j]);
        	 }
         }
         Collections.sort(l);
         long c=0;
         for (int i=N-1; i>=2; i--) {
        	 for(int j=0; j<i; j++) {
        		 l.pop();
        	 }

        	 int li=-1;
        	 int ri=l.size();
        	 while(ri-li>1) {
        		 int ind=(li+ri)/2;
        		 if(L[i]<l.get(ind)) {
        			 ri=ind;
        		 } else {
        			 li=ind;
        		 }
        	 }
        	 c+=l.size()-li-1;
         }

         System.out.println(c);
     }


     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 112340
#include <iostream>

using namespace std;

typedef long long ll;

int n;

int dfs(int bit, ll num) {
    int ret = 0;
    if (bit == 7) ret = 1;

    if (10 * num + 3 <= n) ret += dfs(bit | 1, 10 * num + 3);
    if (10 * num + 5 <= n) ret += dfs(bit | 2, 10 * num + 5);
    if (10 * num + 7 <= n) ret += dfs(bit | 4, 10 * num + 7);

    return ret;
}

int main() {
    cin >> n;
    cout << dfs(0, 0) << endl;
}

Measured memory_bytes: 256
l,r = map(int, input().split())

min = 2019
diff = r-l+1

if diff > 2019:
  diff = 2019

for i in range(diff):
  for j in range(diff):
    if j > i:
      total = (i+l)*(j+l)
      if total > 2019:
        mod = total % 2019
        if min > mod:
           min = mod
      else:
        if min > total:
          min = total
print(min)

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
using namespace std;
char s[105][105];
int  a[100],c[100];
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s[i]+1);
	}
	if(n==1&&m==1)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		a[s[i][j]-'a'+1]++;
	}
	for(int i=1;i<=26;i++)
	{	
		a[i]%=4;
		c[a[i]]++;
	}
	if((n*m)%2==0&&(c[1]||c[3]))
	{
		cout<<"No"<<endl;
		return 0;
	}
	if(n%2==0&&m%2==0&&c[2])
	{
		cout<<"No"<<endl;
		return 0;
	}
	if(c[1]>1||c[3]>1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	if((n%2==0&&m%2==1)||(n%2==1&&m%2==0))
	{
		if((n%2==0&&m%2==1)&&(c[2]*2>n||c[2]*2==n-2))
		{
			cout<<"No"<<endl;
			return 0;
		}
		if((m%2==0&&n%2==1)&&(c[2]*2>m||c[2]*2==m-2))
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	if(n%2==1&&m%2==1)
	{
		if(c[1]=0&&c[3]==0)
		{
			cout<<"No"<<endl;
			return 0;
		}
		if(c[1]>0&&c[3]>0)
		{
			cout<<"No"<<endl;
			return 0;
		}
		if(c[3]>0)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
 
#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
 
const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);
 
template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}
 
struct Law {
	int G;
	vector<int> S;
};
 
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N, E, T;
	cin >> N >> E >> T; --T;
	vector<int> W(N); cin >> W;
	vector<Law> law;
	REP(i, E) {
		int G, C; cin >> G >> C; --G;
		vector<int> S(C); cin >> S;
		REP(i, C) S[i]--;
		law.pb( (Law){G, S} );
	}
	vector<int> dp(N, inf);
	REP(i, N) {
		if (W[i] == 1) {
			dp[i] = 1;
		}
	}
	REP(i, E) REP(j, E) {
		int M = 0, m = inf;
		vector<int> a(law[j].S.size());
		REP(k, law[j].S.size()) {
			int id = law[j].S[k];
			a[k] = dp[id];
		}
		sort( ALL(a), greater<int>() );
		int c = 1;
		REP(i, a.size()) {
			c = max(c, a[i]+(int)i);
		}
		if (c < dp[law[j].G]) {
			dp[law[j].G] = c;
		}
	}
	if (dp[T] == inf) cout << -1 << endl;
	else cout << dp[T] << endl;
}

Measured memory_bytes: 3224
N = int(input())
a = list(map(int,input().split()))

def minimize(list):
    min = 1000000
    for i in range(-100,101):
        num = 0
        for j in range(len(list)):
            num = num + (int(list[j]) - i)**2
        if min >= num:
            min = num
    return min

print(minimize(a))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n,m,a,b,c;
	string str;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>str;
	x[str[0]]++;
	x[str[1]]++;
	x[str[2]]++;
	x[str[3]]++;
	if(x[str[0]]==2&&x[str[1]]==2&&x[str[2]]==2&&x[str[3]]==2){
		cout<<"Yes";
	}else{cout<<"No";}

	cout<<endl;
} 


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

P GetPair(int i)
{
    int a = i %10;
    int b = 0;

    while(i){
        b = i;
        i /= 10;
    }
    return P(a,b);
}

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

    map<P,int> freq;
    for(int i = 1; i <= n ; ++i){
        P p = GetPair(i);
        freq[p]++;
    }
    ll ans =0;
    for(int i = 1; i <= n ; ++i){
        P p = GetPair(i);
        //ペアを探すために入れ替える
        P q(p.second, p.first);
        ans += freq[q];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
  int n;  cin>>n;
  vector<int> v(n);
  int cnt=0;
  rep(i,0,n)  cin>>v[i], v[i]--;
  rep(i,0,n-1){
    if(v[i]==i){
      swap(v[i], v[i+1]);
      cnt++;
    }
  }
  if(v.back()==n-1) cnt++;

  cout<<cnt<<endl;
  return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

// ?????????????????§???
template<class T>
struct SlideQ{
  int M, iter;
  deque<pair<int,T>> q;
  SlideQ(int M): M(M), iter(0)
  {
  }

  bool empty() const{
	return q.empty();
  }
  
  void push(const T& x){
	while(!q.empty() && q.front().FF <= iter-M)
	  q.pop_front();
	while(!q.empty() && q.back().SS <= x)
	  q.pop_back();
	q.push_back(MP(iter++, x));
  }

  T top() const{
	return q.front().SS;
  }
};

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

  int N, W; cin >> N >> W;
  vector<pair<PII,int>> xs(N);
  REP(i,N){
	int v, w, m;
	cin >> v >> w >> m;
	xs[i] = MP(MP(v,w), m);
  }

  LL dp[2][10001];
  fill((LL*)dp, (LL*)dp+2*10001, 0);
  int crt = 0, nxt = 1;
  for(auto&& x: xs){
	REP(w,W+1)  dp[nxt][w] = dp[crt][w];

	for(int b=0;b<x.FF.SS;++b){
	  SlideQ<LL> sq(x.SS+1);
	  for(int j=0;b+j*x.FF.SS<=W;++j){
		LL val = dp[crt][b+j*x.FF.SS] - j*x.FF.FF;
		sq.push(val);
		maxi(dp[nxt][b+j*x.FF.SS], sq.top() + j*x.FF.FF);
	  }
	}
	
	swap(crt, nxt);
  }

  cout << *max_element(dp[crt], dp[crt]+W+1) << endl;

  return 0;
}

Measured memory_bytes: 3476