jiahuimbzuai/CoQuIR huggingface dataset:
//  [rust]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let a: usize = read!();
    let b: usize = read!();
    let c: usize = read!();

    let ans = if a == b && b == c { "Yes" } else { "No" };
    println!("{}", ans);
}
//  [rust]
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();
    let c: usize = iterator.next().unwrap().parse().unwrap();

    if a == b && b == c && c == a {
        return "Yes".to_string();
    }

    return "No".to_string();
}
//  [rust]
fn main() {
    proconio::input! {
    a:[usize;3],
    }
    println!("{}",if a[0]==a[2]&&a[2]==a[1]{"Yes"}else{"No"})
}
//  [typescript]
const p = (...args) => {
  process.env.NODE_ENV === "test" ? console.log(...args) : ""
}

const solve = (input) => {
  const [a, b, c] = input.split(" ").map(Number)

  return a == b && b == c ? "Yes" : "No"
}

if (process.env.NODE_ENV === "test") {
  module.exports = (input) => solve(input.trim())
} else {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(solve(input.trim()))
}
//  [typescript]
// inputに入力データ全体が入る
function Main(input) {
	const temp = input.split(" ").map(x => +x)
	console.log(temp[0] == temp[1] && temp[1] == temp[2] && temp[0] != 0 ? "Yes" : "No")
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [python]
import sys
input = sys.stdin.readline
def main():
  L=list()
  R=list()
  a,b=map(int,input().split())
  for i in range(b):
    c,d=input().split()
    c=int(c)
    if d=="AC":
      L.append(c)
    elif d=="WA":
      if c not in L:
        R.append(c)
  L=set(L)
  t=len(L)
  P=[1 for i in R if i in L]
  s=sum(P)
  print(t,s)
main()
//  [python]
import numpy as np
N, M = map(int, input().split(' '))
suc_list = np.zeros(N, dtype=np.uint8)
fai_count = np.zeros(N, dtype=np.int32)
for i in range(M):
    p, s = input().split(' ')
    p = int(p) - 1
    if suc_list[p] == 0:
        if s == 'WA':
            fai_count[p] += 1
        else:
            suc_list[p] = 1

print('{} {}'.format(np.sum(suc_list), np.sum(fai_count[suc_list == 1])))
//  [python]
import numpy as np
N, M = map(int, input().split())
d = np.array([0]*(N+1), dtype = 'int32')
t = 0
f = 0
for i in range(M):
    tmp = input().split()
    p = int(tmp[0])
    S = tmp[1]
    if S == 'AC':
        if d[p] != -1:
            f += d[p]
            d[p] = -1
            t += 1
    elif d[p] != -1:
        d[p] += 1
print(t, f)
//  [java]
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.nextLine();
        Set<Integer> acList = new HashSet<>();
        Map<Integer, Integer> waMap = new HashMap<>();
        for (int i = 0; i < m; i++){
            int q = sc.nextInt();
            String r = sc.next();
            if(!acList.contains(q)) {
                if (r.equals("AC")) {
                    acList.add(q);
                } else {
                    waMap.put(q, waMap.getOrDefault(q, 0) + 1);
                }
            }
            sc.nextLine();
        }
        System.out.println(acList.size() + " " + acList.stream().mapToInt(q -> waMap.getOrDefault(q, 0)).sum());
    }
}
//  [java]
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        Map<Integer, Map<String,Integer>> submit = new TreeMap<>();
        for (int i = 1; i <= N; i++){
            submit.put(i, new HashMap<>());
            submit.get(i).put("AC",0);
            submit.get(i).put("WA",0);
        }

        int M = sc.nextInt();
        int AC = 0;
        int WA = 0;
        for (int i = 0; i < M; i++){
            int p = sc.nextInt();
            String S = sc.next();
            if (submit.get(p).get("AC") == 0) {
                if (S.equals("AC")) {
                    submit.get(p).put("AC", 1);
                    AC++;
                    WA += submit.get(p).get("WA");
                } else {
                    int count = submit.get(p).get("WA");
                    submit.get(p).put("WA", count + 1);
                }
            }
        }
        System.out.print(AC + " " + WA);
    }
}
//  [cpp]
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define mp make_pair
#define F(i, a, n, b) for(int i=a;i<n;i+=b)
#define REVF(i, a, b, c) for(int i=a;i>=b;i-=c)
#define REP(i, n) F(i, 0, n, 1)
#define REP1(i, n) F(i, 1, n+1, 1)
#define REV(i, n) REVF(i, n, 0, 1)
#define PTR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define MOD 1000000007

typedef unsigned long long ll;

const int MAX = 1e6 + 5;

int n,m,p,cor=0,wrn=0;
set<int> v;
string s;
map<int,bool> c;
map<int,int> pen;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	REP(i,MAX){
		c[i] = 0;
	}
	cin>>n>>m;
	REP(i,m){
		cin>>p>>s;
		v.insert(p);
		if(s == "AC" && !c[p]){
			c[p] = 1;
			cor++;
		}
		else if(s == "WA" && !c[p])
			pen[p]++;
	}
	PTR(it,v){
		if(c[*it])
			wrn += pen[*it];
	}
	cout<<cor<<' '<<wrn;

	return 0;
}
//  [cpp]
#include <iostream>
#include <vector>
#include <unordered_map>
#include <exception>

typedef long long ll;
using namespace std;

int main(){
  ll n, m;
  std::cin >> n >> m;

  vector<ll> p(m);
  vector<string> s(m);
  for(ll i=0; i<m; i++){
    std::cin >> p[i];
    std::cin >> s[i];
  }

  unordered_map<ll, pair<ll,ll> > counter;
  for(ll i=0; i<m; i++){
    try{
      if( 0 == counter.at(p[i]).first ){
        if( s[i] == "WA" ) counter.at(p[i]).second += 1;
        else counter.at(p[i]).first += 1;
      }
    }catch(exception e){
      counter[p[i]] = make_pair(0,0);
      if( s[i] == "AC" ) counter[p[i]].first += 1;
      else counter[p[i]].second += 1;
    }
  }
  long long ansAC = 0, ansWA = 0;
  unordered_map<ll, pair<ll,ll> >::iterator iter = counter.begin();
  for(; iter != counter.end(); iter++){
    if(iter->second.first){
      ansAC += iter->second.first;
      ansWA += iter->second.second;
    }
  }
  std::cout << ansAC << ' ' << ansWA << '\n';
  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll m; cin >> m;
    vector <bool> ac(n, false);
    vector <ll> wa(n, 0);
    REP(i, m){
        ll p; cin >> p; p--;
        string s; cin >> s;
        dump(p)
        dump(s)
        if (ac[p]){
            continue;
        }
        if (s == "AC"){
            ac[p] = true;
        } else {
            wa[p]++;
        }
    }
    ll acs = 0;
    REP(i, n){
        acs += ac[i];
    }
    cout << acs << " ";
    ll was = 0;
    REP(i, n){
        was += wa[i] * ac[i];
    }
    cout << was << endl;
    return 0;
}
//  [c]
#include <stdio.h>
int main(){
  int n,m,i,p;
  int ac[100005]={0},wa[100005]={0};
  int WA=0,AC=0;
  char s[3];
  scanf("%d%d", &n,&m);
  for(i=0; i<m; i++){
    scanf("%d",&p);
    scanf("%s",s);
    if(ac[p]==1)
      continue;
    else if(s[0] == 'A')
      {
      WA += wa[p];
      ac[p]++;
      AC++;
      }
    else
      wa[p]++;
  }
  printf("%d %d", AC,WA);
  return 0;
}
//  [c]
#include <stdio.h>
int main(void)
{
    int n ,m,p,i,AC = 0,WA = 0,ac[100008] ={0},wa[100008] = {0};
    char s[3];
    scanf("%d%d",&n,&m);
    for(i = 0 ; i < m ; i++)
    {
        scanf("%d %s",&p,s);
        if(ac[p] == 1)
        {
            continue;
        }
        else if(s[0] == 'A')
        {
            AC++;
            ac[p]++;
            WA += wa[p];

        }
        else
        {
            wa[p]++;
        }
    }
    printf("%d %d\n",AC,WA);
        return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
  int N,M;
  int i;
  char S[100010][3];
  int p[100010];
  int w[100010]={0};
  int pen[100010]={0};
  int ans=0;
  int pe=0;
  scanf("%d %d",&N,&M);
  for(i=0;i<M;i++){
    scanf("%d %s",&p[i],S[i]);
    if(S[i][0]=='W'){
      if(w[p[i]]==0){
        pen[p[i]]++;
      }
    }
    else if(S[i][0]=='A'){
      if(w[p[i]]==0){
        ans=ans+1;
      }
      w[p[i]]=1;
    }
  }
  for(i=0;i<=N;i++){
    if(w[i]==0){
      pen[i]=0;
    }
    pe=pe+pen[i];
  }
  printf("%d %d\n",ans,pe);
  return 0;
}
//  [javascript]
function Main(input) {
    var firstLine = input[0].split(/\s/);
    var N = parseInt(firstLine[0], 10);
    var M = parseInt(firstLine[1], 10);
    var PS = input.slice(1).map(ps => {
        var psArray = ps.split(/\s/);
        psArray[0] = parseInt(psArray[0], 10);
        return psArray;
    });

    var ACList = new Array(N);
    ACList.fill(0);
    var WAList = new Array(N);
    WAList.fill(0);

    for (var i = 0; i < M; i++) {
        if (ACList[PS[i][0] - 1] === 0) {
            if (PS[i][1] === 'AC') {
                ACList[PS[i][0] - 1] = 1;
            } else {
                WAList[[PS[i][0] - 1]]++;
            }
        }
    }

    var AC = 0;
    var WA = 0;
    for (var i = 0; i < ACList.length; i++) {
        AC += ACList[i];
        WA += ACList[i] === 1 ? WAList[i] : 0;
    }

    console.log(`${AC} ${WA}`);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));
//  [javascript]
"use strict";
const fs = require('fs');
let input = fs.readFileSync(0).toString().split("\n").map((a) => a.split(" "));
const n = parseInt(input[0][0]);
const m = parseInt(input[0][1]);
const complete = Array(n).fill(false);
let correct = 0;
let penalties = 0;
const penaltiesDict = {};
input.slice(1).forEach((a) => {
	if (complete[parseInt(a[0]) - 1]) {
		return;
	}
	if (a[1] === "AC") {
		complete[parseInt(a[0]) - 1] = true;
		correct++;
		penalties += penaltiesDict[a[0]] || 0;
		delete penaltiesDict[a[0]];
		return;
	}
	if (typeof penaltiesDict[a[0]] === 'undefined') {
		penaltiesDict[a[0]] = 0;
	}
	penaltiesDict[a[0]]++;
});
console.log(correct + " " + penalties);
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n, m int32
	fmt.Scanf("%d %d", &n, &m)

	a := make([]string, n)
	for i := int32(0); i < m; i++ {
		var pi int32
		var si string
		fmt.Scanf("%d %s", &pi, &si)
		if si == "AC" {
			a[pi-1] += "A"
		} else if si == "WA" {
			a[pi-1] += "W"
		}
	}

	cn := int32(0)
	pn := int32(0)
	for _, v := range a {
		tc, tp := count(v)
		cn += tc
		pn += tp
	}
	fmt.Println(cn, pn)
}

func count(s string) (int32, int32) {
	p := int32(0)
	for _, v := range s {
		if string(v) == "A" {
			return int32(1), p
		} else if string(v) == "W" {
			p++
		}
	}
	return int32(0), int32(0)
}
//  [go]
package main

import (
	"fmt"
)

var n, m int

type ans struct {
	p int
	s string
}

type seiseki struct {
	pneCount int
	isAC     bool
}

func main() {
	fmt.Scan(&n)
	fmt.Scan(&m)

	ss := make(map[int]*seiseki)
	for i := 0; i < m; i++ {
		a := new(ans)
		fmt.Scan(&a.p)
		fmt.Scan(&a.s)

		if _, ok := ss[a.p]; !ok {
			ss[a.p] = &seiseki{}
		}
		if ss[a.p].isAC {
			continue
		}
		if a.s == "AC" {
			ss[a.p].isAC = true
		}
		if a.s == "WA" {
			ss[a.p].pneCount++
		}
	}

	account := 0
	wacount := 0
	for _, mm := range ss {
		if mm.isAC {
			account++
			wacount += mm.pneCount
		}
	}

	fmt.Printf("%d %d", account, wacount)
}
//  [go]
package main

import "fmt"

func main() {
	// Code for C - Welcome to AtCoder
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	var p int
	var S string
	temp := make(map[int]int, N)
	ans := make(map[int]int, N)
	for i := 0; i < M; i++ {
		fmt.Scanf("%d %s", &p, &S)
		if S == "WA" {
			temp[p]++
		} else {
			if ans[p] == 0 {
				ans[p] = temp[p] + 1
			}
		}
	}

	var count int
	for _, v := range ans {
		count += v - 1
	}

	fmt.Println(len(ans), count)
}
//  [ruby]
n,m=gets.split.map(&:to_i)
sp=[]
m.times{x=gets.chomp.split;sp<<[x[0].to_i,x[1]]}
i=0
sp.sort_by!{|a|[a[0],i+=1]}
i=p=q=r=0
c=false
sp.each{|a|
  if a[0]==i
    if c
    elsif a[1]=="WA"
      r+=1
    elsif a[1]=="AC"
      p+=r
      r=0
      q+=1
      c=true
    end
  else
    i=a[0]
    r=0
    c=false
    if a[1]=="WA"
      r+=1
    elsif a[1]=="AC"
      p+=r
      r=0
      q+=1
      c=true
    end
  end  
  }
puts "#{q} #{p}"
//  [ruby]
n, m = gets.split.map(&:to_i)
submits = []
m.times do
  task, result = gets.split
  submits << [task.to_i, result]
end

ac = 0
acs = Hash.new {0}
tmp_penalties = Hash.new {0}
penalty = 0
now_task = 0


submits.each do |task, result|
  if result == 'AC'
    if acs[task.to_s.to_sym].zero?
      ac += 1
      acs[task.to_s.to_sym] = 1
      penalty += tmp_penalties[task.to_s.to_sym]
    end
  else
    tmp_penalties[task.to_s.to_sym] += 1
  end
end

puts "#{ac} #{penalty}"
//  [ruby]
n, m = gets.chomp.split(' ').map(&:to_i)

results = {}
m.times do
  p, s = gets.chomp.split(' ')
  p = p.to_i

  current_p = results[p]

  if current_p.nil?
    hash = { AC: 0, WA: 0 }
    hash[s.to_sym] +=1
    results[p] = hash
  elsif current_p[:AC] > 0
    next
  else
    current_p[s.to_sym] +=1
  end
end

acs = results.select { |k, v| v[:AC] > 0 }
ac_count = acs.count
wa_sum = acs.reduce(0) { |sum, (k, v)| sum + v[:WA] }
puts "#{ac_count} #{wa_sum}"
//  [rust]
use text_io::*;
use std::collections::*;
use std::process::exit;

fn main() {
    let mut n:usize = read!();
    let mut m:usize = read!();
    let mut wa = vec![0; n];
    let mut ac = vec![0; n];
    let mut ss = 0;
    let mut pp = 0;
    for _ in 0..m {
        let mut p:usize = read!();
        let s:String = read!();
        p -= 1;
        if ac[p] == 0 {
            if s == "AC" {
                ac[p] = 1;
                ss += 1;
                pp += wa[p];
            } else {
                wa[p] += 1;
            }
        }
    }
    println!("{} {}", ss, pp);
}
//  [rust]
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let nm: Vec<u32> = read_vec();
    let _n = nm[0];
    let m = nm[1];

    let ps_vec: Vec<Vec<String>> = read_vec2(m);

    let mut ac_map = HashMap::new();
    let mut wa_map = HashMap::new();

    for ps in &ps_vec {
        let p = &ps[0];
        let s = &ps[1];

        if s == "WA" {
            match ac_map.get(&p) {
                Some(_) => {}
                None => {
                    let v = wa_map.entry(p).or_insert(0);
                    *v += 1;
                }
            }
        } else if s == "AC" {
            ac_map.insert(p, 1);
        }
    }

    let mut answers: u32 = 0;
    let mut penalties: u32 = 0;

    for p in ac_map.keys() {
        match ac_map.get(p) {
            Some(_) => answers += 1,
            None => {}
        }

        match wa_map.get(p) {
            Some(i) => penalties += *i,
            None => {}
        }
    }

    println!("{} {}", answers, penalties);
}
//  [rust]
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
use std::collections::HashMap;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let M: usize = read();
    let mut map: HashMap<usize, Vec<bool>> = HashMap::new();
    for _ in 0..M {
        let i: usize = read::<usize>();
        let mut entry = map.entry(i).or_insert(vec![]);
        (*entry).push(read::<String>() == "AC");
    }
    let mut correct: usize = 0;
    let mut penalty: usize = 0;
    for (_, v) in map {
        let mut penalty_tmp: usize = 0;
        for b in v {
            if b {
                correct += 1;
                penalty += penalty_tmp;
                break;
            } else {
                penalty_tmp += 1;
            }
        }
    }
    println!("{} {}", correct, penalty);
}
//  [typescript]
const main = arg => {  
  const input = arg.trim().split('\n')
  const [n, m] = input[0].split(' ').map(t => parseInt(t))

  const ln = new Array(n)
  for (let i = 0; i < n; i++) ln[i] = new Array(0)

  input.slice(1, m + 1).forEach(t => {
    const l = t.split(' ')
    ln[parseInt(l[0]) - 1].push(l[1])
  })

  let cc = 0
  let pc = 0

  ln.filter(l => l.length > 0).forEach(l => {
    const i = l.indexOf('AC')
    if (i < 0) return
    pc += i
    cc++
  })

  console.log(cc, pc)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [typescript]
import {isNumber} from "util";

function Main(input: string) {
  const lines: string[] = input.split('\n');
  const params1 = lines[0].split(' ');

  const n = parseInt(params1[0]);
  const m = parseInt(params1[1]);
  const p = lines.slice(1, m + 1).map(x => x.split(' ')[0]).map(x => parseInt(x));
  const s = lines.slice(1, m + 1).map(x => x.split(' ')[1]);

  let subject: { [n: number]: number } = {};
  let accepted = new Set();
  let accept = 0;
  let penalty = 0;
  for (let i = 0; i < m; i++) {
    if (typeof subject[p[i]] !== 'number') subject[p[i]] = 0;
    if (!accepted.has(p[i]) && s[i] === 'AC') {
      accept++;
      penalty += subject[p[i]];
      accepted.add(p[i]);
    }
    subject[p[i]]++;
  }
  console.log(`${accept} ${penalty}`);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
import {isNumber} from "util";

function Main(input: string) {
  const lines: string[] = input.split('\n');
  const params1 = lines[0].split(' ');
  
  const m = parseInt(params1[1]);
  const p = lines.slice(1, m + 1).map(x => x.split(' ')[0]).map(x => parseInt(x));
  const s = lines.slice(1, m + 1).map(x => x.split(' ')[1]);

  let subject: { [n: number]: number } = {};
  let accepted = new Set();
  let accept = 0;
  let penalty = 0;
  for (let i = 0; i < m; i++) {
    if (typeof subject[p[i]] !== 'number') subject[p[i]] = 0;
    if (!accepted.has(p[i]) && s[i] === 'AC') {
      accept++;
      penalty += subject[p[i]];
      accepted.add(p[i]);
    }
    subject[p[i]]++;
  }
  console.log(`${accept} ${penalty}`);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [python]
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 

A,B = [int(x) for x in input().split()]
if B % A == 0:
    print (A + B)
else:
    print (B - A)
//  [python]
4,12
a,b = map(int, raw_input().split(' '))
print a + b if (b % a == 0) else -a + b
//  [python]
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:52:15 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())
    
all(nstr.count(c) for c in '753')

ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
#A, B, totAB = zip(*ABT)
(x >> i) & 1

"""


A, B = map(int, input().split())

if B%A ==0:
    print(A+B)
else:
    print(B-A)
//  [java]
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		//変数
		int count=0;
		boolean sw=false;
		int answer=0;
		//long answer=0;
		//double answer=0;
		//String answer="NO";
		//List<Integer> h=new ArrayList<Integer>();
		//int af=Integer.MAX_VALUE;
		int L=0;
		//int sub=0;
		int a=0;
		int b=0;
		//int t[]=new int[(int)Math.pow(10,5)];
		
		//入力
		Scanner sc = new Scanner(System.in);
		a=sc.nextInt();
		b=sc.nextInt();
		//X=sc.nextDouble();
		//int A[]=new int[L];
		//for(int i=0;i<L;i++)
		//{
		//	A[i]=sc.nextInt();
		//}
		//String S=sc.next();
		
		//処理
		if(b%a==0)
		{
			answer=a+b;
		}else
		{
			answer=b-a;
		}
		// 出力
		//System.out.println(Arrays.toString(X))
		//System.out.println(Arrays.deepToString(td));
		System.out.println(answer);
	}
}
//  [java]
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();
        sc.close();
        if(b % a == 0){
            System.out.println(a + b);
        }else{
            System.out.println(b - a);
        }
    }
}
//  [java]
import java.util.Scanner;

class Problem {
    private int A;
    private int B;

    Problem() {
        Scanner sc = new Scanner(System.in);

        A = sc.nextInt();
        B = sc.nextInt();
    }

    int solve() {
        if (B % A == 0) {
            return A + B;
        } else {
            return B - A;
        }
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println(new Problem().solve());
    }
}
//  [cpp]

#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

vll adj[N];ll visit[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m,k;
string s,t;
vll a,b,p,ans;
// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin >>n>>m;
	ll x= (m%n==0)?(m+n):(m-n);
	cout<<x;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const int mod=1e9+7;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}

void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );

  int a,b;
  cin>>a>>b;
  int ans=0;
  if(b%a==0)ans=a+b;
  else ans=b-a;
  
  cout<<ans<<endl;

  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  int a,b;
  cin>>a>>b;
  int ans=0;
  if(b%a==0)ans=a+b;
  else ans=b-a;
  
  cout<<ans<<endl;
 
  return 0;
}
//  [c]
#include<stdio.h>

int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  if(b%a==0){
    printf("%d\n",a+b);
  }else{
    printf("%d\n",b-a);
  }
  return 0;
}
//  [c]
#include <stdio.h>
//#include <string.h>

int main(void){
  
  int a,b;
  
  scanf("%d %d", &a, &b);
  //scanf("%d %d", &h, &w);
  
  if(b%a==0) printf("%d", a+b);
  else printf("%d", b-a);

  return 0;
}
//  [c]
#include <stdio.h>
int main (){
	int A,B;
	scanf("%d %d",&A,&B);
	
	if (B%A==0)
	{
		printf("%d",A+B);
	}
	else 
	{
		printf("%d\n",B-A);
	}
	
	
	
	return 0;
}
//  [javascript]
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var a = o.a();
  var b = o.a();
  if(b % a)return b - a;
  else return a + b;
}
//  [javascript]
var lines =[];

var readline = require("readline");
var rl = readline.createInterface({
  input:  process.stdin,
  output: process.stdout
});

rl.on('line',function(x){
  lines.push(x);
});


rl.on('close',function(){
  var a = Number(lines[0].split(" ")[0]);
  var b = Number(lines[0].split(" ")[1]);

  if(b%a===0){console.log(a+b)}
  else{console.log(b-a)}
});
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	inputList = input[0].split(" ").map(str => parseInt(str, 10));
	a = inputList[0];
	b = inputList[1];
	result = b % a == 0 ? a + b : b - a;
	console.log(result);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	if b%a == 0 {
		fmt.Println(a + b)
	} else {
		fmt.Println(b - a)
	}
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if b%a == 0 {
		fmt.Println(a + b)
	} else {
		fmt.Println(b - a)
	}
}
//  [go]
package main

import "fmt"

func main() {
	// Code for A - B +/- A
	var A, B int
	fmt.Scanf("%d %d", &A, &B)
	if B%A == 0 {
		fmt.Println(A + B)
	} else {
		fmt.Println(B - A)
	}
}
//  [ruby]
a,b = gets.split.map(&:to_i)
if b % a == 0
  puts (a + b)
else
  puts (b - a)
end
//  [ruby]
a,b=gets.split.map &:to_i
puts b%a==0 ? a+b : b-a
//  [ruby]
a,b=gets.split.map(&:to_i)
p b%a==0?a+b:b-a
//  [rust]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(a: isize, b: isize);

    println!("{}", if b % a == 0 { a + b } else { b - a });
}
//  [rust]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::cmp::max;
use std::cmp::min;


fn main() {
    input! {
        A: i32,
        B: i32,
    }

    let ans = if B % A == 0 { A + B } else { B - A };
    println!("{}", ans);
}
//  [rust]
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();

    return if b % a == 0 {
        (a + b).to_string()
    } else {
        (b - a).to_string()
    }
}
//  [typescript]
 import * as fs from 'fs';

namespace AtCoder.abc118 {

    export class Program {
        /**
         * in
         * 4 12
         * out
         * 16
         */
        static main(inp: string):
            void {
            const [a, b]: number[] = inp.split(' ').map(Number);

            if (b % a === 0) {
                console.log(a + b);
            } else {
                console.log(b - a);
            }
        }
    }
}

AtCoder.abc118.Program.main(fs.readFileSync('/dev/stdin', 'utf8').trim());
//  [typescript]
let  lines: number[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', function (line: string) {
  lines = line.split(/\s/).map(i => parseInt(i));
});
reader.on('close', function() {
  let [a, b]: number[] = lines;
  if (b % a === 0) console.log(a + b);
  else console.log(b - a);
});
//  [typescript]
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length == 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function slove() {
    const sc = new Scanner();
    const [a, b] = (await sc.getLine()).split(' ').map((x) => +x);
    if (b % a === 0) {
      console.log(a + b);
    } else {
      console.log(b - a);
    }
    sc.close();
  }

  slove();
}
//  [python]
N = int(input())
A = list(map(int, input().split()))

ans = [0 for _ in range(N)]

sign = 1
for a in A:
    ans[0] += sign * a
    sign *= -1


for i in range(1, N):
    ans[i] = 2 * A[0] - ans[i - 1]

    t = A.pop(0)
    A.append(t)

print(*ans)
//  [python]
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う
# rを10**9にしてたらなんかしらんけど駄目だった 10にしたらいけた...

n = int(input())
dum = list(map(int, input().split()))
l, r = 0, (10 ** 10) // 2

while True:
    mid = (l + r) // 2
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        l = mid + 1
    else:
        r = mid


"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""
//  [python]
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
B = np.zeros(A.shape)

memo = A[0]
B[0] = A[0]
sig = 1
for i in range(1,len(A)):
    sig *= -1
    B[i] = memo + sig * A[i]
    memo = B[i]

output = ""
output += str(int(B[-1]))
memo = B[-1]
for j in range(0,len(A)-1):
    output += " "+str(int(A[j]*2-memo))
    memo = A[j]*2-memo
print(output)
//  [java]
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;
    // static int dp[][] = new int[MAX][MAX];
    static int a[] = new int[MAX];

    public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        for(int i=0;i<n;i++) a[i] = sc.nextInt();

        int x1 = 0;
        for (int i=0;i<n;i++) {
            if ((i&1)==0) x1+=a[i];
            else x1 -= a[i];
        }
        out.printf("%d ", x1);
        int last=x1;
        for (int i=0;i<n-2;i++) {
            last = 2*a[i] - last;
            out.printf("%d ", last);
        }
        out.println(2*a[n-1]-x1);
    }

    public static void main(String[] args) {
        new Main()._main(args);
    }
}
//  [java]
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        long total = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
            total += a[i];
        }
        long res = 0;
        for (int i = 1; i < n; i += 2) {
            res += a[i];
        }
        long[] x = new long[n];
        x[0] = total - 2 * res;
        for (int i = 1; i < n; i++) {
            x[i] = 2 * a[i - 1] - x[i - 1];
        }
        for (int i = 0; i < n - 1; i++) {
            System.out.printf("%d ", x[i]);
        }
        System.out.println(x[n - 1]);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}
//  [java]
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
			
			Scanner input = new Scanner(System.in);
			int N = input.nextInt();
			int[] A = new int[N];
			for(int i = 0; i<N; i++){
				A[i] = input.nextInt();
			}
			
			int[] ans = new int[N];
			ans[0] = 0;
			for(int i = 0; i<N; i++){
				ans[0] = (int)(ans[0]+A[i]*Math.pow(-1, i));
			}
			System.out.println(ans[0]);
			for(int i=1; i<N; i++){
				ans[i] = 2* A[i-1] - ans[i-1];
				System.out.println(" ");
				System.out.println(ans[i]);
			}
	}
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const double pi=acos(-1);
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<MOD>;

mint calc(long long N, long long K) {
    mint res = 1;
    for (long long n = 0; n < K; ++n) {
        res *= (N - n);
        res /= (n + 1);
    }
    return res;
}
int main() {
//cout << fixed << setprecision(12);
ll n;
cin>>n;
ll a[n]={};
ll ma = 0;
rep(i,n){
cin>>a[i];
ma += a[i];}
ll ca = 0;
ma/=2;
rep(i,n){
ll m = i -2;
ll u = i + 1;
while(m>=0){
ca+=a[m];
m--;
m--;}
while(u<=n-1){
ca+=a[u];
u++;
u++;}
cout << 2*(ma-ca) << " ";
ca = 0;}
cout << endl;}
//  [cpp]
#include <bits/stdc++.h>

int main() {
    int N;
    std::cin >> N;
    std::vector<long long int> A(N);
    long long int sum = 0;
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
        sum += A[i];
    }
    sum /= 2;

    for (int i = 0; i < N; i++) {
        long long int val = 0;
        for (int j = i; j < N; j += 2) {
            val += A[j];
        }
        for (int j = i - 1; j >= 0; j -= 2) {
            val += A[j];
        }
        std::cout << (val - sum) * 2;
        if (i < N - 1) {
            std::cout << " ";
        }
    }
    std::cout << std::endl;
}
//  [cpp]
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+5];
	int m[n+5];
	for(int i=1;i<=n;i++)
		cin>>a[i];
	m[1]=a[1]*2;
	for(int i=2;i<=n;i++)
		m[i]=(a[i-1]*2)-m[i-1];
	int x=0;
	while(a[n]*2!=m[1]+m[n])
	{
		x+=2;
		m[1]-=2;
		m[n]-=2;
	}
	cout<<m[1]<<" ";
	for(int i=2;i<n;i++)
	{
		if(i%2==0) m[i]+=x;
		else m[i]-=x;
		cout<<m[i]<<" ";
	}
	cout<<m[n]<<" ";
	return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define rep(i,l,r) for(int i=l;i<r;i++)

typedef long long ll;

ll max(ll x, ll y) { return (x > y) ? x : y; }

int dsc(const void* a, const void* b) { return -*(int*)a + *(int*)b; }

int main() {
    ll n, a[100000],b[100000];
    scanf("%lld", &n);
    ll sum = 0;
    rep(i, 0, n) {
        scanf("%lld", &a[i]);
        if (i % 2 == 0) sum += a[i];
        else sum -= a[i];
    }
    b[0] = sum;
    rep(i, 1, n) {
        b[i] = 2*a[i - 1] - b[i - 1];
    }

    rep(i,0,n) printf("%lld ",b[i]);

    return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int n;
	long sum = 0, in;
	scanf("%d", &n);
	long *a = malloc(sizeof(long) * n);
	for(int i = 0; i < n; i++){
		scanf("%ld", a + i);
		if(i % 2 == 0)sum += a[i];
		else sum -= a[i];
	}
	sum /= 2;
	for(int i = 0; i < n; i++){
		printf("%ld ", sum * 2);
		sum = a[i] - sum;
	}
	return 0;
}
//  [javascript]
console.log((args=>{
  const [[N],A] = args.trim().split`\n`.map(r=>r.split` `.map(v=>0|v));
  const AA = A.concat(A), B = Array(N+N).fill(0), C = Array(N).fill(0);
  for ( let i = 0; i <N+N;i++ ) B[i+1] = B[i] + ((i&1)?-AA[i]:AA[i]);
  for ( let i = 0; i < N; i++ ) C[i] = (i&1)?B[i]-B[N+i]:B[N+i]-B[i];
  return C.join` `;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
//  [javascript]
'use strict'
function main(input) {
    const tmp = Array.from(input.split('\n'));
    const N = parseInt(tmp[0], 10);
    const A = tmp[1].split(' ').map((elem) => parseInt(elem, 10));

    let X = [];
    const S = A.reduce((sum, elem) => sum + elem);
    const A2 = A.filter((elem, i) => i % 2 !== 0).reduce((sum, elem) => sum + elem);
    X[0] = S - 2 * A2;

    for (let i = 1; i < N; i++) {
        X[i] = 2 * A[i - 1] - X[i - 1];
    }
    console.log(X.join(' '));

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));